Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Hein <me@chrishein.com>
  • Loading branch information
christopherhein committed Oct 9, 2020
1 parent 9842992 commit adf52a6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
})
3 changes: 2 additions & 1 deletion pkg/config/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerConfiguration
cacheNamespace: default
metricsBindAddress: :8081
metrics:
BindAddress: :8081
leaderElection:
leaderElect: true
51 changes: 39 additions & 12 deletions pkg/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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"`
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
12 changes: 8 additions & 4 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit adf52a6

Please sign in to comment.