diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index afaf1855..4faaed42 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -13,6 +13,7 @@ on: - 'main.go' - 'Makefile' - 'internal/**' + - 'cmd/**' pull_request: branches: [ "*" ] paths: @@ -25,6 +26,7 @@ on: - 'main.go' - 'Makefile' - 'internal/**' + - 'cmd/**' jobs: kind: diff --git a/cmd/manager/cmd.go b/cmd/manager/cmd.go index 81bd8050..ad3cab0e 100644 --- a/cmd/manager/cmd.go +++ b/cmd/manager/cmd.go @@ -14,8 +14,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/rest" "k8s.io/klog/v2" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -31,6 +33,7 @@ import ( "github.com/clastix/kamaji/internal/webhook/routes" ) +//nolint:maintidx func NewCmd(scheme *runtime.Scheme) *cobra.Command { // CLI flags var ( @@ -40,6 +43,7 @@ func NewCmd(scheme *runtime.Scheme) *cobra.Command { tmpDirectory string kineImage string controllerReconcileTimeout time.Duration + cacheResyncPeriod time.Duration datastore string managerNamespace string managerServiceAccountName string @@ -98,6 +102,11 @@ func NewCmd(scheme *runtime.Scheme) *cobra.Command { LeaderElection: leaderElect, LeaderElectionNamespace: managerNamespace, LeaderElectionID: "799b98bc.clastix.io", + NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) { + opts.Resync = &cacheResyncPeriod + + return cache.New(config, opts) + }, }) if err != nil { setupLog.Error(err, "unable to start manager") @@ -239,6 +248,7 @@ func NewCmd(scheme *runtime.Scheme) *cobra.Command { cmd.Flags().StringVar(&managerServiceAccountName, "serviceaccount-name", os.Getenv("SERVICE_ACCOUNT"), "The Kubernetes Namespace on which the Operator is running in, required for the TenantControlPlane migration jobs.") cmd.Flags().StringVar(&webhookCAPath, "webhook-ca-path", "/tmp/k8s-webhook-server/serving-certs/ca.crt", "Path to the Manager webhook server CA, required for the TenantControlPlane migration jobs.") cmd.Flags().DurationVar(&controllerReconcileTimeout, "controller-reconcile-timeout", 30*time.Second, "The reconciliation request timeout before the controller withdraw the external resource calls, such as dealing with the Datastore, or the Tenant Control Plane API endpoint.") + cmd.Flags().DurationVar(&cacheResyncPeriod, "cache-resync-period", 10*time.Hour, "The controller-runtime.Manager cache resync period.") cobra.OnInitialize(func() { viper.AutomaticEnv() diff --git a/docs/content/reference/configuration.md b/docs/content/reference/configuration.md index e20b9913..2166844e 100644 --- a/docs/content/reference/configuration.md +++ b/docs/content/reference/configuration.md @@ -4,22 +4,24 @@ Currently, **Kamaji** allows customization using CLI flags for the `manager` sub Available flags are the following: -| Flag | Usage | Default | -| ---- | ------ | --- | -| `--metrics-bind-address` | The address the metric endpoint binds to. | `:8080` | -| `--health-probe-bind-address` | The address the probe endpoint binds to. | `:8081` | -| `--leader-elect` | Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager. | `true` | -| `--tmp-directory` | Directory which will be used to work with temporary files. | `/tmp/kamaji` | -| `--kine-image` | Container image along with tag to use for the Kine sidecar container (used only if etcd-storage-type is set to one of kine strategies). | `rancher/kine:v0.9.2-amd64` | -| `--datastore` | The default DataStore that should be used by Kamaji to setup the required storage. | `etcd` | -| `--migrate-image` | Specify the container image to launch when a TenantControlPlane is migrated to a new datastore. | `migrate-image` | -| `--max-concurrent-tcp-reconciles` | Specify the number of workers for the Tenant Control Plane controller (beware of CPU consumption). | `1` | -| `--pod-namespace` | The Kubernetes Namespace on which the Operator is running in, required for the TenantControlPlane migration jobs. | `os.Getenv("POD_NAMESPACE")` | -| `--webhook-service-name` | The Kamaji webhook server Service name which is used to get validation webhooks, required for the TenantControlPlane migration jobs. | `kamaji-webhook-service` | -| `--serviceaccount-name` | The Kubernetes ServiceAccount used by the Operator, required for the TenantControlPlane migration jobs. | `os.Getenv("SERVICE_ACCOUNT")` | -| `--webhook-ca-path` | Path to the Manager webhook server CA, required for the TenantControlPlane migration jobs. | `/tmp/k8s-webhook-server/serving-certs/ca.crt` | -| `--zap-devel` | Development Mode (encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn). Production Mode (encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error). | `true` | -| `--zap-encoder` | Zap log encoding, one of 'json' or 'console' | `console` | -| `--zap-log-level` | Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity | `info` | -| `--zap-stacktrace-level` | Zap Level at and above which stacktraces are captured (one of 'info', 'error', 'panic'). | `info` | -| `--zap-time-encoding` | Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano') | `epoch` | +| Flag | Usage | Default | +|-----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------| +| `--metrics-bind-address` | The address the metric endpoint binds to. | `:8080` | +| `--health-probe-bind-address` | The address the probe endpoint binds to. | `:8081` | +| `--leader-elect` | Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager. | `true` | +| `--tmp-directory` | Directory which will be used to work with temporary files. | `/tmp/kamaji` | +| `--kine-image` | Container image along with tag to use for the Kine sidecar container (used only if etcd-storage-type is set to one of kine strategies). | `rancher/kine:v0.9.2-amd64` | +| `--datastore` | The default DataStore that should be used by Kamaji to setup the required storage. | `etcd` | +| `--migrate-image` | Specify the container image to launch when a TenantControlPlane is migrated to a new datastore. | `migrate-image` | +| `--max-concurrent-tcp-reconciles` | Specify the number of workers for the Tenant Control Plane controller (beware of CPU consumption). | `1` | +| `--pod-namespace` | The Kubernetes Namespace on which the Operator is running in, required for the TenantControlPlane migration jobs. | `os.Getenv("POD_NAMESPACE")` | +| `--webhook-service-name` | The Kamaji webhook server Service name which is used to get validation webhooks, required for the TenantControlPlane migration jobs. | `kamaji-webhook-service` | +| `--serviceaccount-name` | The Kubernetes ServiceAccount used by the Operator, required for the TenantControlPlane migration jobs. | `os.Getenv("SERVICE_ACCOUNT")` | +| `--webhook-ca-path` | Path to the Manager webhook server CA, required for the TenantControlPlane migration jobs. | `/tmp/k8s-webhook-server/serving-certs/ca.crt` | +| `--controller-reconcile-timeout` | The reconciliation request timeout before the controller withdraw the external resource calls, such as dealing with the Datastore, or the Tenant Control Plane API endpoint. | `30s` | +| `--cache-resync-period` | The controller-runtime.Manager cache resync period. | `10h` | +| `--zap-devel` | Development Mode (encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn). Production Mode (encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error). | `true` | +| `--zap-encoder` | Zap log encoding, one of 'json' or 'console' | `console` | +| `--zap-log-level` | Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity | `info` | +| `--zap-stacktrace-level` | Zap Level at and above which stacktraces are captured (one of 'info', 'error', 'panic'). | `info` | +| `--zap-time-encoding` | Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano') | `epoch` |