Skip to content

Commit f5da4be

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

File tree

5 files changed

+89
-17
lines changed

5 files changed

+89
-17
lines changed

api/v2beta1/helmrelease_types.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ 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
216+
// SecretRef holds the name to a secret that contains
217217
// the kubeconfig file as the value. It must be in the same namespace as
218218
// the HelmRelease.
219219
// It is recommended that the kubeconfig is self-contained, and the secret
@@ -222,7 +222,14 @@ type KubeConfig struct {
222222
// binaries and credentials to the Pod that is responsible for reconciling
223223
// the HelmRelease.
224224
// +required
225-
SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"`
225+
SecretRef SecretRef `json:"secretRef,omitempty"`
226+
}
227+
228+
type SecretRef struct {
229+
// Name of the Secret.
230+
Name string `json:"name"`
231+
// Key in the Secret. If not specified it defaults to 'value'.
232+
Key string `json:"key"`
226233
}
227234

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

api/v2beta1/zz_generated.deepcopy.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,22 @@ 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+
the kubeconfig file as the value. It must be in the same namespace
249+
as the HelmRelease. It is recommended that the kubeconfig is
250+
self-contained, and the secret is regularly updated if credentials
251+
such as a cloud-access-token expire. Cloud specific `cmd-path`
252+
auth helpers will not function without adding binaries and credentials
253+
to the Pod that is responsible for reconciling the HelmRelease.
255254
properties:
255+
key:
256+
description: Key in the Secret. If not specified it defaults
257+
to 'value'.
258+
type: string
256259
name:
257-
description: Name of the referent.
260+
description: Name of the Secret.
258261
type: string
259262
required:
263+
- key
260264
- name
261265
type: object
262266
type: object

controllers/helmrelease_controller.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,14 @@ 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
498+
if refkey := hr.Spec.KubeConfig.SecretRef.Key; refkey != "" {
499+
kubeConfig = secret.Data[refkey]
500+
} else {
501+
for k, _ := range secret.Data {
502+
if k == "value" || k == "value.yaml" {
503+
kubeConfig = secret.Data[k]
504+
break
505+
}
502506
}
503507
}
504508

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>

0 commit comments

Comments
 (0)