Skip to content

Commit

Permalink
✨ (go/v3-alpha) Add the liveness and readiness probe in the manager d…
Browse files Browse the repository at this point in the history
…eployment
  • Loading branch information
prafull01 committed Nov 22, 2020
1 parent 2c3ae8f commit f294eb8
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
{{- if not .ComponentConfig }}
- name: manager
args:
- "--probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ spec:
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
Expand Down
7 changes: 7 additions & 0 deletions pkg/plugins/golang/v3/scaffolds/internal/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ package main
import (
"flag"
"net/http"
"os"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -217,7 +218,9 @@ func main() {
{{- if not .ComponentConfig }}
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. " +
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -241,6 +244,7 @@ func main() {
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "{{ hashFNV .Repo }}.{{ .Domain }}",
})
Expand All @@ -264,6 +268,9 @@ func main() {
%s
_ = mgr.AddHealthzCheck("check", func(_ *http.Request) error { return nil })
_ = mgr.AddReadyzCheck("check", func(_ *http.Request) error { return nil })
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ spec:
name: https
- name: manager
args:
- "--probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
12 changes: 12 additions & 0 deletions testdata/project-v3-addon/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ spec:
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
Expand Down
17 changes: 12 additions & 5 deletions testdata/project-v3-addon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"net/http"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -50,7 +51,9 @@ func init() {
func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -63,11 +66,12 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "52ea9610.testproject.org",
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "52ea9610.testproject.org",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -100,6 +104,9 @@ func main() {
}
// +kubebuilder:scaffold:builder

_ = mgr.AddHealthzCheck("check", func(_ *http.Request) error { return nil })
_ = mgr.AddReadyzCheck("check", func(_ *http.Request) error { return nil })

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
12 changes: 12 additions & 0 deletions testdata/project-v3-config/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ spec:
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
Expand Down
4 changes: 4 additions & 0 deletions testdata/project-v3-config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"net/http"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -123,6 +124,9 @@ func main() {
}
// +kubebuilder:scaffold:builder

_ = mgr.AddHealthzCheck("check", func(_ *http.Request) error { return nil })
_ = mgr.AddReadyzCheck("check", func(_ *http.Request) error { return nil })

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ spec:
name: https
- name: manager
args:
- "--probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
12 changes: 12 additions & 0 deletions testdata/project-v3-multigroup/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ spec:
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
Expand Down
17 changes: 12 additions & 5 deletions testdata/project-v3-multigroup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"net/http"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -69,7 +70,9 @@ func init() {
func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -82,11 +85,12 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "14be1926.testproject.org",
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "14be1926.testproject.org",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -187,6 +191,9 @@ func main() {
}
// +kubebuilder:scaffold:builder

_ = mgr.AddHealthzCheck("check", func(_ *http.Request) error { return nil })
_ = mgr.AddReadyzCheck("check", func(_ *http.Request) error { return nil })

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ spec:
name: https
- name: manager
args:
- "--probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
12 changes: 12 additions & 0 deletions testdata/project-v3/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ spec:
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
Expand Down
17 changes: 12 additions & 5 deletions testdata/project-v3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"net/http"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -50,7 +51,9 @@ func init() {
func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -63,11 +66,12 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "dd1da13f.testproject.org",
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "dd1da13f.testproject.org",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -120,6 +124,9 @@ func main() {
}
// +kubebuilder:scaffold:builder

_ = mgr.AddHealthzCheck("check", func(_ *http.Request) error { return nil })
_ = mgr.AddReadyzCheck("check", func(_ *http.Request) error { return nil })

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down

0 comments on commit f294eb8

Please sign in to comment.