Skip to content

Commit

Permalink
Merge pull request #665 from fluxcd/fix-chart-meta
Browse files Browse the repository at this point in the history
Fix chart metadata by making it truly optional
  • Loading branch information
darkowlzz authored Apr 3, 2023
2 parents ce30d39 + 18ed296 commit 527ab97
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (in HelmReleaseSpec) GetUninstall() Uninstall {
type HelmChartTemplate struct {
// ObjectMeta holds the template for metadata like labels and annotations.
// +optional
ObjectMeta HelmChartTemplateObjectMeta `json:"metadata,omitempty"`
ObjectMeta *HelmChartTemplateObjectMeta `json:"metadata,omitempty"`

// Spec holds the template for the v1beta2.HelmChartSpec for this HelmRelease.
// +required
Expand Down
6 changes: 5 additions & 1 deletion api/v2beta1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion docs/spec/v2beta1/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type KubeConfig struct {
type HelmChartTemplate struct {
// ObjectMeta holds the template for metadata like labels and annotations.
// +optional
ObjectMeta HelmChartTemplateObjectMeta `json:"metadata,omitempty"`
ObjectMeta *HelmChartTemplateObjectMeta `json:"metadata,omitempty"`

// Spec holds the template for the v1beta1.HelmChartSpec for this HelmRelease.
// +required
Expand Down
17 changes: 10 additions & 7 deletions internal/controllers/helmrelease_controller_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,10 @@ func (r *HelmReleaseReconciler) deleteHelmChart(ctx context.Context, hr *v2.Helm
// v2beta1.HelmChartTemplate of the given v2beta1.HelmRelease.
func buildHelmChartFromTemplate(hr *v2.HelmRelease) *sourcev1b2.HelmChart {
template := hr.Spec.Chart
return &sourcev1b2.HelmChart{
result := &sourcev1b2.HelmChart{
ObjectMeta: metav1.ObjectMeta{
Name: hr.GetHelmChartName(),
Namespace: hr.Spec.Chart.GetNamespace(hr.Namespace),
Labels: hr.Spec.Chart.ObjectMeta.Labels,
Annotations: hr.Spec.Chart.ObjectMeta.Annotations,
Name: hr.GetHelmChartName(),
Namespace: hr.Spec.Chart.GetNamespace(hr.Namespace),
},
Spec: sourcev1b2.HelmChartSpec{
Chart: template.Spec.Chart,
Expand All @@ -220,6 +218,11 @@ func buildHelmChartFromTemplate(hr *v2.HelmRelease) *sourcev1b2.HelmChart {
Verify: templateVerificationToSourceVerification(template.Spec.Verify),
},
}
if hr.Spec.Chart.ObjectMeta != nil {
result.ObjectMeta.Labels = hr.Spec.Chart.ObjectMeta.Labels
result.ObjectMeta.Annotations = hr.Spec.Chart.ObjectMeta.Annotations
}
return result
}

// helmChartRequiresUpdate compares the v2beta1.HelmChartTemplate of the
Expand All @@ -246,9 +249,9 @@ func helmChartRequiresUpdate(hr *v2.HelmRelease, chart *sourcev1b2.HelmChart) bo
return true
case template.Spec.ValuesFile != chart.Spec.ValuesFile:
return true
case !apiequality.Semantic.DeepEqual(template.ObjectMeta.Annotations, chart.Annotations):
case template.ObjectMeta != nil && !apiequality.Semantic.DeepEqual(template.ObjectMeta.Annotations, chart.Annotations):
return true
case !apiequality.Semantic.DeepEqual(template.ObjectMeta.Labels, chart.Labels):
case template.ObjectMeta != nil && !apiequality.Semantic.DeepEqual(template.ObjectMeta.Labels, chart.Labels):
return true
case !reflect.DeepEqual(templateVerificationToSourceVerification(template.Spec.Verify), chart.Spec.Verify):
return true
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/helmrelease_controller_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,14 @@ func Test_helmChartRequiresUpdate(t *testing.T) {
{
name: "detects labels change",
modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) {
hr.Spec.Chart.ObjectMeta.Labels = map[string]string{"foo": "bar"}
hr.Spec.Chart.ObjectMeta = &v2.HelmChartTemplateObjectMeta{Labels: map[string]string{"foo": "bar"}}
},
want: true,
},
{
name: "detects annotations change",
modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) {
hr.Spec.Chart.ObjectMeta.Annotations = map[string]string{"foo": "bar"}
hr.Spec.Chart.ObjectMeta = &v2.HelmChartTemplateObjectMeta{Annotations: map[string]string{"foo": "bar"}}
},
want: true,
},
Expand Down

0 comments on commit 527ab97

Please sign in to comment.