Skip to content

Commit

Permalink
Merge pull request #980 from fluxcd/chartTemplate-as-pointer
Browse files Browse the repository at this point in the history
Fix: Make `HelmChartTemplate` a pointer in `.spec.chart`
  • Loading branch information
souleb authored May 10, 2024
2 parents 2c26ac1 + 16b61c6 commit bc1219f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions api/v2/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion api/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/v2beta2/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion api/v2beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions internal/controller/helmrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -2424,6 +2424,9 @@ func TestHelmReleaseReconciler_reconcileChartTemplate(t *testing.T) {
}

obj := &v2.HelmRelease{
Spec: v2.HelmReleaseSpec{
Chart: &v2.HelmChartTemplate{},
},
Status: v2.HelmReleaseStatus{
StorageNamespace: "default",
},
Expand Down Expand Up @@ -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{
Expand Down
10 changes: 6 additions & 4 deletions internal/reconcile/helmchart_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions internal/reconcile/helmchart_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit bc1219f

Please sign in to comment.