Skip to content

Commit

Permalink
Add handling for logging configuration migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Oct 3, 2023
1 parent 73bbc0b commit 4214bde
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 31 deletions.
15 changes: 10 additions & 5 deletions charts/karpenter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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. |
Expand Down
22 changes: 18 additions & 4 deletions charts/karpenter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,35 @@ 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 -}}

{{/*
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 -}}
18 changes: 8 additions & 10 deletions charts/karpenter/templates/configmap-logging.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.logConfig.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -13,17 +14,17 @@ 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,
"sampling": {
"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",
Expand All @@ -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 }}
21 changes: 15 additions & 6 deletions charts/karpenter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
28 changes: 22 additions & 6 deletions charts/karpenter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4214bde

Please sign in to comment.