Skip to content

Commit

Permalink
Added liveness probes to the karpenter controller (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn authored May 19, 2021
1 parent ce119ae commit 1009568
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion charts/karpenter/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ spec:
ports:
- name: webhook
containerPort: 9443
protocol: TCP
- name: metrics
containerPort: 8080
- name: health-probe
containerPort: 8081
livenessProbe:
httpGet:
path: /healthz
port: 8081
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
Expand Down
13 changes: 8 additions & 5 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ type Options struct {
EnableVerboseLogging bool
MetricsPort int
WebhookPort int
HealthProbePort int
}

func main() {
flag.BoolVar(&options.EnableVerboseLogging, "verbose", false, "Enable verbose logging")
flag.IntVar(&options.WebhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to for validation and mutation of resources")
flag.IntVar(&options.MetricsPort, "metrics-port", 8080, "The port the metric endpoint binds to for operating metrics about the controller itself")
flag.IntVar(&options.HealthProbePort, "health-probe-port", 8081, "The port the health probe endpoint binds to for reporting controller health")
flag.Parse()

log.Setup(
Expand All @@ -53,11 +55,12 @@ func main() {
controllerruntimezap.StacktraceLevel(zapcore.DPanicLevel),
)
manager := controllers.NewManagerOrDie(controllerruntime.GetConfigOrDie(), controllerruntime.Options{
LeaderElection: true,
LeaderElectionID: "karpenter-leader-election",
Scheme: scheme,
MetricsBindAddress: fmt.Sprintf(":%d", options.MetricsPort),
Port: options.WebhookPort,
LeaderElection: true,
LeaderElectionID: "karpenter-leader-election",
Scheme: scheme,
Port: options.WebhookPort,
MetricsBindAddress: fmt.Sprintf(":%d", options.MetricsPort),
HealthProbeBindAddress: fmt.Sprintf(":%d", options.HealthProbePort),
})

clientSet := kubernetes.NewForConfigOrDie(manager.GetConfig())
Expand Down
4 changes: 4 additions & 0 deletions pkg/controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
controllerruntime "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"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)
Expand Down Expand Up @@ -79,6 +80,9 @@ func (m *GenericControllerManager) RegisterControllers(controllers ...Controller
log.PanicIfError(controllerruntime.NewWebhookManagedBy(m).For(controlledObject).Complete(),
"Failed to register controller to manager for %s", controlledObject)
}
if err := m.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.PanicIfError(err, "Failed to add readiness probe")
}
return m
}

Expand Down

0 comments on commit 1009568

Please sign in to comment.