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

Unable to get extraInitContainers to work #1423

Closed
vuldin opened this issue Jul 16, 2024 · 3 comments
Closed

Unable to get extraInitContainers to work #1423

vuldin opened this issue Jul 16, 2024 · 3 comments

Comments

@vuldin
Copy link
Member

vuldin commented Jul 16, 2024

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.

$ helm get values <redpanda-release-name> -n <redpanda-release-namespace> --all
# paste output here

Anything else we need to know?

No response

Which are the affected charts?

Redpanda

Chart Version(s)

$ helm -n <redpanda-release-namespace> list 
# paste output here

5.8.12

Cloud provider

self-hosted (kind)

JIRA Link: K8S-292

@jan-g
Copy link
Contributor

jan-g commented Jul 17, 2024

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
Copy link
Contributor

See also #1427

@vuldin
Copy link
Member Author

vuldin commented Jul 24, 2024

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

@vuldin vuldin closed this as completed Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants