From 4214bde3746e15a049047d9047b20d83091749d0 Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Fri, 29 Sep 2023 13:55:41 -0500 Subject: [PATCH] Add handling for logging configuration migration --- charts/karpenter/README.md | 15 ++++++---- charts/karpenter/templates/_helpers.tpl | 22 ++++++++++++--- .../templates/configmap-logging.yaml | 18 ++++++------ charts/karpenter/templates/deployment.yaml | 21 ++++++++++---- charts/karpenter/values.yaml | 28 +++++++++++++++---- 5 files changed, 73 insertions(+), 31 deletions(-) diff --git a/charts/karpenter/README.md b/charts/karpenter/README.md index a407e310c284..d9ce8c987036 100644 --- a/charts/karpenter/README.md +++ b/charts/karpenter/README.md @@ -34,16 +34,15 @@ helm upgrade --install --namespace karpenter --create-namespace \ | affinity | object | `{"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"karpenter.sh/provisioner-name","operator":"DoesNotExist"}]}]}},"podAntiAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":[{"topologyKey":"kubernetes.io/hostname"}]}}` | Affinity rules for scheduling the pod. If an explicit label selector is not provided for pod affinity or pod anti-affinity one will be created from the pod selector labels. | | controller.env | list | `[]` | Additional environment variables for the controller pod. | | controller.envFrom | list | `[]` | | -| controller.errorOutputPaths | list | `["stderr"]` | Controller errorOutputPaths - default to stderr only | +| controller.errorOutputPaths | list | `["stderr"]` | Controller errorOutputPaths - defaults to stderr only (Deprecated: Use logConfig.errorOutputPaths instead) | | controller.extraVolumeMounts | list | `[]` | Additional volumeMounts for the controller pod. | | controller.healthProbe.port | int | `8081` | The container port to use for http health probe. | | controller.image.digest | string | `"sha256:d29767fa9c5c0511a3812397c932f5735234f03a7a875575422b712d15e54a77"` | SHA256 digest of the controller image. | | controller.image.repository | string | `"public.ecr.aws/karpenter/controller"` | Repository path to the controller image. | | controller.image.tag | string | `"v0.31.0"` | Tag of the controller image. | -| controller.logEncoding | string | `""` | Controller log encoding, defaults to the global log encoding | -| controller.logLevel | string | `""` | Controller log level, defaults to the global log level | +| controller.logLevel | string | `""` | Controller log level, defaults to the global log level (Deprecated: Use logConfig.logLevel.controller instead) | | controller.metrics.port | int | `8000` | The container port to use for metrics. | -| controller.outputPaths | list | `["stdout"]` | Controller outputPaths - default to stdout only | +| controller.outputPaths | list | `["stdout"]` | Controller outputPaths - defaults to stdout only (Deprecated: Use logConfig.outputPaths instead) | | controller.resources | object | `{}` | Resources for the controller pod. | | controller.sidecarContainer | list | `[]` | Additional sidecarContainer config | | controller.sidecarVolumeMounts | list | `[]` | Additional volumeMounts for the sidecar - this will be added to the volume mounts on top of extraVolumeMounts | @@ -54,7 +53,13 @@ helm upgrade --install --namespace karpenter --create-namespace \ | hostNetwork | bool | `false` | Bind the pod to the host network. This is required when using a custom CNI. | | imagePullPolicy | string | `"IfNotPresent"` | Image pull policy for Docker images. | | imagePullSecrets | list | `[]` | Image pull secrets for Docker images. | -| logEncoding | string | `"console"` | Global log encoding | +| logConfig | object | `{"enabled":true,"errorOutputPaths":["stderr"],"logEncoding":"console","logLevel":{"controller":"debug","global":"debug","webhook":"error"},"outputPaths":["stdout"]}` | Log configuration | +| logConfig.enabled | bool | `true` | Whether to enable provisioning and mounting the log ConfigMap | +| logConfig.errorOutputPaths | list | `["stderr"]` | Log errorOutputPaths - defaults to stderr only | +| logConfig.logEncoding | string | `"console"` | Log encoding - defaults to console - must be one of 'json', 'console' | +| logConfig.logLevel | object | `{"controller":"debug","global":"debug","webhook":"error"}` | Component-based log configuration | +| logConfig.outputPaths | list | `["stdout"]` | Log outputPaths - defaults to stdout only | +| logEncoding | string | `"console"` | Global log encoding (Deprecated: Use logConfig.logEncoding instead) | | logLevel | string | `"debug"` | Global log level | | nameOverride | string | `""` | Overrides the chart's name. | | nodeSelector | object | `{"kubernetes.io/os":"linux"}` | Node selectors to schedule the pod to nodes with labels. | diff --git a/charts/karpenter/templates/_helpers.tpl b/charts/karpenter/templates/_helpers.tpl index 5dfa6bd94809..c59591fd0c75 100644 --- a/charts/karpenter/templates/_helpers.tpl +++ b/charts/karpenter/templates/_helpers.tpl @@ -171,10 +171,17 @@ Flatten Settings Map using "." syntax {{/* Flatten the stdout logging outputs from args provided */}} -{{- define "karpenter.controller.outputPathsList" -}} +{{- define "karpenter.outputPathsList" -}} {{ $paths := list -}} {{- range .Values.controller.outputPaths -}} - {{- $paths = printf "%s" . | quote | append $paths -}} + {{- if not (has (printf "%s" . | quote) $paths) -}} + {{- $paths = printf "%s" . | quote | append $paths -}} + {{- end -}} +{{- end -}} +{{- range .Values.logConfig.outputPaths -}} + {{- if not (has (printf "%s" . | quote) $paths) -}} + {{- $paths = printf "%s" . | quote | append $paths -}} + {{- end -}} {{- end -}} {{ $paths | join ", " }} {{- end -}} @@ -182,10 +189,17 @@ Flatten the stdout logging outputs from args provided {{/* Flatten the stderr logging outputs from args provided */}} -{{- define "karpenter.controller.errorOutputPathsList" -}} +{{- define "karpenter.errorOutputPathsList" -}} {{ $paths := list -}} {{- range .Values.controller.errorOutputPaths -}} - {{- $paths = printf "%s" . | quote | append $paths -}} + {{- if not (has (printf "%s" . | quote) $paths) -}} + {{- $paths = printf "%s" . | quote | append $paths -}} + {{- end -}} +{{- end -}} +{{- range .Values.logConfig.errorOutputPaths -}} + {{- if not (has (printf "%s" . | quote) $paths) -}} + {{- $paths = printf "%s" . | quote | append $paths -}} + {{- end -}} {{- end -}} {{ $paths | join ", " }} {{- end -}} diff --git a/charts/karpenter/templates/configmap-logging.yaml b/charts/karpenter/templates/configmap-logging.yaml index 604e5e66a66a..925ee4ce5b11 100644 --- a/charts/karpenter/templates/configmap-logging.yaml +++ b/charts/karpenter/templates/configmap-logging.yaml @@ -1,3 +1,4 @@ +{{- if .Values.logConfig.enabled -}} apiVersion: v1 kind: ConfigMap metadata: @@ -13,7 +14,7 @@ data: # https://github.com/uber-go/zap/blob/aa3e73ec0896f8b066ddf668597a02f89628ee50/config.go zap-logger-config: | { - "level": "{{ .Values.logLevel }}", + "level": "{{ or .Values.logLevel .Values.logConfig.logLevel.global }}", "development": false, "disableStacktrace": true, "disableCaller": true, @@ -21,9 +22,9 @@ data: "initial": 100, "thereafter": 100 }, - "outputPaths": [{{ include "karpenter.controller.outputPathsList" . }}], - "errorOutputPaths": [{{ include "karpenter.controller.errorOutputPathsList" . }}], - "encoding": "{{ .Values.logEncoding }}", + "outputPaths": [{{ or (include "karpenter.outputPathsList" .) }}], + "errorOutputPaths": [{{ include "karpenter.errorOutputPathsList" . }}], + "encoding": "{{ or .Values.logEncoding .Values.logConfig.logEncoding }}", "encoderConfig": { "timeKey": "time", "levelKey": "level", @@ -35,9 +36,6 @@ data: "timeEncoder": "iso8601" } } -{{- with .Values.controller.logLevel }} - loglevel.controller: {{ . | quote }} -{{- end }} -{{- with .Values.webhook.logLevel }} - loglevel.webhook: {{ . | quote }} -{{- end }} + loglevel.controller: {{ or .Values.controller.logLevel .Values.logConfig.logLevel.controller }} + loglevel.webhook: {{ or .Values.webhook.logLevel .Values.logConfig.logLevel.webhook }} +{{- end }} \ No newline at end of file diff --git a/charts/karpenter/templates/deployment.yaml b/charts/karpenter/templates/deployment.yaml index 3f3429c3d902..c1d70cb2d4a7 100644 --- a/charts/karpenter/templates/deployment.yaml +++ b/charts/karpenter/templates/deployment.yaml @@ -134,22 +134,28 @@ spec: resources: {{- toYaml . | nindent 12 }} {{- end }} - {{- with .Values.controller.extraVolumeMounts }} + {{- if or .Values.logConfig.enabled .Values.controller.extraVolumeMounts }} volumeMounts: + {{- if .Values.logConfigEnabled }} + - name: config-logging + mountPath: /etc/karpenter/logging + {{- end }} + {{- with .Values.controller.extraVolumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} + {{- end }} {{- with .Values.controller.sidecarContainer }} - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} {{- if and (.Values.controller.sidecarContainer) (or .Values.controller.extraVolumeMounts .Values.controller.sidecarVolumeMounts) }} volumeMounts: {{- with .Values.controller.extraVolumeMounts }} - {{- toYaml . | nindent 12 }} + {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.controller.sidecarVolumeMounts }} - {{- toYaml . | nindent 12 }} + {{- toYaml . | nindent 12 }} {{- end }} - {{- end }} + {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} @@ -170,7 +176,10 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.extraVolumes }} volumes: + - name: config-logging + configMap: + name: config-logging + {{- with .Values.extraVolumes }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/charts/karpenter/values.yaml b/charts/karpenter/values.yaml index 8384deee7975..309235699eac 100644 --- a/charts/karpenter/values.yaml +++ b/charts/karpenter/values.yaml @@ -117,16 +117,14 @@ controller: # cpu: 1 # memory: 1Gi - # -- Controller outputPaths - default to stdout only + # -- Controller outputPaths - defaults to stdout only (Deprecated: Use logConfig.outputPaths instead) outputPaths: - stdout - # -- Controller errorOutputPaths - default to stderr only + # -- Controller errorOutputPaths - defaults to stderr only (Deprecated: Use logConfig.errorOutputPaths instead) errorOutputPaths: - stderr - # -- Controller log level, defaults to the global log level + # -- Controller log level, defaults to the global log level (Deprecated: Use logConfig.logLevel.controller instead) logLevel: "" - # -- Controller log encoding, defaults to the global log encoding - logEncoding: "" # -- Additional volumeMounts for the controller pod. extraVolumeMounts: [] # - name: aws-iam-token @@ -145,6 +143,7 @@ controller: webhook: # -- Whether to enable the webhooks and webhook permissions. enabled: true + # -- Webhook log level (Deprecated: Use logConfig.logLevel.webhook instead) logLevel: error # -- The container port to use for the webhook. port: 8443 @@ -153,8 +152,25 @@ webhook: port: 8001 # -- Global log level logLevel: debug -# -- Global log encoding +# -- Global log encoding (Deprecated: Use logConfig.logEncoding instead) logEncoding: console +# -- Log configuration +logConfig: + # -- Whether to enable provisioning and mounting the log ConfigMap + enabled: true + # -- Log outputPaths - defaults to stdout only + outputPaths: + - stdout + # -- Log errorOutputPaths - defaults to stderr only + errorOutputPaths: + - stderr + # -- Log encoding - defaults to console - must be one of 'json', 'console' + logEncoding: console + # -- Component-based log configuration + logLevel: + global: debug + controller: debug + webhook: error # -- Global Settings to configure Karpenter settings: # -- The maximum length of a batch window. The longer this is, the more pods we can consider for provisioning at one