Skip to content

Commit

Permalink
Add healthprobe for bootstrap and controlplane
Browse files Browse the repository at this point in the history
Signed-off-by: chymy <[email protected]>
  • Loading branch information
chymy committed Apr 13, 2021
1 parent 2cbeb17 commit cdefccd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
12 changes: 12 additions & 0 deletions bootstrap/kubeadm/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ spec:
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=false}"
image: controller:latest
name: manager
ports:
- containerPort: 9440
name: healthz
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
terminationGracePeriodSeconds: 10
serviceAccountName: manager
tolerations:
Expand Down
23 changes: 21 additions & 2 deletions bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -71,6 +72,7 @@ var (
syncPeriod time.Duration
webhookPort int
webhookCertDir string
healthAddr string
)

func InitFlags(fs *pflag.FlagSet) {
Expand Down Expand Up @@ -110,6 +112,9 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
"Webhook cert dir, only used when webhook-port is specified.")

fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

feature.MutableGates.AddFlag(fs)
}

Expand Down Expand Up @@ -144,8 +149,9 @@ func main() {
&corev1.ConfigMap{},
&corev1.Secret{},
},
Port: webhookPort,
CertDir: webhookCertDir,
Port: webhookPort,
HealthProbeBindAddress: healthAddr,
CertDir: webhookCertDir,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand All @@ -155,6 +161,7 @@ func main() {
// Setup the context that's going to be used in controllers and for the manager.
ctx := ctrl.SetupSignalHandler()

setupChecks(mgr)
setupWebhooks(mgr)
setupReconcilers(ctx, mgr)

Expand All @@ -166,6 +173,18 @@ func main() {
}
}

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)
}
}

func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&kubeadmbootstrapcontrollers.KubeadmConfigReconciler{
Client: mgr.GetClient(),
Expand Down
12 changes: 12 additions & 0 deletions controlplane/kubeadm/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ spec:
- "--metrics-bind-addr=127.0.0.1:8080"
image: controller:latest
name: manager
ports:
- containerPort: 9440
name: healthz
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
terminationGracePeriodSeconds: 10
serviceAccountName: manager
tolerations:
Expand Down
23 changes: 21 additions & 2 deletions controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -71,6 +72,7 @@ var (
syncPeriod time.Duration
webhookPort int
webhookCertDir string
healthAddr string
)

// InitFlags initializes the flags.
Expand Down Expand Up @@ -107,6 +109,9 @@ func InitFlags(fs *pflag.FlagSet) {

fs.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
"Webhook cert dir, only used when webhook-port is specified.")

fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")
}
func main() {
rand.Seed(time.Now().UnixNano())
Expand Down Expand Up @@ -139,8 +144,9 @@ func main() {
&corev1.ConfigMap{},
&corev1.Secret{},
},
Port: webhookPort,
CertDir: webhookCertDir,
Port: webhookPort,
HealthProbeBindAddress: healthAddr,
CertDir: webhookCertDir,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand All @@ -150,6 +156,7 @@ func main() {
// Setup the context that's going to be used in controllers and for the manager.
ctx := ctrl.SetupSignalHandler()

setupChecks(mgr)
setupReconcilers(ctx, mgr)
setupWebhooks(mgr)

Expand All @@ -161,6 +168,18 @@ func main() {
}
}

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)
}
}

func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
// Set up a ClusterCacheTracker to provide to controllers
// requiring a connection to a remote cluster
Expand Down

0 comments on commit cdefccd

Please sign in to comment.