Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into PROD-2223-use-opentof…
Browse files Browse the repository at this point in the history
…u-binary-in-terraform-dockerfile
  • Loading branch information
seemywingz committed Jun 21, 2024
2 parents 21c85fa + afea748 commit ac42531
Show file tree
Hide file tree
Showing 38 changed files with 917 additions and 134 deletions.
4 changes: 2 additions & 2 deletions charts/deployment-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: deployment-operator
description: creates a new instance of the plural deployment operator
appVersion: 0.4.34
version: 0.4.34
appVersion: 0.4.36
version: 0.4.36
maintainers:
- name: Plural
url: https://www.plural.sh
Expand Down
29 changes: 16 additions & 13 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,52 @@ import (
"github.com/pluralsh/deployment-operator/internal/utils"
"github.com/pluralsh/deployment-operator/pkg/controller/stacks"

"github.com/samber/lo"
"golang.org/x/net/context"
"k8s.io/client-go/rest"
ctrclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/pluralsh/deployment-operator/pkg/controller"
"github.com/pluralsh/deployment-operator/pkg/controller/namespaces"
"github.com/pluralsh/deployment-operator/pkg/controller/pipelinegates"
"github.com/pluralsh/deployment-operator/pkg/controller/restore"
"github.com/pluralsh/deployment-operator/pkg/controller/service"
"github.com/samber/lo"
"golang.org/x/net/context"
"k8s.io/client-go/rest"
ctrclient "sigs.k8s.io/controller-runtime/pkg/client"
)

const pollInterval = time.Second * 30

