diff --git a/api/v2/helmrelease_types.go b/api/v2/helmrelease_types.go index 5698ea148..317db89a8 100644 --- a/api/v2/helmrelease_types.go +++ b/api/v2/helmrelease_types.go @@ -69,7 +69,7 @@ type HelmReleaseSpec struct { // Chart defines the template of the v1beta2.HelmChart that should be created // for this HelmRelease. // +optional - Chart HelmChartTemplate `json:"chart,omitempty"` + Chart *HelmChartTemplate `json:"chart,omitempty"` // ChartRef holds a reference to a source controller resource containing the // Helm chart artifact. @@ -1243,7 +1243,7 @@ func (in *HelmRelease) HasChartRef() bool { // HasChartTemplate returns true if the HelmRelease has a ChartTemplate. func (in *HelmRelease) HasChartTemplate() bool { - return in.Spec.Chart.Spec.Chart != "" + return in.Spec.Chart != nil } // +kubebuilder:object:root=true diff --git a/api/v2/zz_generated.deepcopy.go b/api/v2/zz_generated.deepcopy.go index 57e62b402..c9f8e8ffe 100644 --- a/api/v2/zz_generated.deepcopy.go +++ b/api/v2/zz_generated.deepcopy.go @@ -258,7 +258,11 @@ func (in *HelmReleaseList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HelmReleaseSpec) DeepCopyInto(out *HelmReleaseSpec) { *out = *in - in.Chart.DeepCopyInto(&out.Chart) + if in.Chart != nil { + in, out := &in.Chart, &out.Chart + *out = new(HelmChartTemplate) + (*in).DeepCopyInto(*out) + } if in.ChartRef != nil { in, out := &in.ChartRef, &out.ChartRef *out = new(CrossNamespaceSourceReference) diff --git a/api/v2beta2/helmrelease_types.go b/api/v2beta2/helmrelease_types.go index 589b331fd..cea04dc28 100644 --- a/api/v2beta2/helmrelease_types.go +++ b/api/v2beta2/helmrelease_types.go @@ -81,7 +81,7 @@ type HelmReleaseSpec struct { // Chart defines the template of the v1beta2.HelmChart that should be created // for this HelmRelease. // +optional - Chart HelmChartTemplate `json:"chart,omitempty"` + Chart *HelmChartTemplate `json:"chart,omitempty"` // ChartRef holds a reference to a source controller resource containing the // Helm chart artifact. @@ -1275,7 +1275,7 @@ func (in *HelmRelease) HasChartRef() bool { // IsChartTemplatePresent returns true if the HelmRelease has a ChartTemplate. func (in *HelmRelease) HasChartTemplate() bool { - return in.Spec.Chart.Spec.Chart != "" + return in.Spec.Chart != nil } // +kubebuilder:object:root=true diff --git a/api/v2beta2/zz_generated.deepcopy.go b/api/v2beta2/zz_generated.deepcopy.go index 6e97f139a..4704fb012 100644 --- a/api/v2beta2/zz_generated.deepcopy.go +++ b/api/v2beta2/zz_generated.deepcopy.go @@ -259,7 +259,11 @@ func (in *HelmReleaseList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HelmReleaseSpec) DeepCopyInto(out *HelmReleaseSpec) { *out = *in - in.Chart.DeepCopyInto(&out.Chart) + if in.Chart != nil { + in, out := &in.Chart, &out.Chart + *out = new(HelmChartTemplate) + (*in).DeepCopyInto(*out) + } if in.ChartRef != nil { in, out := &in.ChartRef, &out.ChartRef *out = new(CrossNamespaceSourceReference) diff --git a/internal/controller/helmrelease_controller_test.go b/internal/controller/helmrelease_controller_test.go index c2b66c3a5..89d38865b 100644 --- a/internal/controller/helmrelease_controller_test.go +++ b/internal/controller/helmrelease_controller_test.go @@ -864,7 +864,7 @@ func TestHelmReleaseReconciler_reconcileReleaseFromHelmChartSource(t *testing.T) Name: "chart", Namespace: "mock", }, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: "mychart", SourceRef: v2.CrossNamespaceObjectReference{ @@ -1332,7 +1332,7 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin Name: "ocirepo", Namespace: "mock", }, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: "mychart", SourceRef: v2.CrossNamespaceObjectReference{ @@ -2424,6 +2424,9 @@ func TestHelmReleaseReconciler_reconcileChartTemplate(t *testing.T) { } obj := &v2.HelmRelease{ + Spec: v2.HelmReleaseSpec{ + Chart: &v2.HelmChartTemplate{}, + }, Status: v2.HelmReleaseStatus{ StorageNamespace: "default", }, @@ -3334,7 +3337,7 @@ func TestValuesReferenceValidation(t *testing.T) { }, Spec: v2.HelmReleaseSpec{ Interval: metav1.Duration{Duration: 5 * time.Minute}, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: "mychart", SourceRef: v2.CrossNamespaceObjectReference{ diff --git a/internal/reconcile/helmchart_template.go b/internal/reconcile/helmchart_template.go index 6529bf206..7b76612c9 100644 --- a/internal/reconcile/helmchart_template.go +++ b/internal/reconcile/helmchart_template.go @@ -79,12 +79,14 @@ func NewHelmChartTemplate(client client.Client, recorder record.EventRecorder, f func (r *HelmChartTemplate) Reconcile(ctx context.Context, req *Request) error { var ( obj = req.Object - chartRef = types.NamespacedName{ - Namespace: obj.Spec.Chart.GetNamespace(obj.Namespace), - Name: obj.GetHelmChartName(), - } + chartRef = types.NamespacedName{} ) + if obj.Spec.Chart != nil { + chartRef.Name = obj.GetHelmChartName() + chartRef.Namespace = obj.Spec.Chart.GetNamespace(obj.Namespace) + } + // The HelmChart name and/or namespace diverges or the HelmRelease is // being deleted, delete the HelmChart. if (obj.Status.HelmChart != "" && obj.Status.HelmChart != chartRef.String()) || !obj.DeletionTimestamp.IsZero() { diff --git a/internal/reconcile/helmchart_template_test.go b/internal/reconcile/helmchart_template_test.go index 287274dcc..b601ce2d6 100644 --- a/internal/reconcile/helmchart_template_test.go +++ b/internal/reconcile/helmchart_template_test.go @@ -144,7 +144,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) { Name: "release-with-existing-chart", }, Spec: v2.HelmReleaseSpec{ - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: "foo", SourceRef: v2.CrossNamespaceObjectReference{ @@ -194,7 +194,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) { }, Spec: v2.HelmReleaseSpec{ Interval: metav1.Duration{Duration: 1 * time.Hour}, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ SourceRef: v2.CrossNamespaceObjectReference{ Kind: sourcev1.HelmRepositoryKind, @@ -265,7 +265,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) { }, Spec: v2.HelmReleaseSpec{ Interval: metav1.Duration{Duration: 1 * time.Hour}, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: "foo", SourceRef: v2.CrossNamespaceObjectReference{ @@ -336,7 +336,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) { }, Spec: v2.HelmReleaseSpec{ Interval: existingChart.Spec.Interval, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: existingChart.Spec.Chart, SourceRef: v2.CrossNamespaceObjectReference{ @@ -380,7 +380,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) { }, Spec: v2.HelmReleaseSpec{ Interval: metav1.Duration{Duration: 1 * time.Hour}, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ SourceRef: v2.CrossNamespaceObjectReference{ Kind: sourcev1.HelmRepositoryKind, @@ -424,7 +424,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) { Namespace: "default", }, Spec: v2.HelmReleaseSpec{ - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ SourceRef: v2.CrossNamespaceObjectReference{ Name: "chart", @@ -661,7 +661,7 @@ func Test_buildHelmChartFromTemplate(t *testing.T) { }, Spec: v2.HelmReleaseSpec{ Interval: metav1.Duration{Duration: time.Minute}, - Chart: v2.HelmChartTemplate{ + Chart: &v2.HelmChartTemplate{ Spec: v2.HelmChartTemplateSpec{ Chart: "chart", Version: "1.0.0",