Skip to content

Commit 098fa6d

Browse files
authored
Merge pull request #306 from fluxcd/sops-kubeconfig
Make the kubeconfig secrets compatible with SOPS
2 parents 8ffa994 + e9d31e9 commit 098fa6d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

controllers/helmrelease_controller.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,16 @@ func (r *HelmReleaseReconciler) getRESTClientGetter(ctx context.Context, hr v2.H
470470
if err := r.Get(ctx, secretName, &secret); err != nil {
471471
return nil, fmt.Errorf("could not find KubeConfig secret '%s': %w", secretName, err)
472472
}
473-
kubeConfig, ok := secret.Data["value"]
474-
if !ok {
473+
474+
var kubeConfig []byte
475+
for k, _ := range secret.Data {
476+
if k == "value" || k == "value.yaml" {
477+
kubeConfig = secret.Data[k]
478+
break
479+
}
480+
}
481+
482+
if len(kubeConfig) == 0 {
475483
return nil, fmt.Errorf("KubeConfig secret '%s' does not contain a 'value' key", secretName)
476484
}
477485
return kube.NewMemoryRESTClientGetter(kubeConfig, hr.GetReleaseNamespace()), nil

docs/spec/v2beta1/helmreleases.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ in that KubeConfig instead of the local cluster that is responsible for the reco
10351035
HelmRelease.
10361036

10371037
The secret defined in the `spec.kubeConfig.secretRef` must exist in the same namespace as the
1038-
HelmRelease. On every reconciliation, the KubeConfig bytes will be loaded from the `values` key
1038+
HelmRelease. On every reconciliation, the KubeConfig bytes will be loaded from the `value` or `value.yaml` key
10391039
of the secret's data, and the secret can thus be regularly updated if cluster-access-tokens have
10401040
to rotate due to expiration.
10411041

@@ -1114,7 +1114,7 @@ cluster where helm-controller is running e.g.:
11141114

11151115
```sh
11161116
kubectl -n default create secret generic prod-kubeconfig \
1117-
--from-file=value=./kubeconfig
1117+
--from-file=value.yaml=./kubeconfig
11181118
```
11191119

11201120
> **Note** that the KubeConfig should be self-contained and not rely on binaries, environment,

0 commit comments

Comments
 (0)