func runAgent(opt *options, config *rest.Config, ctx context.Context, k8sClient ctrclient.Client) (*controller.ControllerManager, *service.ServiceReconciler, *pipelinegates.GateReconciler) {
r, err := time.ParseDuration(opt.refreshInterval)
if err != nil {
setupLog.Error(err, "unable to get refresh interval")
setupLog.Error("unable to get refresh interval", "error", err)
os.Exit(1)
}

t, err := time.ParseDuration(opt.processingTimeout)
if err != nil {
setupLog.Error(err, "unable to get processing timeout")
setupLog.Errorw("unable to get processing timeout", "error", err)
os.Exit(1)
}

mgr, err := controller.NewControllerManager(ctx, opt.maxConcurrentReconciles, t, r, lo.ToPtr(true), opt.consoleUrl, opt.deployToken, opt.clusterId)
if err != nil {
setupLog.Error(err, "unable to create manager")
setupLog.Errorw("unable to create manager", "error", err)
os.Exit(1)
}

sr, err := service.NewServiceReconciler(ctx, mgr.GetClient(), config, r, opt.restoreNamespace)
if err != nil {
setupLog.Error(err, "unable to create service reconciler")
setupLog.Errorw("unable to create service reconciler", "error", err)
os.Exit(1)
}
mgr.AddController(&controller.Controller{
Name: "Service Controller",
Do: sr,
Queue: sr.SvcQueue,
})
gr, err := pipelinegates.NewGateReconciler(mgr.GetClient(), k8sClient, config, r, opt.clusterId)
gr, err := pipelinegates.NewGateReconciler(mgr.GetClient(), k8sClient, config, r, pollInterval, opt.clusterId)
if err != nil {
setupLog.Error(err, "unable to create gate reconciler")
setupLog.Errorw("unable to create gate reconciler", "error", err)
os.Exit(1)
}
mgr.AddController(&controller.Controller{
Expand All @@ -74,18 +77,18 @@ func runAgent(opt *options, config *rest.Config, ctx context.Context, k8sClient

namespace, err := utils.GetOperatorNamespace()
if err != nil {
setupLog.Error(err, "unable to get operator namespace")
setupLog.Errorw("unable to get operator namespace", "error", err)
os.Exit(1)
}

s := stacks.NewStackReconciler(mgr.GetClient(), k8sClient, r, namespace, opt.consoleUrl, opt.deployToken)
s := stacks.NewStackReconciler(mgr.GetClient(), k8sClient, r, pollInterval, namespace, opt.consoleUrl, opt.deployToken)
mgr.AddController(&controller.Controller{
Name: "Stack Controller",
Do: s,
Queue: s.StackQueue,
})
if err := mgr.Start(); err != nil {
setupLog.Error(err, "unable to start controller manager")
setupLog.Errorw("unable to start controller manager", "error", err)
os.Exit(1)
}

Expand Down
45 changes: 44 additions & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package main

import (
"net/http"
"os"
"time"

"github.com/argoproj/argo-rollouts/pkg/apis/rollouts"
rolloutv1alpha1 "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
roclientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned"
templatesv1 "github.com/open-policy-agent/frameworks/constraint/pkg/apis/templates/v1"
constraintstatusv1beta1 "github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand All @@ -32,9 +39,15 @@ func init() {
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
utilruntime.Must(constraintstatusv1beta1.AddToScheme(scheme))
utilruntime.Must(templatesv1.AddToScheme(scheme))
utilruntime.Must(rolloutv1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

const (
httpClientTimout = time.Second * 5
httpCacheExpiryTime = time.Second * 2
)

func main() {
opt := newOptions()
config := ctrl.GetConfigOrDie()
Expand All @@ -50,7 +63,21 @@ func main() {
setupLog.Error(err, "unable to create manager")
os.Exit(1)
}

rolloutsClient, err := roclientset.NewForConfig(config)
if err != nil {
setupLog.Error(err, "unable to create rollouts client")
os.Exit(1)
}
dynamicClient, err := dynamic.NewForConfig(config)
if err != nil {
setupLog.Error(err, "unable to create dynamic client")
os.Exit(1)
}
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
setupLog.Error(err, "unable to create kubernetes client")
os.Exit(1)
}
setupLog.Info("starting agent")
ctrlMgr, serviceReconciler, gateReconciler := runAgent(opt, config, ctx, mgr.GetClient())

Expand All @@ -70,6 +97,17 @@ func main() {
ConsoleClient: ctrlMgr.GetClient(),
Reader: mgr.GetCache(),
}
argoRolloutController := &controller.ArgoRolloutReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ConsoleClient: ctrlMgr.GetClient(),
ConsoleURL: opt.consoleUrl,
HttpClient: &http.Client{Timeout: httpClientTimout},
ArgoClientSet: rolloutsClient,
DynamicClient: dynamicClient,
SvcReconciler: serviceReconciler,
KubeClient: kubeClient,
}

reconcileGroups := map[schema.GroupVersionKind]controller.SetupWithManager{
{
Expand All @@ -87,6 +125,11 @@ func main() {
Version: "v1beta1",
Kind: "ConstraintPodStatus",
}: constraintController.SetupWithManager,
{
Group: rolloutv1alpha1.SchemeGroupVersion.Group,
Version: rolloutv1alpha1.SchemeGroupVersion.Version,
Kind: rollouts.RolloutKind,
}: argoRolloutController.SetupWithManager,
}

if err = (&controller.CrdRegisterControllerReconciler{
Expand Down
26 changes: 26 additions & 0 deletions cmd/agent/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"net/http"

"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/klog/v2"
)

const (
prometheusMetricsPath = "/metrics"
prometheusMetricsPort = 8000
)

func init() {
go initPrometheusMetrics()
}

func initPrometheusMetrics() {
http.Handle(prometheusMetricsPath, promhttp.Handler())

if err := http.ListenAndServe(fmt.Sprintf(":%d", prometheusMetricsPort), nil); err != nil {
klog.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion cmd/agent/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newOptions() *options {
flag.StringVar(&o.metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&o.probeAddr, "health-probe-bind-address", ":9001", "The address the probe endpoint binds to.")
flag.BoolVar(&o.enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.IntVar(&o.maxConcurrentReconciles, "max-concurrent-reconciles", 10, "Maximum number of concurrent reconciles which can be run.")
flag.IntVar(&o.maxConcurrentReconciles, "max-concurrent-reconciles", 20, "Maximum number of concurrent reconciles which can be run.")
flag.IntVar(&o.resyncSeconds, "resync-seconds", 300, "Resync duration in seconds.")
flag.StringVar(&o.refreshInterval, "refresh-interval", "2m", "Refresh interval duration.")
flag.StringVar(&o.processingTimeout, "processing-timeout", "1m", "Maximum amount of time to spend trying to process queue item.")
Expand Down
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/Masterminds/sprig/v3 v3.2.3
github.com/Yamashou/gqlgenc v0.18.1
github.com/argoproj/argo-rollouts v1.6.6
github.com/elastic/crd-ref-docs v0.0.12
github.com/evanphx/json-patch v5.7.0+incompatible
github.com/fluxcd/flagger v1.35.0
Expand All @@ -19,10 +20,11 @@ require (
github.com/open-policy-agent/gatekeeper/v3 v3.15.1
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/pkg/errors v0.9.1
github.com/pluralsh/console-client-go v0.5.13
github.com/pluralsh/console-client-go v0.7.0
github.com/pluralsh/controller-reconcile-helper v0.0.4
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
github.com/pluralsh/polly v0.1.10
github.com/prometheus/client_golang v1.19.1
github.com/samber/lo v1.39.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand All @@ -39,7 +41,6 @@ require (
k8s.io/apimachinery v0.29.3
k8s.io/cli-runtime v0.29.2
k8s.io/client-go v0.29.2
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.110.1
k8s.io/kubectl v0.29.2
layeh.com/gopher-luar v1.0.11
Expand Down Expand Up @@ -88,7 +89,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand All @@ -112,7 +113,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/cel-go v0.17.7 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand All @@ -123,7 +124,7 @@ require (
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -150,7 +151,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -172,9 +172,8 @@ require (
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/zerolog v1.29.0 // indirect
Expand All @@ -185,7 +184,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sosodev/duration v1.2.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.15.0 // indirect
Expand All @@ -207,7 +206,7 @@ require (
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
Expand Down
Loading

0 comments on commit ac42531

Please sign in to comment.