Skip to content

Commit

Permalink
Add support to refer to values from ConfigMap and Secret in other nam…
Browse files Browse the repository at this point in the history
…espaces

Signed-off-by: Alexander Berger <[email protected]>
  • Loading branch information
alex-berger committed Feb 4, 2021
1 parent 27a532f commit a03bb2c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
10 changes: 8 additions & 2 deletions api/v2beta1/reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ type ValuesReference struct {
// +required
Kind string `json:"kind"`

// Name of the values referent. Should reside in the same namespace as the
// referring resource.
// Name of the values referent.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +required
Name string `json:"name"`

// Namespace of the values referent. If not present, then the namespace of
// the referring resource will be used.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +optional
Namespace string `json:"namespace,omitempty"`

// ValuesKey is the data key where the values.yaml or a specific value can be
// found at. Defaults to 'values.yaml'.
// +optional
Expand Down
9 changes: 7 additions & 2 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,13 @@ spec:
- ConfigMap
type: string
name:
description: Name of the values referent. Should reside in the
same namespace as the referring resource.
description: Name of the values referent.
maxLength: 253
minLength: 1
type: string
namespace:
description: Namespace of the values referent. If not present,
then the namespace of the referring resource will be used.
maxLength: 253
minLength: 1
type: string
Expand Down
6 changes: 5 additions & 1 deletion controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,11 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
secrets := make(map[string]*corev1.Secret)

for _, v := range hr.Spec.ValuesFrom {
namespacedName := types.NamespacedName{Namespace: hr.Namespace, Name: v.Name}
namespace := v.Namespace
if namespace == "" {
namespace = hr.Namespace
}
namespacedName := types.NamespacedName{Namespace: namespace, Name: v.Name}
var valuesData []byte

switch v.Kind {
Expand Down
16 changes: 14 additions & 2 deletions docs/api/helmrelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -1877,8 +1877,20 @@ string
</em>
</td>
<td>
<p>Name of the values referent. Should reside in the same namespace as the
referring resource.</p>
<p>Name of the values referent.</p>
</td>
</tr>
<tr>
<td>
<code>namespace</code><br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Namespace of the values referent. If not present, then the namespace of
the referring resource will be used.</p>
</td>
</tr>
<tr>
Expand Down
18 changes: 13 additions & 5 deletions docs/spec/v2beta1/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,19 @@ type ValuesReference struct {
// +required
Kind string `json:"kind"`

// Name of the values referent. Should reside in the same namespace as the
// referring resource.
// Name of the values referent.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +required
Name string `json:"name"`

// Namespace of the values referent. If not present, then the namespace of
// the referring resource will be used.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +optional
Namespace string `json:"namespace,omitempty"`

// ValuesKey is the data key where the values.yaml or a specific value can be
// found at. Defaults to 'values.yaml'.
// +optional
Expand Down Expand Up @@ -644,7 +650,8 @@ spec:
name: prod-env-values
valuesKey: values-prod.yaml
- kind: Secret
name: prod-tls-values
name: prod-tls-values
namespace: other-namespace
valuesKey: crt
targetPath: tls.crt
optional: true
Expand All @@ -653,8 +660,9 @@ spec:
The definition of the listed keys for items in `spec.valuesFrom` is as follows:

- `kind`: Kind of the values referent (`ConfigMap` or `Secret`).
- `name`: Name of the values referent, in the same namespace as the
`HelmRelease`.
- `name`: Name of the values referent.
- `namespace` _(Optional)_: Namespace of the values referent. Defaults to
the namespace of the `HelmRelease`.
- `valuesKey` _(Optional)_: The data key where the values.yaml or a
specific value can be found. Defaults to `values.yaml` when omitted.
- `targetPath` _(Optional)_: The YAML dot notation path at which the
Expand Down

0 comments on commit a03bb2c

Please sign in to comment.