Skip to content

Commit

Permalink
add resync-option for operatorkit (#518)
Browse files Browse the repository at this point in the history
* add resync-option for operatorkit
  • Loading branch information
nce authored Jun 17, 2024
1 parent 469683f commit 93d5e1e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions flag/service/controller/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package controller

type Controller struct {
ResyncPeriod string
}
3 changes: 3 additions & 0 deletions flag/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -16,4 +17,6 @@ type Service struct {
Kubernetes kubernetes.Kubernetes
Workload workload.Workload
Proxy proxy.Proxy

Controller controller.Controller
}
2 changes: 2 additions & 0 deletions helm/cluster-apps-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ data:
image:
registry:
domain: {{ .Values.registry.domain }}
controller:
resyncPeriod: '{{ .Values.controller.resyncPeriod }}'
kubernetes:
address: ''
inCluster: true
Expand Down
3 changes: 3 additions & 0 deletions helm/cluster-apps-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ image:
name: "giantswarm/cluster-apps-operator"
tag: "[[ .Version ]]"

controller:
resyncPeriod: "5m"

kubernetes:
api:
clusterIPRange: 10.96.0.0/12
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
11 changes: 8 additions & 3 deletions service/controller/cluster.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 93d5e1e

Please sign in to comment.