Skip to content

Commit 78594f7

Browse files
authored
Merge pull request #461 from nstogner/secret-ref-key
2 parents 18c3a3b + 9f60433 commit 78594f7

File tree

8 files changed

+36
-29
lines changed

8 files changed

+36
-29
lines changed

api/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.17
44

55
require (
66
github.com/fluxcd/pkg/apis/kustomize v0.3.3
7-
github.com/fluxcd/pkg/apis/meta v0.12.2
7+
github.com/fluxcd/pkg/apis/meta v0.13.0
88
k8s.io/apiextensions-apiserver v0.23.5
99
k8s.io/apimachinery v0.23.5
1010
sigs.k8s.io/controller-runtime v0.11.2

api/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
122122
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
123123
github.com/fluxcd/pkg/apis/kustomize v0.3.3 h1:bPN29SdVzWl0yhgivuf/83IAe2R6vUuDVcB3LzyVU8E=
124124
github.com/fluxcd/pkg/apis/kustomize v0.3.3/go.mod h1:5HTOFZfQFVMMqR2rvuxpbZhpb+sQpcTT6RCQZOhjFzA=
125-
github.com/fluxcd/pkg/apis/meta v0.12.2 h1:AiKAZxLyPtV150y63WC+mL1Qm4x5qWQmW6r4mLy1i8c=
126-
github.com/fluxcd/pkg/apis/meta v0.12.2/go.mod h1:Z26X5uTU5LxAyWETGueRQY7TvdPaGfKU7Wye9bdUlho=
125+
github.com/fluxcd/pkg/apis/meta v0.13.0 h1:0QuNKEExSjk+Rv0I6a85p2H3xOlWhdxZRsh10waEL/c=
126+
github.com/fluxcd/pkg/apis/meta v0.13.0/go.mod h1:Z26X5uTU5LxAyWETGueRQY7TvdPaGfKU7Wye9bdUlho=
127127
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
128128
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
129129
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

api/v2beta1/helmrelease_types.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,17 @@ func (in HelmReleaseSpec) GetUninstall() Uninstall {
213213

214214
// KubeConfig references a Kubernetes secret that contains a kubeconfig file.
215215
type KubeConfig struct {
216-
// SecretRef holds the name to a secret that contains a 'value' key with
217-
// the kubeconfig file as the value. It must be in the same namespace as
216+
// SecretRef holds the name to a secret that contains a key with
217+
// the kubeconfig file as the value. If no key is specified the key will
218+
// default to 'value'. The secret must be in the same namespace as
218219
// the HelmRelease.
219220
// It is recommended that the kubeconfig is self-contained, and the secret
220221
// is regularly updated if credentials such as a cloud-access-token expire.
221222
// Cloud specific `cmd-path` auth helpers will not function without adding
222223
// binaries and credentials to the Pod that is responsible for reconciling
223224
// the HelmRelease.
224225
// +required
225-
SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"`
226+
SecretRef meta.SecretKeyReference `json:"secretRef,omitempty"`
226227
}
227228

228229
// HelmChartTemplate defines the template from which the controller will

config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

+12-8
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,20 @@ spec:
245245
properties:
246246
secretRef:
247247
description: SecretRef holds the name to a secret that contains
248-
a 'value' key with the kubeconfig file as the value. It must
249-
be in the same namespace as the HelmRelease. It is recommended
250-
that the kubeconfig is self-contained, and the secret is regularly
251-
updated if credentials such as a cloud-access-token expire.
252-
Cloud specific `cmd-path` auth helpers will not function without
253-
adding binaries and credentials to the Pod that is responsible
254-
for reconciling the HelmRelease.
248+
a key with the kubeconfig file as the value. If no key is specified
249+
the key will default to 'value'. The secret must be in the same
250+
namespace as the HelmRelease. It is recommended that the kubeconfig
251+
is self-contained, and the secret is regularly updated if credentials
252+
such as a cloud-access-token expire. Cloud specific `cmd-path`
253+
auth helpers will not function without adding binaries and credentials
254+
to the Pod that is responsible for reconciling the HelmRelease.
255255
properties:
256+
key:
257+
description: Key in the Secret, when not specified an implementation-specific
258+
default key is used.
259+
type: string
256260
name:
257-
description: Name of the referent.
261+
description: Name of the Secret.
258262
type: string
259263
required:
260264
- name

controllers/helmrelease_controller.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,17 @@ func (r *HelmReleaseReconciler) getRESTClientGetter(ctx context.Context, hr v2.H
500500
}
501501

502502
var kubeConfig []byte
503-
for k, _ := range secret.Data {
504-
if k == "value" || k == "value.yaml" {
505-
kubeConfig = secret.Data[k]
506-
break
507-
}
508-
}
509-
510-
if len(kubeConfig) == 0 {
503+
if key := hr.Spec.KubeConfig.SecretRef.Key; key != "" {
504+
kubeConfig = secret.Data[key]
505+
} else if val, ok := secret.Data["value"]; ok {
506+
kubeConfig = val
507+
} else if val, ok := secret.Data["value.yaml"]; ok {
508+
kubeConfig = val
509+
} else {
510+
// User did not specify a key, and the 'value' key was not defined.
511511
return nil, fmt.Errorf("KubeConfig secret '%s' does not contain a 'value' key", secretName)
512512
}
513+
513514
return kube.NewMemoryRESTClientGetter(kubeConfig, hr.GetReleaseNamespace(), impersonateAccount, r.Config.QPS, r.Config.Burst, r.KubeConfigOpts), nil
514515
}
515516

docs/api/helmrelease.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1398,14 +1398,15 @@ no retries remain. Defaults to &lsquo;false&rsquo;.</p>
13981398
<td>
13991399
<code>secretRef</code><br>
14001400
<em>
1401-
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
1402-
github.com/fluxcd/pkg/apis/meta.LocalObjectReference
1401+
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#SecretKeyReference">
1402+
github.com/fluxcd/pkg/apis/meta.SecretKeyReference
14031403
</a>
14041404
</em>
14051405
</td>
14061406
<td>
1407-
<p>SecretRef holds the name to a secret that contains a &lsquo;value&rsquo; key with
1408-
the kubeconfig file as the value. It must be in the same namespace as
1407+
<p>SecretRef holds the name to a secret that contains a key with
1408+
the kubeconfig file as the value. If no key is specified the key will
1409+
default to &lsquo;value&rsquo;. The secret must be in the same namespace as
14091410
the HelmRelease.
14101411
It is recommended that the kubeconfig is self-contained, and the secret
14111412
is regularly updated if credentials such as a cloud-access-token expire.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/fluxcd/helm-controller/api v0.20.1
99
github.com/fluxcd/pkg/apis/acl v0.0.3
1010
github.com/fluxcd/pkg/apis/kustomize v0.3.3
11-
github.com/fluxcd/pkg/apis/meta v0.12.2
11+
github.com/fluxcd/pkg/apis/meta v0.13.0
1212
github.com/fluxcd/pkg/runtime v0.14.1
1313
github.com/fluxcd/source-controller/api v0.24.1
1414
github.com/go-logr/logr v1.2.3

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ github.com/fluxcd/pkg/apis/acl v0.0.3 h1:Lw0ZHdpnO4G7Zy9KjrzwwBmDZQuy4qEjaU/RvA6
305305
github.com/fluxcd/pkg/apis/acl v0.0.3/go.mod h1:XPts6lRJ9C9fIF9xVWofmQwftvhY25n1ps7W9xw0XLU=
306306
github.com/fluxcd/pkg/apis/kustomize v0.3.3 h1:bPN29SdVzWl0yhgivuf/83IAe2R6vUuDVcB3LzyVU8E=
307307
github.com/fluxcd/pkg/apis/kustomize v0.3.3/go.mod h1:5HTOFZfQFVMMqR2rvuxpbZhpb+sQpcTT6RCQZOhjFzA=
308-
github.com/fluxcd/pkg/apis/meta v0.12.2 h1:AiKAZxLyPtV150y63WC+mL1Qm4x5qWQmW6r4mLy1i8c=
309-
github.com/fluxcd/pkg/apis/meta v0.12.2/go.mod h1:Z26X5uTU5LxAyWETGueRQY7TvdPaGfKU7Wye9bdUlho=
308+
github.com/fluxcd/pkg/apis/meta v0.13.0 h1:0QuNKEExSjk+Rv0I6a85p2H3xOlWhdxZRsh10waEL/c=
309+
github.com/fluxcd/pkg/apis/meta v0.13.0/go.mod h1:Z26X5uTU5LxAyWETGueRQY7TvdPaGfKU7Wye9bdUlho=
310310
github.com/fluxcd/pkg/runtime v0.14.1 h1:ZbS3RzR+f+wu1e6Y7GoCxY9PFZkOgX6/gL7Enr75CY0=
311311
github.com/fluxcd/pkg/runtime v0.14.1/go.mod h1:eS4378ydLlWPt2fFjcrAAnJegGJNj3Q/iqYZqjBeWlM=
312312
github.com/fluxcd/source-controller/api v0.24.1 h1:bFpfajE09k/xNIWkgNZtmtPrw/dS0zWUYMYxUUWu+jI=

0 commit comments

Comments
 (0)