Skip to content

Commit

Permalink
Implement healthchecks. (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Nov 17, 2023
1 parent c858bf9 commit 78fe4a4
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 22 deletions.
12 changes: 12 additions & 0 deletions charts/gardener-extension-audit/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
networking.gardener.cloud/to-runtime-apiserver: allowed
networking.gardener.cloud/to-dns: allowed
networking.resources.gardener.cloud/to-all-shoots-kube-apiserver-tcp-443: allowed
networking.resources.gardener.cloud/to-all-shoots-audit-webhook-backend-tcp-2020: allowed
{{ include "labels" . | indent 8 }}
spec:
containers:
Expand All @@ -37,6 +38,17 @@ spec:
- --webhook-config-namespace={{ .Release.Namespace }}
- --webhook-config-server-port={{ .Values.webhookConfig.serverPort }}
- --disable-controllers={{ .Values.disableControllers | join "," }}
{{- if .Values.metricsPort }}
- --metrics-bind-address=:{{ .Values.metricsPort }}
{{- end }}
{{- if .Values.healthPort }}
- --health-bind-address=:{{ .Values.healthPort }}
{{- end }}
{{- if .Values.gardener.version }}
- --gardener-version={{ .Values.gardener.version }}
{{- end }}
- --log-level={{ .Values.logLevel | default "info" }}
- --log-format={{ .Values.logFormat | default "json" }}
env:
- name: LEADER_ELECTION_NAMESPACE
valueFrom:
Expand Down
1 change: 1 addition & 0 deletions charts/gardener-extension-audit/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ rules:
- leases
verbs:
- create
- update
- list
- watch
- apiGroups:
Expand Down
2 changes: 2 additions & 0 deletions charts/gardener-extension-audit/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ controllers:
concurrentSyncs: 5
healthcheck:
concurrentSyncs: 5
heartbeat:
renewIntervalSeconds: 30
ignoreOperationAnnotation: false

disableControllers: []
Expand Down
8 changes: 4 additions & 4 deletions cmd/gardener-extension-audit/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/metal-stack/gardener-extension-audit/pkg/apis/audit/install"
"github.com/metal-stack/gardener-extension-audit/pkg/controller"
"github.com/metal-stack/gardener-extension-audit/pkg/controller/audit"

extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
heartbeatcontroller "github.com/gardener/gardener/extensions/pkg/controller/heartbeat"
Expand Down Expand Up @@ -74,9 +74,9 @@ func (o *Options) run(ctx context.Context) error {
}

ctrlConfig := o.auditOptions.Completed()
ctrlConfig.Apply(&controller.DefaultAddOptions.Config)
o.controllerOptions.Completed().Apply(&controller.DefaultAddOptions.ControllerOptions)
o.reconcileOptions.Completed().Apply(&controller.DefaultAddOptions.IgnoreOperationAnnotation)
ctrlConfig.Apply(&audit.DefaultAddOptions.Config)
o.controllerOptions.Completed().Apply(&audit.DefaultAddOptions.ControllerOptions)
o.reconcileOptions.Completed().Apply(&audit.DefaultAddOptions.IgnoreOperationAnnotation)
o.heartbeatOptions.Completed().Apply(&heartbeatcontroller.DefaultAddOptions)

if err := o.controllerSwitches.Completed().AddToManager(mgr); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/gardener-extension-audit/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd"
heartbeatcmd "github.com/gardener/gardener/extensions/pkg/controller/heartbeat/cmd"
webhookcmd "github.com/gardener/gardener/extensions/pkg/webhook/cmd"
"k8s.io/client-go/tools/leaderelection/resourcelock"

auditcmd "github.com/metal-stack/gardener-extension-audit/pkg/cmd"
"k8s.io/client-go/tools/leaderelection/resourcelock"
)

