redpanda-data / helm-charts

Redpanda Helm Chart
http://redpanda.com
Apache License 2.0
78 stars 96 forks source link

Unable to get `extraInitContainers` to work #1423

Closed vuldin closed 3 months ago

vuldin commented 4 months ago

What happened?

I'm trying to create an extra initContainer with the folling values.yaml:

statefulset:
  initContainers:
    extraInitContainers: |-
    - name: "update-advertised-rpc"
      image: "mintel/docker-alpine-bash-curl-yq:latest"
      command: [ "/bin/bash", "-c" ]
      args:
      - |
        cat << EOF > advertised-rpc.yaml
        redpanda:
          advertised_rpc_api:
            address: $SERVICE_NAME
            port: 33145
        EOF
        yq '. *= load("advertised-rpc.yaml")' /etc/redpanda/redpanda.yaml >> redpanda.yaml
        mv redpanda.yaml /etc/redpanda/redpanda.yaml
        chown 101:101 /etc/redpanda/redpanda.yaml

And running into this error:

timeout 1h -f values-update-advertised-rpc.yaml --debug        
history.go:56: [debug] getting history for release redpanda
Release "redpanda" does not exist. Installing it now.
install.go:200: [debug] Original chart version: ""
install.go:217: [debug] CHART PATH: /home/vuldin/projects/redpanda/helm-charts/charts/redpanda

Error: failed to parse values-update-advertised-rpc.yaml: error converting YAML to JSON: yaml: line 3: did not find expected key
helm.go:84: [debug] error converting YAML to JSON: yaml: line 3: did not find expected key
failed to parse values-update-advertised-rpc.yaml
helm.sh/helm/v3/pkg/cli/values.(*Options).MergeValues
        helm.sh/helm/v3/pkg/cli/values/options.go:57
main.runInstall
        helm.sh/helm/v3/cmd/helm/install.go:220
main.newUpgradeCmd.func2
        helm.sh/helm/v3/cmd/helm/upgrade.go:130
github.com/spf13/cobra.(*Command).execute
        github.com/spf13/cobra@v1.6.1/command.go:916
github.com/spf13/cobra.(*Command).ExecuteC
        github.com/spf13/cobra@v1.6.1/command.go:1044
github.com/spf13/cobra.(*Command).Execute
        github.com/spf13/cobra@v1.6.1/command.go:968
main.main
        helm.sh/helm/v3/cmd/helm/helm.go:83
runtime.main
        runtime/proc.go:250
runtime.goexit
        runtime/asm_amd64.s:1598

When I change extraInitContainers: |- to extraInitContainers: I get the following error:

Error: INSTALLATION FAILED: values don't meet the specifications of the schema(s) in the following chart(s):
redpanda:
- statefulset.initContainers.extraInitContainers: Invalid type. Expected: string, given: array

I'm following the example in values.yaml for this parameter closely. The only difference is the commands I'm running in the initContainer.

What did you expect to happen?

An initContainer should have been started up successfully.

How can we reproduce it (as minimally and precisely as possible)?. Please include values file.

```console $ helm get values -n --all # paste output here ```

Anything else we need to know?

No response

Which are the affected charts?

Redpanda

Chart Version(s)

```console $ helm -n list # paste output here ``` 5.8.12

Cloud provider

self-hosted (kind)

JIRA Link: K8S-292

jan-g commented 4 months ago

I think this is a "yaml is awful" error.

For historical reasons, extraInitContainers takes a single string parameter (which is template-expanded) and treated as yaml input.

Although this looks like an ordinary yaml array with the |- characters at the start, the rules for parsing the |--delimited string require additional indentation.

statefulset:
  initContainers:
    extraInitContainers: |-
      - name: "update-advertised-rpc"
        image: "mintel/docker-alpine-bash-curl-yq:latest"
        command: [ "/bin/bash", "-c" ]
        args:
        - |
          cat << EOF > advertised-rpc.yaml
          redpanda:
            advertised_rpc_api:
              address: $SERVICE_NAME
              port: 33145
          EOF
          yq '. *= load("advertised-rpc.yaml")' /etc/redpanda/redpanda.yaml >> redpanda.yaml
          mv redpanda.yaml /etc/redpanda/redpanda.yaml
          chown 101:101 /etc/redpanda/redpanda.yaml

I think that values.yaml includes this extra indentation in the commented-out example but doesn't make it clear that it's required. This isn't helped because it looks like the error message is counting lines from 0; it's currently parsing initContainers as an object and has found the extraInitContainers: "" and is looking for another dictionary key, but instead it sees an array element.

chrisseto commented 4 months ago

See also https://github.com/redpanda-data/helm-charts/issues/1427

vuldin commented 3 months ago

Circling back on this, @jan-g was right! Adding the additional (ie. the correct amount of) indentation allowed the extraInitContainers config to work.