Skip to content

Commit 527ab97

Browse files
authored
Merge pull request #665 from fluxcd/fix-chart-meta
Fix chart metadata by making it truly optional
2 parents ce30d39 + 18ed296 commit 527ab97

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

api/v2beta1/helmrelease_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (in HelmReleaseSpec) GetUninstall() Uninstall {
236236
type HelmChartTemplate struct {
237237
// ObjectMeta holds the template for metadata like labels and annotations.
238238
// +optional
239-
ObjectMeta HelmChartTemplateObjectMeta `json:"metadata,omitempty"`
239+
ObjectMeta *HelmChartTemplateObjectMeta `json:"metadata,omitempty"`
240240

241241
// Spec holds the template for the v1beta2.HelmChartSpec for this HelmRelease.
242242
// +required

api/v2beta1/zz_generated.deepcopy.go

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/spec/v2beta1/helmreleases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type KubeConfig struct {
151151
type HelmChartTemplate struct {
152152
// ObjectMeta holds the template for metadata like labels and annotations.
153153
// +optional
154-
ObjectMeta HelmChartTemplateObjectMeta `json:"metadata,omitempty"`
154+
ObjectMeta *HelmChartTemplateObjectMeta `json:"metadata,omitempty"`
155155

156156
// Spec holds the template for the v1beta1.HelmChartSpec for this HelmRelease.
157157
// +required

internal/controllers/helmrelease_controller_chart.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,10 @@ func (r *HelmReleaseReconciler) deleteHelmChart(ctx context.Context, hr *v2.Helm
199199
// v2beta1.HelmChartTemplate of the given v2beta1.HelmRelease.
200200
func buildHelmChartFromTemplate(hr *v2.HelmRelease) *sourcev1b2.HelmChart {
201201
template := hr.Spec.Chart
202-
return &sourcev1b2.HelmChart{
202+
result := &sourcev1b2.HelmChart{
203203
ObjectMeta: metav1.ObjectMeta{
204-
Name: hr.GetHelmChartName(),
205-
Namespace: hr.Spec.Chart.GetNamespace(hr.Namespace),
206-
Labels: hr.Spec.Chart.ObjectMeta.Labels,
207-
Annotations: hr.Spec.Chart.ObjectMeta.Annotations,
204+
Name: hr.GetHelmChartName(),
205+
Namespace: hr.Spec.Chart.GetNamespace(hr.Namespace),
208206
},
209207
Spec: sourcev1b2.HelmChartSpec{
210208
Chart: template.Spec.Chart,
@@ -220,6 +218,11 @@ func buildHelmChartFromTemplate(hr *v2.HelmRelease) *sourcev1b2.HelmChart {
220218
Verify: templateVerificationToSourceVerification(template.Spec.Verify),
221219
},
222220
}
221+
if hr.Spec.Chart.ObjectMeta != nil {
222+
result.ObjectMeta.Labels = hr.Spec.Chart.ObjectMeta.Labels
223+
result.ObjectMeta.Annotations = hr.Spec.Chart.ObjectMeta.Annotations
224+
}
225+
return result
223226
}
224227

225228
// helmChartRequiresUpdate compares the v2beta1.HelmChartTemplate of the
@@ -246,9 +249,9 @@ func helmChartRequiresUpdate(hr *v2.HelmRelease, chart *sourcev1b2.HelmChart) bo
246249
return true
247250
case template.Spec.ValuesFile != chart.Spec.ValuesFile:
248251
return true
249-
case !apiequality.Semantic.DeepEqual(template.ObjectMeta.Annotations, chart.Annotations):
252+
case template.ObjectMeta != nil && !apiequality.Semantic.DeepEqual(template.ObjectMeta.Annotations, chart.Annotations):
250253
return true
251-
case !apiequality.Semantic.DeepEqual(template.ObjectMeta.Labels, chart.Labels):
254+
case template.ObjectMeta != nil && !apiequality.Semantic.DeepEqual(template.ObjectMeta.Labels, chart.Labels):
252255
return true
253256
case !reflect.DeepEqual(templateVerificationToSourceVerification(template.Spec.Verify), chart.Spec.Verify):
254257
return true

internal/controllers/helmrelease_controller_chart_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,14 @@ func Test_helmChartRequiresUpdate(t *testing.T) {
517517
{
518518
name: "detects labels change",
519519
modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) {
520-
hr.Spec.Chart.ObjectMeta.Labels = map[string]string{"foo": "bar"}
520+
hr.Spec.Chart.ObjectMeta = &v2.HelmChartTemplateObjectMeta{Labels: map[string]string{"foo": "bar"}}
521521
},
522522
want: true,
523523
},
524524
{
525525
name: "detects annotations change",
526526
modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) {
527-
hr.Spec.Chart.ObjectMeta.Annotations = map[string]string{"foo": "bar"}
527+
hr.Spec.Chart.ObjectMeta = &v2.HelmChartTemplateObjectMeta{Annotations: map[string]string{"foo": "bar"}}
528528
},
529529
want: true,
530530
},

0 commit comments

Comments
 (0)