Skip to content

Commit 7857bb8

Browse files
astefanuttiopenshift-merge-robot
authored andcommitted
Add controller manager structured config
1 parent 2991661 commit 7857bb8

File tree

3 files changed

+78
-34
lines changed

3 files changed

+78
-34
lines changed

config/manager/manager.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ spec:
3434
containers:
3535
- command:
3636
- /manager
37-
args:
38-
- "--health-probe-bind-address=:8081"
39-
- "--metrics-bind-address=0.0.0.0:8082"
4037
image: controller:latest
4138
imagePullPolicy: Always
4239
name: manager

main.go

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3333
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3434
_ "k8s.io/client-go/plugin/pkg/client/auth"
35+
"k8s.io/client-go/rest"
3536
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
3637
"k8s.io/utils/pointer"
3738
ctrl "sigs.k8s.io/controller-runtime"
@@ -56,12 +57,6 @@ func init() {
5657
}
5758

5859
func main() {
59-
var metricsAddr string
60-
var probeAddr string
61-
62-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
63-
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
64-
6560
zapOptions := zap.Options{
6661
Development: true,
6762
TimeEncoder: zapcore.TimeEncoderOfLayout(time.RFC3339),
@@ -73,15 +68,27 @@ func main() {
7368
ctx := ctrl.SetupSignalHandler()
7469

7570
cfg := config.CodeFlareOperatorConfiguration{
76-
LeaderElection: &configv1alpha1.LeaderElectionConfiguration{},
77-
MCAD: &mcadconfig.MCADConfiguration{},
78-
InstaScale: &config.InstaScaleConfiguration{},
71+
ControllerManager: config.ControllerManager{
72+
LeaderElection: &configv1alpha1.LeaderElectionConfiguration{},
73+
},
74+
MCAD: &mcadconfig.MCADConfiguration{},
75+
InstaScale: &config.InstaScaleConfiguration{},
7976
}
8077

81-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
78+
kubeConfig, err := ctrl.GetConfig()
79+
exitOnError(err, "unable to get client config")
80+
81+
if kubeConfig.UserAgent == "" {
82+
kubeConfig.UserAgent = "codeflare-operator"
83+
}
84+
kubeConfig.Burst = int(pointer.Int32Deref(cfg.ClientConnection.Burst, int32(rest.DefaultBurst)))
85+
kubeConfig.QPS = pointer.Float32Deref(cfg.ClientConnection.QPS, rest.DefaultQPS)
86+
setupLog.V(2).Info("REST client", "qps", kubeConfig.QPS, "burst", kubeConfig.Burst)
87+
88+
mgr, err := ctrl.NewManager(kubeConfig, ctrl.Options{
8289
Scheme: scheme,
83-
MetricsBindAddress: metricsAddr,
84-
HealthProbeBindAddress: probeAddr,
90+
MetricsBindAddress: cfg.Metrics.BindAddress,
91+
HealthProbeBindAddress: cfg.Health.BindAddress,
8592
LeaderElection: pointer.BoolDeref(cfg.LeaderElection.LeaderElect, false),
8693
LeaderElectionID: cfg.LeaderElection.ResourceName,
8794
LeaderElectionNamespace: cfg.LeaderElection.ResourceNamespace,
@@ -90,10 +97,7 @@ func main() {
9097
RetryPeriod: &cfg.LeaderElection.RetryPeriod.Duration,
9198
RenewDeadline: &cfg.LeaderElection.RenewDeadline.Duration,
9299
})
93-
if err != nil {
94-
setupLog.Error(err, "unable to start manager")
95-
os.Exit(1)
96-
}
100+
exitOnError(err, "unable to start manager")
97101

98102
mcadQueueController := mcad.NewJobController(mgr.GetConfig(), cfg.MCAD, &mcadconfig.MCADConfigurationExtended{})
99103
if mcadQueueController == nil {
@@ -111,20 +115,11 @@ func main() {
111115
exitOnError(instaScaleController.SetupWithManager(mgr), "Error setting up InstaScale controller")
112116
}
113117

114-
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
115-
setupLog.Error(err, "unable to set up health check")
116-
os.Exit(1)
117-
}
118-
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
119-
setupLog.Error(err, "unable to set up ready check")
120-
os.Exit(1)
121-
}
118+
exitOnError(mgr.AddHealthzCheck(cfg.Health.LivenessEndpointName, healthz.Ping), "unable to set up health check")
119+
exitOnError(mgr.AddReadyzCheck(cfg.Health.ReadinessEndpointName, healthz.Ping), "unable to set up ready check")
122120

123121
setupLog.Info("starting manager")
124-
if err := mgr.Start(ctx); err != nil {
125-
setupLog.Error(err, "problem running manager")
126-
os.Exit(1)
127-
}
122+
exitOnError(mgr.Start(ctx), "error running manager")
128123
}
129124

130125
func exitOnError(err error, msg string) {

pkg/config/config.go

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import (
2424
)
2525

2626
type CodeFlareOperatorConfiguration struct {
27-
// LeaderElection is the LeaderElection config to be used when configuring
28-
// the manager.Manager leader election
29-
LeaderElection *configv1alpha1.LeaderElectionConfiguration `json:"leaderElection,omitempty"`
27+
// ClientConnection provides additional configuration options for Kubernetes
28+
// API server client.
29+
ClientConnection *ClientConnection `json:"clientConnection,omitempty"`
30+
31+
// ControllerManager returns the configurations for controllers
32+
ControllerManager `json:",inline"`
3033

3134
// The MCAD controller configuration
3235
MCAD *mcad.MCADConfiguration `json:"mcad,omitempty"`
@@ -44,3 +47,52 @@ type InstaScaleConfiguration struct {
4447
// The InstaScale controller configuration
4548
instascale.InstaScaleConfiguration `json:",inline,omitempty"`
4649
}
50+
51+
type ControllerManager struct {
52+
// Metrics contains the controller metrics configuration
53+
// +optional
54+
Metrics MetricsConfiguration `json:"metrics,omitempty"`
55+
56+
// Health contains the controller health configuration
57+
// +optional
58+
Health HealthConfiguration `json:"health,omitempty"`
59+
60+
// LeaderElection is the LeaderElection config to be used when configuring
61+
// the manager.Manager leader election
62+
LeaderElection *configv1alpha1.LeaderElectionConfiguration `json:"leaderElection,omitempty"`
63+
}
64+
65+
type ClientConnection struct {
66+
// QPS controls the number of queries per second allowed before client-side throttling
67+
// connection to the API server.
68+
QPS *float32 `json:"qps,omitempty"`
69+
70+
// Burst allows extra queries to accumulate when a client is exceeding its rate.
71+
Burst *int32 `json:"burst,omitempty"`
72+
}
73+
74+
// MetricsConfiguration defines the metrics configuration.
75+
type MetricsConfiguration struct {
76+
// BindAddress is the TCP address that the controller should bind to
77+
// for serving Prometheus metrics.
78+
// It can be set to "0" to disable the metrics serving.
79+
// +optional
80+
BindAddress string `json:"bindAddress,omitempty"`
81+
}
82+
83+
// HealthConfiguration defines the health configuration.
84+
type HealthConfiguration struct {
85+
// BindAddress is the TCP address that the controller should bind to
86+
// for serving health probes.
87+
// It can be set to "0" or "" to disable serving the health probe.
88+
// +optional
89+
BindAddress string `json:"bindAddress,omitempty"`
90+
91+
// ReadinessEndpointName, defaults to "readyz"
92+
// +optional
93+
ReadinessEndpointName string `json:"readinessEndpointName,omitempty"`
94+
95+
// LivenessEndpointName, defaults to "healthz"
96+
// +optional
97+
LivenessEndpointName string `json:"livenessEndpointName,omitempty"`
98+
}

0 commit comments

Comments
 (0)