Make chartTemplate a pointer in .spec.chart
If implemented, this will omit empty `.spec.chart` in rendered yamls. Signed-off-by: Soule BA <bah.soule@gmail.com>
This commit is contained in:
parent
2c26ac1d62
commit
16b61c6f8a
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue