From 1a88b409360b79c198e8109632582ac7a9c46ce6 Mon Sep 17 00:00:00 2001
From: Hidde Beydals
Date: Tue, 22 Sep 2020 23:31:46 +0200
Subject: [PATCH] Support optional values references
This commit adds support for optional values references, as discussions
have brought to light that there are some valid use cases in which
having this option is desirable. For example to allow a user to extend
behaviour at a later date with their own repository without modifying
the HelmRelease object.
When a values reference is marked as optional, not found errors for the
value reference are ignored, but any ValuesKey, TargetPath or transient
error will still result in a reconciliation failure.
---
api/v2alpha1/reference_types.go | 6 ++++++
.../bases/helm.toolkit.fluxcd.io_helmreleases.yaml | 6 ++++++
controllers/helmrelease_controller.go | 8 ++++++++
docs/api/helmrelease.md | 14 ++++++++++++++
4 files changed, 34 insertions(+)
diff --git a/api/v2alpha1/reference_types.go b/api/v2alpha1/reference_types.go
index 33bb162..448f723 100644
--- a/api/v2alpha1/reference_types.go
+++ b/api/v2alpha1/reference_types.go
@@ -67,6 +67,12 @@ type ValuesReference struct {
// Defaults to 'None', which results in the values getting merged at the root.
// +optional
TargetPath string `json:"targetPath,omitempty"`
+
+ // Optional marks this ValuesReference as optional. When set, a not found
+ // error for the values reference is ignored, but any ValuesKey, TargetPath or
+ // transient error will still result in a reconciliation failure.
+ // +optional
+ Optional bool `json:"optional,omitempty"`
}
// GetValuesKey returns the defined ValuesKey, or the default ('values.yaml').
diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
index 37253ab..b1fcdc1 100644
--- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
+++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
@@ -368,6 +368,12 @@ spec:
maxLength: 253
minLength: 1
type: string
+ optional:
+ description: Optional marks this ValuesReference as optional.
+ When set, a not found error for the values reference is ignored,
+ but any ValuesKey, TargetPath or transient error will still
+ result in a reconciliation failure.
+ type: boolean
targetPath:
description: TargetPath is the YAML dot notation path the value
should be merged at. When set, the ValuesKey is expected to
diff --git a/controllers/helmrelease_controller.go b/controllers/helmrelease_controller.go
index c6ddcf9..f54d56f 100644
--- a/controllers/helmrelease_controller.go
+++ b/controllers/helmrelease_controller.go
@@ -525,6 +525,10 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
var resource corev1.ConfigMap
if err := r.Get(ctx, namespacedName, &resource); err != nil {
if apierrors.IsNotFound(err) {
+ if v.Optional {
+ r.Log.Info("could not find optional %s '%s'", v.Kind, namespacedName)
+ continue
+ }
return nil, fmt.Errorf("could not find %s '%s'", v.Kind, namespacedName)
}
return nil, err
@@ -538,6 +542,10 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
var resource corev1.Secret
if err := r.Get(ctx, namespacedName, &resource); err != nil {
if apierrors.IsNotFound(err) {
+ if v.Optional {
+ r.Log.Info("could not find optional %s '%s'", v.Kind, namespacedName)
+ continue
+ }
return nil, fmt.Errorf("could not find %s '%s'", v.Kind, namespacedName)
}
return nil, err
diff --git a/docs/api/helmrelease.md b/docs/api/helmrelease.md
index 436c37b..bbe6b79 100644
--- a/docs/api/helmrelease.md
+++ b/docs/api/helmrelease.md
@@ -1722,6 +1722,20 @@ When set, the ValuesKey is expected to be a single flat value.
Defaults to ‘None’, which results in the values getting merged at the root.
+
+
+optional
+
+bool
+
+ |
+
+(Optional)
+ Optional marks this ValuesReference as optional. When set, a not found
+error for the values reference is ignored, but any ValuesKey, TargetPath or
+transient error will still result in a reconciliation failure.
+ |
+