diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index ec08b31118..5d0dfd2620 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -42,7 +42,7 @@ var _ = Describe("config", func() { Expect(*conf.LeaderElection.LeaderElect).To(Equal(true)) Expect(conf.CacheNamespace).To(Equal("default")) - Expect(conf.MetricsBindAddress).To(Equal(":8081")) + Expect(conf.Metrics.BindAddress).To(Equal(":8081")) }) }) }) diff --git a/pkg/config/testdata/config.yaml b/pkg/config/testdata/config.yaml index 99c6ac9d2d..07d1c3646a 100644 --- a/pkg/config/testdata/config.yaml +++ b/pkg/config/testdata/config.yaml @@ -1,6 +1,7 @@ apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 kind: ControllerConfiguration cacheNamespace: default -metricsBindAddress: :8081 +metrics: + BindAddress: :8081 leaderElection: leaderElect: true diff --git a/pkg/config/v1alpha1/types.go b/pkg/config/v1alpha1/types.go index 0caf4ea38c..b792027d70 100644 --- a/pkg/config/v1alpha1/types.go +++ b/pkg/config/v1alpha1/types.go @@ -24,11 +24,17 @@ import ( // ControllerConfigurationSpec defines the desired state of GenericControllerConfiguration type ControllerConfigurationSpec struct { - // SyncPeriod returns the SyncPeriod + // SyncPeriod determines the minimum frequency at which watched resources are + // reconciled. A lower period will correct entropy more quickly, but reduce + // responsiveness to change if there are many watched resources. Change this + // value only if you know what you are doing. Defaults to 10 hours if unset. + // there will a 10 percent jitter between the SyncPeriod of all controllers + // so that all controllers will not send list requests simultaneously. // +optional SyncPeriod *metav1.Duration `json:"syncPeriod,omitempty"` - // LeaderElection returns the LeaderElection config + // LeaderElection is the LeaderElection config to be used when configuring + // the manager.Manager leader election // +optional LeaderElection *configv1alpha1.LeaderElectionConfiguration `json:"leaderElection,omitempty"` @@ -41,45 +47,66 @@ type ControllerConfigurationSpec struct { // +optional CacheNamespace string `json:"cacheNamespace,omitempty"` - // MetricsBindAddress returns the bind address for the metrics server + // GracefulShutdownTimeout is the duration given to runnable to stop before the manager actually returns on stop. + // To disable graceful shutdown, set to time.Duration(0) + // To use graceful shutdown without timeout, set to a negative duration, e.G. time.Duration(-1) + // The graceful shutdown is skipped for safety reasons in case the leadere election lease is lost. + GracefulShutdownTimeout *metav1.Duration `json:"gracefulShutDown,omitempty"` + + // Metrics contains thw controller metrics configuration // +optional - MetricsBindAddress string `json:"metricsBindAddress,omitempty"` + Metrics ControllerMetrics `json:"metrics,omitempty"` - // Health contains the controller health information + // Health contains the controller health configuration // +optional Health ControllerHealth `json:"health,omitempty"` - // Webhook contains the controllers webhook information + // Webhook contains the controllers webhook configuration // +optional Webhook ControllerWebhook `json:"webhook,omitempty"` } +// ControllerMetrics defines the metrics configs +type ControllerMetrics struct { + // BindAddress is the TCP address that the controller should bind to + // for serving prometheus metrics. + // It can be set to "0" to disable the metrics serving. + // +optional + BindAddress string `json:"BindAddress,omitempty"` +} + // ControllerHealth defines the health configs type ControllerHealth struct { - // HealthProbeBindAddress returns the bind address for the health probe + // HealthProbeBindAddress is the TCP address that the controller should bind to + // for serving health probes // +optional HealthProbeBindAddress string `json:"healthProbeBindAddress,omitempty"` - // ReadinessEndpointName returns the readiness endpoint name + // ReadinessEndpointName, defaults to "readyz" // +optional ReadinessEndpointName string `json:"readinessEndpointName,omitempty"` - // LivenessEndpointName returns the liveness endpoint name + // LivenessEndpointName, defaults to "healthz" // +optional LivenessEndpointName string `json:"livenessEndpointName,omitempty"` } // ControllerWebhook defines the webhook server for the controller type ControllerWebhook struct { - // Port returns the Port for the server + // Port is the port that the webhook server serves at. + // It is used to set webhook.Server.Port. // +optional Port *int `json:"port,omitempty"` - // Host returns the Host for the server + // Host is the hostname that the webhook server binds to. + // It is used to set webhook.Server.Host. // +optional Host string `json:"host,omitempty"` - // CertDir returns the CertDir + // CertDir is the directory that contains the server key and certificate. + // if not set, webhook server would look up the server key and certificate in + // {TempDir}/k8s-webhook-server/serving-certs. The server key and certificate + // must be named tls.key and tls.crt, respectively. // +optional CertDir string `json:"certDir,omitempty"` } diff --git a/pkg/config/v1alpha1/zz_generated.deepcopy.go b/pkg/config/v1alpha1/zz_generated.deepcopy.go index b223f68fb3..dd96cf48c4 100644 --- a/pkg/config/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/config/v1alpha1/zz_generated.deepcopy.go @@ -48,6 +48,12 @@ func (in *ControllerConfigurationSpec) DeepCopyInto(out *ControllerConfiguration *out = new(configv1alpha1.LeaderElectionConfiguration) (*in).DeepCopyInto(*out) } + if in.GracefulShutdownTimeout != nil { + in, out := &in.GracefulShutdownTimeout, &out.GracefulShutdownTimeout + *out = new(v1.Duration) + **out = **in + } + out.Metrics = in.Metrics out.Health = in.Health in.Webhook.DeepCopyInto(&out.Webhook) } @@ -77,6 +83,21 @@ func (in *ControllerHealth) DeepCopy() *ControllerHealth { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ControllerMetrics) DeepCopyInto(out *ControllerMetrics) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControllerMetrics. +func (in *ControllerMetrics) DeepCopy() *ControllerMetrics { + if in == nil { + return nil + } + out := new(ControllerMetrics) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ControllerWebhook) DeepCopyInto(out *ControllerWebhook) { *out = *in diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 59ab025606..65688b4f65 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -426,8 +426,8 @@ func (o Options) AndFrom(loader config.DeferredFileLoader) (Options, error) { o.Namespace = newObj.CacheNamespace } - if o.MetricsBindAddress == "" && newObj.MetricsBindAddress != "" { - o.MetricsBindAddress = newObj.MetricsBindAddress + if o.MetricsBindAddress == "" && newObj.Metrics.BindAddress != "" { + o.MetricsBindAddress = newObj.Metrics.BindAddress } if o.HealthProbeBindAddress == "" && newObj.Health.HealthProbeBindAddress != "" { diff --git a/pkg/manager/manager_test.go b/pkg/manager/manager_test.go index ecd4eb052a..ce3d97521a 100644 --- a/pkg/manager/manager_test.go +++ b/pkg/manager/manager_test.go @@ -143,8 +143,10 @@ var _ = Describe("manger.Manager", func() { RenewDeadline: duration, RetryPeriod: duration, }, - CacheNamespace: "default", - MetricsBindAddress: ":6000", + CacheNamespace: "default", + Metrics: v1alpha1.ControllerMetrics{ + BindAddress: ":6000", + }, Health: v1alpha1.ControllerHealth{ HealthProbeBindAddress: "6060", ReadinessEndpointName: "/readyz", @@ -199,8 +201,10 @@ var _ = Describe("manger.Manager", func() { RenewDeadline: duration, RetryPeriod: duration, }, - CacheNamespace: "default", - MetricsBindAddress: ":6000", + CacheNamespace: "default", + Metrics: v1alpha1.ControllerMetrics{ + BindAddress: ":6000", + }, Health: v1alpha1.ControllerHealth{ HealthProbeBindAddress: "6060", ReadinessEndpointName: "/readyz",