Skip to content

Commit

Permalink
Setup health and ready endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed Oct 21, 2020
1 parent 3315e66 commit f17aa63
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
15 changes: 11 additions & 4 deletions config/manager/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ spec:
ports:
- containerPort: 8080
name: http-prom
- containerPort: 9440
name: healthz
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
env:
- name: RUNTIME_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
livenessProbe:
httpGet:
port: http-prom
path: /metrics
args:
- --watch-all-namespaces
- --log-level=info
Expand Down
32 changes: 25 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"

kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
Expand Down Expand Up @@ -54,6 +55,7 @@ func main() {
var (
metricsAddr string
eventsAddr string
healthAddr string
enableLeaderElection bool
concurrent int
requeueDependency time.Duration
Expand All @@ -64,6 +66,7 @@ func main() {

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&eventsAddr, "events-addr", "", "The address of the events receiver.")
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand Down Expand Up @@ -96,19 +99,22 @@ func main() {
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7593cc5d.fluxcd.io",
Namespace: watchNamespace,
Logger: ctrl.Log,
Scheme: scheme,
MetricsBindAddress: metricsAddr,
HealthProbeBindAddress: healthAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7593cc5d.fluxcd.io",
Namespace: watchNamespace,
Logger: ctrl.Log,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

setupChecks(mgr)

if err = (&controllers.GitRepositoryWatcher{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName(sourcev1.GitRepositoryKind),
Expand Down Expand Up @@ -148,3 +154,15 @@ func main() {
os.Exit(1)
}
}

func setupChecks(mgr ctrl.Manager) {
if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}

if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create health check")
os.Exit(1)
}
}

0 comments on commit f17aa63

Please sign in to comment.