Skip to content

Helm Chart: Adding support for secrets enabled multi-cluster#4938

Open
cmcgalliard wants to merge 12 commits intokubernetes-sigs:mainfrom
cmcgalliard:multicluster
Open

Helm Chart: Adding support for secrets enabled multi-cluster#4938
cmcgalliard wants to merge 12 commits intokubernetes-sigs:mainfrom
cmcgalliard:multicluster

Conversation

@cmcgalliard
Copy link
Copy Markdown

Summary

This simplifies the process of configuring kubeconfigs in secrets for Headlamp. This functionality already exists; the Helm chart just doesn't make it easy to configure.

Changes

  • Updated Deployments YAML to add volumes for each secret
  • Updated Deployments YAML to target each kubeconfig mount in the KUBECONFIG envvar
  • Updated values file to allow for a list of secrets containing kubeconfigs
  • Updated helm documentation

Steps to Test

  1. Create 1+ secret containing a kubeconfig

  2. Configure the kubeconfigSecrets

# kubeconfigSecrets:
  #   - secretName: prod-cluster-kubeconfig
  #     key: config  # optional, defaults to "config"
  1. Disable the inCluster kubeconfkg (there is a conflict in the code here, documented in my PR)
config:
  inCluster: false
  1. helm install headlamp
  2. navigate to clusters, validate that you can see multiple clusters configured with secrets you provided.

Screenshots (if applicable)

image

Notes for the Reviewer

I considered changing it so we could use the in-cluster kubeconfig, but I'm not sure whether you all have intentionally chosen this pattern.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cmcgalliard
Once this PR has been reviewed and has the lgtm label, please assign yolossn for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from sniok and yolossn March 22, 2026 22:20
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 22, 2026

CLA Not Signed

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @cmcgalliard!

It looks like this is your first PR to kubernetes-sigs/headlamp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/headlamp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Helm chart support for configuring Headlamp multi-cluster access via one or more kubeconfig files stored in Kubernetes Secrets, by mounting each secret and building a KUBECONFIG env var pointing at the mounted files.

Changes:

  • Introduces config.kubeconfigSecrets in chart values and documents how to use it.
  • Updates the Deployment template to mount each referenced secret and set KUBECONFIG accordingly.
  • Adds Helm helper templates to detect/configure kubeconfig secret usage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
charts/headlamp/values.yaml Adds config.kubeconfigSecrets values entry with inline documentation.
charts/headlamp/templates/deployment.yaml Mounts kubeconfig secrets as volumes/volumeMounts and sets KUBECONFIG env var.
charts/headlamp/templates/_helpers.tpl Adds helpers to build the KUBECONFIG path and detect whether secrets are configured.
charts/headlamp/README.md Documents multi-cluster configuration via kubeconfig secrets.

Comment on lines +136 to +141
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| config.kubeconfigSecrets | list | `[]` | List of secrets containing kubeconfig files |
| config.kubeconfigSecrets[].secretName | string | required | Name of the secret containing kubeconfig |
| config.kubeconfigSecrets[].key | string | `"config"` | Key within the secret data (optional, defaults to "config") |

Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multi-cluster table is malformed Markdown: the header and rows start with || instead of |, so it won’t render as a proper table. Please fix the leading pipes for the table in this section.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a line where this is the case

Comment on lines +110 to +123
{{- if include "headlamp.hasKubeconfigSecrets" . }}
- name: KUBECONFIG
value: {{ include "headlamp.kubeconfigPath" . | quote }}
{{- end }}
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 12 }}
{{- end }}
{{- end }}
{{- else }}
env:
{{- if include "headlamp.hasKubeconfigSecrets" . }}
- name: KUBECONFIG
value: {{ include "headlamp.kubeconfigPath" . | quote }}
{{- end }}
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds KUBECONFIG support via config.kubeconfigSecrets, but the chart doesn’t currently enforce the documented requirement that config.inCluster must be false. Consider adding a template validation (e.g., required/fail) when kubeconfigSecrets is non-empty and inCluster is true, so Helm install fails fast instead of silently ignoring the mounted kubeconfigs.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still not sure whether the lack of the in-cluster kubeconfig mapping here was intentional. I also asked about this in the CNCF Slack. It would be nice if someone from the project could let me know what you all would like :)

Comment on lines +125 to +131
# Example:
# kubeconfigSecrets:
# - secretName: prod-cluster-kubeconfig
# key: config # optional, defaults to "config"
# - secretName: dev-cluster-kubeconfig
# key: kubeconfig
# - secretName: staging-cluster-kubeconfig
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented example under config.kubeconfigSecrets is missing the surrounding config: key/indentation, which can be confusing when users copy/paste it into their values file. Please adjust the example to reflect the actual nesting under config:.

Suggested change
# Example:
# kubeconfigSecrets:
# - secretName: prod-cluster-kubeconfig
# key: config # optional, defaults to "config"
# - secretName: dev-cluster-kubeconfig
# key: kubeconfig
# - secretName: staging-cluster-kubeconfig
# Example (in values.yaml):
# config:
# kubeconfigSecrets:
# - secretName: prod-cluster-kubeconfig
# key: config # optional, defaults to "config"
# - secretName: dev-cluster-kubeconfig
# key: kubeconfig
# - secretName: staging-cluster-kubeconfig

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding config: would be more confusing than helpful, as it would add a duplicate line if someone were to just uncomment the code.

cmcgalliard and others added 3 commits March 30, 2026 01:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Corey McGalliard <59486473+cmcgalliard@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 30, 2026
@cmcgalliard
Copy link
Copy Markdown
Author

Tested this evening after adjusting for code review and it seems to work as expected.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

@cmcgalliard cmcgalliard requested a review from Copilot March 30, 2026 02:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +111 to 115
- name: KUBECONFIG
value: {{ include "headlamp.kubeconfigPath" . | quote }}
{{- end }}
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 12 }}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users also set .Values.env with a KUBECONFIG entry, this template will emit duplicate env: entries with the same name (one from kubeconfigSecrets, one from toYaml .Values.env). That can lead to unpredictable results during apply/patch. Consider either (a) only setting KUBECONFIG when it’s not already present in .Values.env, or (b) explicitly failing with a clear message when both are configured.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think handling this edge case will make the helm difficult to read - most folks will not use both if they get this far, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants