From 94ccdf0afbe0277dfd76eaa4847a1d754823ff77 Mon Sep 17 00:00:00 2001 From: Adrian Kostrubiak Date: Fri, 3 Dec 2021 11:13:53 -0500 Subject: [PATCH 1/5] add healthz, readyz probes to controller manager. fixes #602 Signed-off-by: Adrian Kostrubiak adrian.kostrubiak@tomtom.com --- config/manager/manager.yaml | 12 ++++++++++++ main.go | 38 ++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index fbb8654ddc..51bbdb2293 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -27,6 +27,18 @@ spec: - --enable-leader-election image: controller name: manager + livenessProbe: + httpGet: + path: /healthz + port: http-8081 + initialDelaySeconds: 15 + periodSeconds: 20 + readinessProbe: + httpGet: + path: /readyz + port: http-8081 + initialDelaySeconds: 5 + periodSeconds: 10 resources: limits: cpu: 200m diff --git a/main.go b/main.go index f70438c099..5370d9ef10 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,8 @@ import ( "runtime" "strings" + "sigs.k8s.io/controller-runtime/pkg/healthz" + "github.com/spf13/pflag" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sruntime "k8s.io/apimachinery/pkg/runtime" @@ -68,12 +70,16 @@ func main() { v := version.Get() // add flags related to this operator - var metricsAddr string - var enableLeaderElection bool - var collectorImage string - var targetAllocatorImage string - var autoInstrumentationJava string + var ( + metricsAddr string + probeAddr string + enableLeaderElection bool + collectorImage string + targetAllocatorImage string + autoInstrumentationJava string + ) pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") + flag.StringVar(&probeAddr, "health-probe-address", ":8081", "The address the probe endpoint binds to.") pflag.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") @@ -124,12 +130,13 @@ func main() { } mgrOptions := ctrl.Options{ - Scheme: scheme, - MetricsBindAddress: metricsAddr, - Port: 9443, - LeaderElection: enableLeaderElection, - LeaderElectionID: "9f7554c3.opentelemetry.io", - Namespace: watchNamespace, + Scheme: scheme, + MetricsBindAddress: metricsAddr, + Port: 9443, + HealthProbeBindAddress: probeAddr, + LeaderElection: enableLeaderElection, + LeaderElectionID: "9f7554c3.opentelemetry.io", + Namespace: watchNamespace, } if strings.Contains(watchNamespace, ",") { @@ -206,6 +213,15 @@ func main() { } // +kubebuilder:scaffold:builder + if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up health check") + os.Exit(1) + } + if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up ready check") + os.Exit(1) + } + setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") From 1565cd6a122ed22bb2b1a0e9461b3a88d5cc7cbb Mon Sep 17 00:00:00 2001 From: Adrian Kostrubiak Date: Fri, 3 Dec 2021 11:27:59 -0500 Subject: [PATCH 2/5] fix manager port --- config/manager/manager.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 51bbdb2293..4057084d49 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -30,13 +30,13 @@ spec: livenessProbe: httpGet: path: /healthz - port: http-8081 + port: 8081 initialDelaySeconds: 15 periodSeconds: 20 readinessProbe: httpGet: path: /readyz - port: http-8081 + port: 8081 initialDelaySeconds: 5 periodSeconds: 10 resources: From 096b61cecf1bd9cb66b8dfea28291888224cd973 Mon Sep 17 00:00:00 2001 From: Adrian Kostrubiak Date: Fri, 3 Dec 2021 11:30:22 -0500 Subject: [PATCH 3/5] run `make bundle' to update csv --- ...opentelemetry-operator.clusterserviceversion.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index a022f288e1..9ec503968e 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -266,11 +266,23 @@ spec: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:v0.40.0 + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 name: manager ports: - containerPort: 9443 name: webhook-server protocol: TCP + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 resources: limits: cpu: 200m From 65943fe326f1c6c55484a42165db0a6940631381 Mon Sep 17 00:00:00 2001 From: Adrian Kostrubiak Date: Fri, 3 Dec 2021 11:43:11 -0500 Subject: [PATCH 4/5] nitty change flag naming to be more consistent with existing flags --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 5370d9ef10..861cd42130 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { autoInstrumentationJava string ) pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") - flag.StringVar(&probeAddr, "health-probe-address", ":8081", "The address the probe endpoint binds to.") + flag.StringVar(&probeAddr, "health-probe-addr", ":8081", "The address the probe endpoint binds to.") pflag.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") From 02a6f7369243ff71bb187626c8d71a9329cf4388 Mon Sep 17 00:00:00 2001 From: Adrian Kostrubiak Date: Mon, 6 Dec 2021 06:21:49 -0500 Subject: [PATCH 5/5] fix import ordering --- main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.go b/main.go index 861cd42130..e09f8928f2 100644 --- a/main.go +++ b/main.go @@ -22,8 +22,6 @@ import ( "runtime" "strings" - "sigs.k8s.io/controller-runtime/pkg/healthz" - "github.com/spf13/pflag" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sruntime "k8s.io/apimachinery/pkg/runtime" @@ -32,6 +30,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 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" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/webhook"