Skip to content

Commit

Permalink
Make the kubeconfig secrets compatible with SOPS
Browse files Browse the repository at this point in the history
Add `values.yaml` to the supported kubeconfig secret key names in order for SOPS to correctly detect the storage format based on the file extension.

Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Aug 4, 2021
1 parent 8ffa994 commit e9d31e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,16 @@ func (r *HelmReleaseReconciler) getRESTClientGetter(ctx context.Context, hr v2.H
if err := r.Get(ctx, secretName, &secret); err != nil {
return nil, fmt.Errorf("could not find KubeConfig secret '%s': %w", secretName, err)
}
kubeConfig, ok := secret.Data["value"]
if !ok {

var kubeConfig []byte
for k, _ := range secret.Data {
if k == "value" || k == "value.yaml" {
kubeConfig = secret.Data[k]
break
}
}

if len(kubeConfig) == 0 {
return nil, fmt.Errorf("KubeConfig secret '%s' does not contain a 'value' key", secretName)
}
return kube.NewMemoryRESTClientGetter(kubeConfig, hr.GetReleaseNamespace()), nil
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/v2beta1/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ in that KubeConfig instead of the local cluster that is responsible for the reco
HelmRelease.

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

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

```sh
kubectl -n default create secret generic prod-kubeconfig \
--from-file=value=./kubeconfig
--from-file=value.yaml=./kubeconfig
```

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

0 comments on commit e9d31e9

Please sign in to comment.