From 93d5e1e3dda31260b8f09499930f5bbedb454c8e Mon Sep 17 00:00:00 2001 From: Ulli Goschler Date: Mon, 17 Jun 2024 15:42:52 +0200 Subject: [PATCH] add resync-option for operatorkit (#518) * add resync-option for operatorkit --- CHANGELOG.md | 6 ++++++ flag/service/controller/controller.go | 5 +++++ flag/service/service.go | 3 +++ helm/cluster-apps-operator/templates/configmap.yaml | 2 ++ helm/cluster-apps-operator/values.yaml | 3 +++ main.go | 1 + service/controller/cluster.go | 11 ++++++++--- service/service.go | 2 ++ 8 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 flag/service/controller/controller.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a890dee..bb55d098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added `--service.controller.resyncperiod` daemon flag that can be controller via `.controller.resyncPeriod` Helm value. + Controls the duration after which a complete sync with all known runtime objects the controller watches is performed. + Defaults to `5m`. + ## [2.22.0] - 2024-05-03 ### Added diff --git a/flag/service/controller/controller.go b/flag/service/controller/controller.go new file mode 100644 index 00000000..f5a3529a --- /dev/null +++ b/flag/service/controller/controller.go @@ -0,0 +1,5 @@ +package controller + +type Controller struct { + ResyncPeriod string +} diff --git a/flag/service/service.go b/flag/service/service.go index 5a490af5..c3fad58e 100644 --- a/flag/service/service.go +++ b/flag/service/service.go @@ -4,6 +4,7 @@ import ( "github.com/giantswarm/operatorkit/v7/pkg/flag/service/kubernetes" "github.com/giantswarm/cluster-apps-operator/v2/flag/service/app" + "github.com/giantswarm/cluster-apps-operator/v2/flag/service/controller" "github.com/giantswarm/cluster-apps-operator/v2/flag/service/image" "github.com/giantswarm/cluster-apps-operator/v2/flag/service/proxy" "github.com/giantswarm/cluster-apps-operator/v2/flag/service/workload" @@ -16,4 +17,6 @@ type Service struct { Kubernetes kubernetes.Kubernetes Workload workload.Workload Proxy proxy.Proxy + + Controller controller.Controller } diff --git a/helm/cluster-apps-operator/templates/configmap.yaml b/helm/cluster-apps-operator/templates/configmap.yaml index 5e48f96a..fd91ad61 100644 --- a/helm/cluster-apps-operator/templates/configmap.yaml +++ b/helm/cluster-apps-operator/templates/configmap.yaml @@ -24,6 +24,8 @@ data: image: registry: domain: {{ .Values.registry.domain }} + controller: + resyncPeriod: '{{ .Values.controller.resyncPeriod }}' kubernetes: address: '' inCluster: true diff --git a/helm/cluster-apps-operator/values.yaml b/helm/cluster-apps-operator/values.yaml index abde2c6f..be180996 100644 --- a/helm/cluster-apps-operator/values.yaml +++ b/helm/cluster-apps-operator/values.yaml @@ -35,6 +35,9 @@ image: name: "giantswarm/cluster-apps-operator" tag: "[[ .Version ]]" +controller: + resyncPeriod: "5m" + kubernetes: api: clusterIPRange: 10.96.0.0/12 diff --git a/main.go b/main.go index c88ea033..b5ef8931 100644 --- a/main.go +++ b/main.go @@ -107,6 +107,7 @@ func mainE(ctx context.Context) error { daemonCommand.PersistentFlags().String(f.Service.App.ChartOperator.Version, "", "Version for chart-operator app CR.") daemonCommand.PersistentFlags().String(f.Service.Image.Registry.Domain, "quay.io", "Image registry.") + daemonCommand.PersistentFlags().String(f.Service.Controller.ResyncPeriod, "5m", "Duration after which a complete sync with all known cluster-objects the controller watches is performed.") daemonCommand.PersistentFlags().String(f.Service.Kubernetes.Address, "http://127.0.0.1:6443", "Address used to connect to Kubernetes. When empty in-cluster config is created.") daemonCommand.PersistentFlags().Bool(f.Service.Kubernetes.InCluster, false, "Whether to use the in-cluster config to authenticate with Kubernetes.") diff --git a/service/controller/cluster.go b/service/controller/cluster.go index 57a1170f..a6481096 100644 --- a/service/controller/cluster.go +++ b/service/controller/cluster.go @@ -1,6 +1,8 @@ package controller import ( + "time" + "github.com/giantswarm/k8sclient/v7/pkg/k8sclient" "github.com/giantswarm/k8smetadata/pkg/label" "github.com/giantswarm/microerror" @@ -25,9 +27,10 @@ import ( ) type ClusterConfig struct { - K8sClient k8sclient.Interface - Logger micrologger.Logger - PodCIDR podcidr.Interface + K8sClient k8sclient.Interface + Logger micrologger.Logger + PodCIDR podcidr.Interface + ResyncPeriod time.Duration AppOperatorCatalog string AppOperatorVersion string @@ -68,6 +71,8 @@ func NewCluster(config ClusterConfig) (*Cluster, error) { }, Resources: resources, + ResyncPeriod: config.ResyncPeriod, + // Name is used to compute finalizer names. This here results in something // like operatorkit.giantswarm.io/cluster-apps-operator-cluster-controller. Name: project.Name() + "-cluster-controller", diff --git a/service/service.go b/service/service.go index b8240941..7a899ece 100644 --- a/service/service.go +++ b/service/service.go @@ -142,6 +142,8 @@ func New(config Config) (*Service, error) { Logger: config.Logger, PodCIDR: pc, + ResyncPeriod: config.Viper.GetDuration(config.Flag.Service.Controller.ResyncPeriod), + AppOperatorCatalog: config.Viper.GetString(config.Flag.Service.App.AppOperator.Catalog), AppOperatorVersion: config.Viper.GetString(config.Flag.Service.App.AppOperator.Version), ChartOperatorCatalog: config.Viper.GetString(config.Flag.Service.App.ChartOperator.Catalog),