// ExtensionName is the name of the extension.
Expand Down Expand Up @@ -55,6 +54,8 @@ func NewOptions() *Options {
LeaderElectionID: controllercmd.LeaderElectionNameID(ExtensionName),
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionNamespace: os.Getenv("LEADER_ELECTION_NAMESPACE"),
MetricsBindAddress: ":8080",
HealthBindAddress: ":8081",
},
controllerOptions: &controllercmd.ControllerOptions{
// This is a default value.
Expand Down
2 changes: 1 addition & 1 deletion example/controller-registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: audit
type: helm
providerConfig:
chart: H4sIAAAAAAAAA+0ca2/bOLKf9SsIdxdogZNkO7azENC7S1PfbnBtEiS9LA6HQ0BLtK1GErUUlSbX9r/f8CGZkmXLTtKk3XoQwDLFGQ45D85w6MwwC0hCmE1uOEmykCY2zoOQu88eDroA+8Oh/ASof8rn3t6g1x/2RyPR3hsMRt1naPiAPKyEPOOYIfSMUcrX9Wt7/53CbJX8D+eYcecWx9G9xxACHg0GK+Xf7+7V5D8awAfqPsD8WuEHlz9OwwvChNw9dN2zcJouvnadntO1ApL5LEy5bDtAv5EoRr5QDjSlDPE5QVJhUKlAVoJj4qFVmmVd1wZ46iX4oWGl/QfUd2b0QcZos//BqFez/yHAzv4fA1x3Rr2Z0ADMCcrmyPZRx3Fc+LsmSUCZOwv5PJ84Po3dQlkWD3PsX7kFuu3ThDMaRaBOjMzCjEMraJQDZJWPcNBPL3wMn3KAi/HZ+dHJ8Uv9ldzgOI2Iu4qK2IvQuFBTT1LsWJbrolPgAs+IdkskwZOIZKgysTxNqXZZujFMZtJ7+ZQx4nO0GBZVhrVSk/qfzVuttH9OQBiwdNn9I8Ht47/RYDjaxX+PARvI/3JOohT2bIend4sFW/x/r98bVuXf7+7v7+/8/2PAp082Csg0TAjqiLitg+wvX6yVsZvoDtuC7GSZuBGekChzIH50rsitoiK/5BPCEgJ65ITUFSNUaKwgcY2jXLPy6RMKEz/Kg5JBB2nENYws49YZFFQ8tKKHHl+OtDyLMAGdSXwi0Z0zEhGcEecYmGvkrGQtjGEbUZwhJN6EUzTH2SmD9zeok81xfzjyYNgLMTwMJfo7HM9QiZGyMOFT1Pk5+/vPWb0nIynNQk7Z7ToSMEfSRNC7M0GYrDHvukACkkb0Ni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pfEjYN4UhV3KIaWJWYZ5TOInKxqPJSsDaOg/FQg0kZdwZOt6M7yv/i0XN6Pefm255Vb2lWnb+/EjPrqxeO41hWJQj0LHXpXVQuiJDS8stXzbX/TZX/OJVGIQa5ovqk0OpFFX7jCFkf3+uqu0hdvN4DlS5/uutZ5mw6u31013Zt13Zt18z2f98IqUsAUAAA
values:
image:
tag: v0.1.0
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ package cmd

import (
controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd"
extensionshealthcheckcontroller "github.com/gardener/gardener/extensions/pkg/controller/healthcheck"
extensionsheartbeatcontroller "github.com/gardener/gardener/extensions/pkg/controller/heartbeat"
webhookcmd "github.com/gardener/gardener/extensions/pkg/webhook/cmd"
"github.com/metal-stack/gardener-extension-audit/pkg/controller"
"github.com/metal-stack/gardener-extension-audit/pkg/controller/audit"
"github.com/metal-stack/gardener-extension-audit/pkg/controller/healthcheck"
"github.com/metal-stack/gardener-extension-audit/pkg/webhook/kapiserver"
)

// ControllerSwitchOptions are the controllercmd.SwitchOptions for the provider controllers.
func ControllerSwitchOptions() *controllercmd.SwitchOptions {
return controllercmd.NewSwitchOptions(
controllercmd.Switch(controller.ControllerName, controller.AddToManager),
controllercmd.Switch(audit.ControllerName, audit.AddToManager),
controllercmd.Switch(extensionshealthcheckcontroller.ControllerName, healthcheck.AddToManager),
controllercmd.Switch(extensionsheartbeatcontroller.ControllerName, extensionsheartbeatcontroller.AddToManager),
)
}

Expand Down
37 changes: 27 additions & 10 deletions pkg/controller/actuator.go → pkg/controller/audit/actuator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controller
package audit

import (
"context"
Expand All @@ -23,7 +23,7 @@ import (
"github.com/go-logr/logr"
"github.com/metal-stack/gardener-extension-audit/pkg/apis/audit/v1alpha1"
"github.com/metal-stack/gardener-extension-audit/pkg/apis/config"
"github.com/metal-stack/gardener-extension-audit/pkg/controller/fluentbitconfig"
"github.com/metal-stack/gardener-extension-audit/pkg/fluentbitconfig"
"github.com/metal-stack/gardener-extension-audit/pkg/imagevector"
"github.com/metal-stack/metal-lib/pkg/pointer"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -274,15 +274,22 @@ func seedObjects(auditConfig *v1alpha1.AuditConfig, secrets map[string]*corev1.S
Data: map[string]string{
"fluent-bit.conf": fluentbitconfig.Config{
Service: map[string]string{
"log_level": "info",
"log_level": "info",

"http_server": "on",
"http_listen": "0.0.0.0",
"http_port": "2020",

"storage.path": "/data/",
"storage.sync": "normal",
"storage.checksum": "off",
"storage.max_chunks_up": "128",
"storage.backlog.mem_limit": "5M",
"http_server": "on",
"http_listen": "0.0.0.0",
"http_port": "2020",

"health_check": "on",
"hc_errors_count": "0",
"hc_retry_failure_count": "0",
"hc_period": "60",
},
Input: []fluentbitconfig.Input{
map[string]string{
Expand Down Expand Up @@ -333,10 +340,11 @@ func seedObjects(auditConfig *v1alpha1.AuditConfig, secrets map[string]*corev1.S
"networking.resources.gardener.cloud/to-audit-cluster-forwarding-vpn-gateway-tcp-9876": "allowed",
},
Annotations: map[string]string{
"scheduler.alpha.kubernetes.io/critical-pod": "",
"prometheus.io/scrape": "true",
"prometheus.io/port": "2020",
"prometheus.io/path": "/api/v1/metrics/prometheus",
"scheduler.alpha.kubernetes.io/critical-pod": "",
"networking.resources.gardener.cloud/to-world-from-ports": `[{"port":2020,"protocol":"TCP"}]`,
"prometheus.io/scrape": "true",
"prometheus.io/port": "2020",
"prometheus.io/path": "/api/v1/metrics/prometheus",
},
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -452,6 +460,10 @@ func seedObjects(auditConfig *v1alpha1.AuditConfig, secrets map[string]*corev1.S
ObjectMeta: metav1.ObjectMeta{
Name: "audit-webhook-backend",
Namespace: namespace,
Annotations: map[string]string{
"networking.resources.gardener.cloud/pod-label-selector-namespace-alias": "all-shoots",
"networking.resources.gardener.cloud/namespace-selectors": `[{"matchLabels":{"gardener.cloud/role":"extension"}}]`,
},
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{
Expand All @@ -463,6 +475,11 @@ func seedObjects(auditConfig *v1alpha1.AuditConfig, secrets map[string]*corev1.S
Port: 9880,
Protocol: corev1.ProtocolTCP,
},
{
Name: "api",
Port: 2020,
Protocol: corev1.ProtocolTCP,
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/add.go → pkg/controller/audit/add.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controller
package audit

import (
"github.com/gardener/gardener/extensions/pkg/controller/extension"
Expand Down
74 changes: 74 additions & 0 deletions pkg/controller/healthcheck/backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package healthcheck

import (
"context"
"fmt"
"io"
"net/http"

"github.com/gardener/gardener/extensions/pkg/controller/healthcheck"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/types"
)

type BackendHealthChecker struct {
logger logr.Logger
httpClient *http.Client
}

func backendHealth() healthcheck.HealthCheck {
return &BackendHealthChecker{
httpClient: http.DefaultClient,
}
}

func (h *BackendHealthChecker) SetLoggerSuffix(provider, extension string) {
h.logger = h.logger.WithName(fmt.Sprintf("%s-%s-healthcheck-backend", provider, extension))
}

func (h *BackendHealthChecker) DeepCopy() healthcheck.HealthCheck {
copy := *h
return &copy
}

func (h *BackendHealthChecker) Check(ctx context.Context, request types.NamespacedName) (*healthcheck.SingleCheckResult, error) {
err := h.check(ctx, request.Namespace)
if err != nil {
return &healthcheck.SingleCheckResult{ // nolint:nilerr
Status: gardencorev1beta1.ConditionFalse,
Detail: err.Error(),
}, nil
}

return &healthcheck.SingleCheckResult{
Status: gardencorev1beta1.ConditionTrue,
}, nil
}

func (h *BackendHealthChecker) check(ctx context.Context, namespace string) error {
url := fmt.Sprintf("http://audit-webhook-backend.%s.svc.cluster.local:2020/api/v1/health", namespace)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("unable to create http request: %w", err)
}

resp, err := h.httpClient.Do(req)
if err != nil {
return fmt.Errorf("unable to do http request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
return nil
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("unable to read http body: %w", err)
}

return fmt.Errorf("backend is unhealthy since errors or failued have occurred in the last minute time frame: %s", string(body))
}
49 changes: 49 additions & 0 deletions pkg/controller/healthcheck/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package healthcheck

import (
"time"

extensionsconfig "github.com/gardener/gardener/extensions/pkg/apis/config"
"github.com/gardener/gardener/extensions/pkg/controller/healthcheck"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/metal-stack/gardener-extension-audit/pkg/controller/audit"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

var (
defaultSyncPeriod = time.Second * 30
// DefaultAddOptions contains configuration for the health check controller.
DefaultAddOptions = healthcheck.DefaultAddArgs{
HealthCheckConfig: extensionsconfig.HealthCheckConfig{SyncPeriod: metav1.Duration{Duration: defaultSyncPeriod}},
}
)

// RegisterHealthChecks registers health checks for each extension resource
// HealthChecks are grouped by extension (e.g worker), extension.type (e.g aws) and Health Check Type (e.g SystemComponentsHealthy)
func RegisterHealthChecks(mgr manager.Manager, opts healthcheck.DefaultAddArgs) error {
return healthcheck.DefaultRegistration(
audit.Type,
extensionsv1alpha1.SchemeGroupVersion.WithKind(extensionsv1alpha1.ExtensionResource),
func() client.ObjectList { return &extensionsv1alpha1.ExtensionList{} },
func() extensionsv1alpha1.Object { return &extensionsv1alpha1.Extension{} },
mgr,
opts,
nil,
[]healthcheck.ConditionTypeToHealthCheck{
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: backendHealth(),
},
},
sets.New(gardencorev1beta1.ShootSystemComponentsHealthy),
)
}

// AddToManager adds a controller with the default Options.
func AddToManager(mgr manager.Manager) error {
return RegisterHealthChecks(mgr, DefaultAddOptions)
}
File renamed without changes.
Loading

0 comments on commit 78fe4a4

Please sign in to comment.