Skip to content

Commit 225274a

Browse files
committed
Add .spec.kubeConfig.secretRef.key
1 parent cbe622f commit 225274a

File tree

8 files changed

+82
-32
lines changed

8 files changed

+82
-32
lines changed

api/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.17
44

55
require (
66
github.com/fluxcd/pkg/apis/kustomize v0.3.2
7-
github.com/fluxcd/pkg/apis/meta v0.12.1
7+
github.com/fluxcd/pkg/apis/meta v0.12.3-0.20220415180444-df88b80c8323
88
k8s.io/apiextensions-apiserver v0.23.4
9-
k8s.io/apimachinery v0.23.4
9+
k8s.io/apimachinery v0.23.5
1010
sigs.k8s.io/controller-runtime v0.11.1
1111
)
1212

api/go.sum

+4-3
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.2 h1:ULoAwOOekHf5cy6mYIwL+K6v8/cfcNVVbwfIPgWjdjg=
124124
github.com/fluxcd/pkg/apis/kustomize v0.3.2/go.mod h1:p8iAH5TeqMBnnxkkpCNNDvWYfKlNRx89a6WKOo+hJHA=
125-
github.com/fluxcd/pkg/apis/meta v0.12.1 h1:m5PfKAqbqWBvGp9+JRj1sv+xNkGsHwUVf+3rJ8wm6SE=
126-
github.com/fluxcd/pkg/apis/meta v0.12.1/go.mod h1:f8YVt70/KAhqzZ7xxhjvqyzKubOYx2pAbakb/FfCEg8=
125+
github.com/fluxcd/pkg/apis/meta v0.12.3-0.20220415180444-df88b80c8323 h1:QaWnZ6IfBj6tcEb1C+G0u7A07IOCo74bZLQSBPJiBqA=
126+
github.com/fluxcd/pkg/apis/meta v0.12.3-0.20220415180444-df88b80c8323/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=
@@ -882,8 +882,9 @@ k8s.io/api v0.23.4 h1:85gnfXQOWbJa1SiWGpE9EEtHs0UVvDyIsSMpEtl2D4E=
882882
k8s.io/api v0.23.4/go.mod h1:i77F4JfyNNrhOjZF7OwwNJS5Y1S9dpwvb9iYRYRczfI=
883883
k8s.io/apiextensions-apiserver v0.23.4 h1:AFDUEu/yEf0YnuZhqhIFhPLPhhcQQVuR1u3WCh0rveU=
884884
k8s.io/apiextensions-apiserver v0.23.4/go.mod h1:TWYAKymJx7nLMxWCgWm2RYGXHrGlVZnxIlGnvtfYu+g=
885-
k8s.io/apimachinery v0.23.4 h1:fhnuMd/xUL3Cjfl64j5ULKZ1/J9n8NuQEgNL+WXWfdM=
886885
k8s.io/apimachinery v0.23.4/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
886+
k8s.io/apimachinery v0.23.5 h1:Va7dwhp8wgkUPWsEXk6XglXWU4IKYLKNlv8VkX7SDM0=
887+
k8s.io/apimachinery v0.23.5/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
887888
k8s.io/apiserver v0.23.4/go.mod h1:A6l/ZcNtxGfPSqbFDoxxOjEjSKBaQmE+UTveOmMkpNc=
888889
k8s.io/client-go v0.23.4/go.mod h1:PKnIL4pqLuvYUK1WU7RLTMYKPiIh7MYShLshtRY9cj0=
889890
k8s.io/code-generator v0.23.4/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk=

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
@@ -495,16 +495,17 @@ func (r *HelmReleaseReconciler) getRESTClientGetter(ctx context.Context, hr v2.H
495495
}
496496

