Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm ServiceAccount scaffolding NIL pointers #4562

Open
klaudworks opened this issue Feb 13, 2025 · 0 comments
Open

Helm ServiceAccount scaffolding NIL pointers #4562

klaudworks opened this issue Feb 13, 2025 · 0 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@klaudworks
Copy link

What broke? What's expected?

Problem 1: Helm doesn't short circuit and conditions

Creating a helm chart with kubebuilder edit --plugins=helm/v1-alpha creates a ServiceAccount template:

{{- if .Values.rbac.enable }}
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    {{- include "chart.labels" . | nindent 4 }}
  {{- if and .Values.controllerManager.serviceAccount .Values.controllerManager.serviceAccount.annotations }}
  annotations:
    {{- range $key, $value := .Values.controllerManager.serviceAccount.annotations }}
    {{ $key }}: {{ $value }}
    {{- end }}
  {{- end }}
  name: {{ .Values.controllerManager.serviceAccountName }}
  namespace: {{ .Release.Namespace }}
{{- end -}}

The issue is the following line of code:

  {{- if and .Values.controllerManager.serviceAccount .Values.controllerManager.serviceAccount.annotations }}

This does not work because Values.controllerManager.serviceAccount is not set by default and Helm evaluates all statements in the and condition first. I.e. the following error arises:

Error: template: kimi-operator/templates/rbac/service_account.yaml:7:61: executing "kimi-operator/templates/rbac/service_account.yaml" at <.Values.controllerManager.serviceAccount.annotations>: nil pointer evaluating interface {}.annotations

Same problem exists for pod.labels:

        {{- if and .Values.controllerManager.pod .Values.controllerManager.pod.labels }}
        {{- range $key, $value := .Values.controllerManager.pod.labels }}
        {{ $key }}: {{ $value }}
        {{- end }}
        {{- end }}

Proposed solution:
In both cases we can just use a with statement so that the subkey is not checked if the parent doesn't exist e.g.:

{{- with .Values.controllerManager.pod }}
  {{- if .labels }}
    {{- range $key, $value := .labels }}
      {{ $key }}: {{ $value }}
    {{- end }}
  {{- end }}
{{- end }}

Problem 2: webhook not set by default in values.yaml

The webhook key is not set by default in the values.yaml. However, in multiple places webhook.enabled is checked.

Proposed solution:
An easy consistent solution would be to just set the following in the values.yaml.

webhook:
  enable: false

If I make the above changes Helm can template the chart.
I'm happy to fix this if the proposed solutions are accepted.

Reproducing this issue

No response

KubeBuilder (CLI) Version

4.5.0

PROJECT version

No response

Plugin versions

Other versions

No response

Extra Labels

No response

@klaudworks klaudworks added the kind/bug Categorizes issue or PR as related to a bug. label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

1 participant