497497
var kubeConfig []byte
498-
for k, _ := range secret.Data {
499-
if k == "value" || k == "value.yaml" {
500-
kubeConfig = secret.Data[k]
501-
break
502-
}
503-
}
504-
505-
if len(kubeConfig) == 0 {
498+
if key := hr.Spec.KubeConfig.SecretRef.Key; key != "" {
499+
kubeConfig = secret.Data[key]
500+
} else if val, ok := secret.Data["value"]; ok {
501+
kubeConfig = val
502+
} else if val, ok := secret.Data["value.yaml"]; ok {
503+
kubeConfig = val
504+
} else {
505+
// User did not specify a key, and the 'value' key was not defined.
506506
return nil, fmt.Errorf("KubeConfig secret '%s' does not contain a 'value' key", secretName)
507507
}
508+
508509
return kube.NewMemoryRESTClientGetter(kubeConfig, hr.GetReleaseNamespace(), impersonateAccount, r.Config.QPS, r.Config.Burst, r.KubeConfigOpts), nil
509510
}
510511

docs/api/helmrelease.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,13 @@ 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="#helm.toolkit.fluxcd.io/v2beta1.SecretRef">
1402+
SecretRef
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
1407+
<p>SecretRef holds the name to a secret that contains
14081408
the kubeconfig file as the value. It must be in the same namespace as
14091409
the HelmRelease.
14101410
It is recommended that the kubeconfig is self-contained, and the secret
@@ -1658,6 +1658,48 @@ rollback action when it fails.</p>
16581658
</table>
16591659
</div>
16601660
</div>
1661+
<h3 id="helm.toolkit.fluxcd.io/v2beta1.SecretRef">SecretRef
1662+
</h3>
1663+
<p>
1664+
(<em>Appears on:</em>
1665+
<a href="#helm.toolkit.fluxcd.io/v2beta1.KubeConfig">KubeConfig</a>)
1666+
</p>
1667+
<div class="md-typeset__scrollwrap">
1668+
<div class="md-typeset__table">
1669+
<table>
1670+
<thead>
1671+
<tr>
1672+
<th>Field</th>
1673+
<th>Description</th>
1674+
</tr>
1675+
</thead>
1676+
<tbody>
1677+
<tr>
1678+
<td>
1679+
<code>name</code><br>
1680+
<em>
1681+
string
1682+
</em>
1683+
</td>
1684+
<td>
1685+
<p>Name of the Secret.</p>
1686+
</td>
1687+
</tr>
1688+
<tr>
1689+
<td>
1690+
<code>key</code><br>
1691+
<em>
1692+
string
1693+
</em>
1694+
</td>
1695+
<td>
1696+
<p>Key in the Secret. If not specified it defaults to &lsquo;value&rsquo;.</p>
1697+
</td>
1698+
</tr>
1699+
</tbody>
1700+
</table>
1701+
</div>
1702+
</div>
16611703
<h3 id="helm.toolkit.fluxcd.io/v2beta1.Test">Test
16621704
</h3>
16631705
<p>

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/fluxcd/helm-controller/api v0.19.0
99
github.com/fluxcd/pkg/apis/acl v0.0.3
1010
github.com/fluxcd/pkg/apis/kustomize v0.3.2
11-
github.com/fluxcd/pkg/apis/meta v0.12.1
11+
github.com/fluxcd/pkg/apis/meta v0.12.3-0.20220415180444-df88b80c8323
1212
github.com/fluxcd/pkg/runtime v0.13.3
1313
github.com/fluxcd/source-controller/api v0.22.3
1414
github.com/go-logr/logr v1.2.3
@@ -19,7 +19,7 @@ require (
1919
helm.sh/helm/v3 v3.8.1
2020
k8s.io/api v0.23.4
2121
k8s.io/apiextensions-apiserver v0.23.4
22-
k8s.io/apimachinery v0.23.4
22+
k8s.io/apimachinery v0.23.5
2323
k8s.io/cli-runtime v0.23.4
2424
k8s.io/client-go v0.23.4
2525
sigs.k8s.io/controller-runtime v0.11.1

go.sum

+4-3
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ github.com/fluxcd/pkg/apis/acl v0.0.3 h1:Lw0ZHdpnO4G7Zy9KjrzwwBmDZQuy4qEjaU/RvA6
315315
github.com/fluxcd/pkg/apis/acl v0.0.3/go.mod h1:XPts6lRJ9C9fIF9xVWofmQwftvhY25n1ps7W9xw0XLU=
316316
github.com/fluxcd/pkg/apis/kustomize v0.3.2 h1:ULoAwOOekHf5cy6mYIwL+K6v8/cfcNVVbwfIPgWjdjg=
317317
github.com/fluxcd/pkg/apis/kustomize v0.3.2/go.mod h1:p8iAH5TeqMBnnxkkpCNNDvWYfKlNRx89a6WKOo+hJHA=
318-
github.com/fluxcd/pkg/apis/meta v0.12.1 h1:m5PfKAqbqWBvGp9+JRj1sv+xNkGsHwUVf+3rJ8wm6SE=
319-
github.com/fluxcd/pkg/apis/meta v0.12.1/go.mod h1:f8YVt70/KAhqzZ7xxhjvqyzKubOYx2pAbakb/FfCEg8=
318+
github.com/fluxcd/pkg/apis/meta v0.12.3-0.20220415180444-df88b80c8323 h1:QaWnZ6IfBj6tcEb1C+G0u7A07IOCo74bZLQSBPJiBqA=
319+
github.com/fluxcd/pkg/apis/meta v0.12.3-0.20220415180444-df88b80c8323/go.mod h1:Z26X5uTU5LxAyWETGueRQY7TvdPaGfKU7Wye9bdUlho=
320320
github.com/fluxcd/pkg/runtime v0.13.3 h1:k0Xun+RoEC/F6iuAPTA6rQb+I4B4oecBx6pOcodX11A=
321321
github.com/fluxcd/pkg/runtime v0.13.3/go.mod h1:dzWNKqFzFXeittbpFcJzR3cdC9CWlbzw+pNOgaVvF/0=
322322
github.com/fluxcd/source-controller/api v0.22.3 h1:HnpSnCtIytwSGSz2qu+GJwyZRmD5UXZL5oOQapiQOtk=
@@ -1560,8 +1560,9 @@ k8s.io/api v0.23.4/go.mod h1:i77F4JfyNNrhOjZF7OwwNJS5Y1S9dpwvb9iYRYRczfI=
15601560
k8s.io/apiextensions-apiserver v0.23.4 h1:AFDUEu/yEf0YnuZhqhIFhPLPhhcQQVuR1u3WCh0rveU=
15611561
k8s.io/apiextensions-apiserver v0.23.4/go.mod h1:TWYAKymJx7nLMxWCgWm2RYGXHrGlVZnxIlGnvtfYu+g=
15621562
k8s.io/apimachinery v0.20.6/go.mod h1:ejZXtW1Ra6V1O5H8xPBGz+T3+4gfkTCeExAHKU57MAc=
1563-
k8s.io/apimachinery v0.23.4 h1:fhnuMd/xUL3Cjfl64j5ULKZ1/J9n8NuQEgNL+WXWfdM=
15641563
k8s.io/apimachinery v0.23.4/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
1564+
k8s.io/apimachinery v0.23.5 h1:Va7dwhp8wgkUPWsEXk6XglXWU4IKYLKNlv8VkX7SDM0=
1565+
k8s.io/apimachinery v0.23.5/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
15651566
k8s.io/apiserver v0.20.6/go.mod h1:QIJXNt6i6JB+0YQRNcS0hdRHJlMhflFmsBDeSgT1r8Q=
15661567
k8s.io/apiserver v0.23.4 h1:zNvQlG+C/ERjuUz4p7eY/0IWHaMixRSBoxgmyIdwo9Y=
15671568
k8s.io/apiserver v0.23.4/go.mod h1:A6l/ZcNtxGfPSqbFDoxxOjEjSKBaQmE+UTveOmMkpNc=

0 commit comments

Comments
 (0)