From cee3c2c0f67f12f44fcf2f67ea9559b09fc6586b Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 8 Jul 2024 23:57:40 +0200 Subject: [PATCH] fix: Stop using pointers as list elements when not really necessary --- api/v1alpha1/objecttemplate_types.go | 2 +- api/v1alpha1/texttemplate_types.go | 2 +- api/v1alpha1/zz_generated.deepcopy.go | 16 ++++--------- controllers/objecttemplate_controller_test.go | 14 +++++------ docs/api/template-controller.md | 24 ++++++++++++------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/api/v1alpha1/objecttemplate_types.go b/api/v1alpha1/objecttemplate_types.go index adaa87e..f4e7e53 100644 --- a/api/v1alpha1/objecttemplate_types.go +++ b/api/v1alpha1/objecttemplate_types.go @@ -50,7 +50,7 @@ type ObjectTemplateSpec struct { // Matrix specifies the input matrix // +required - Matrix []*MatrixEntry `json:"matrix"` + Matrix []MatrixEntry `json:"matrix"` // Templates specifies a list of templates to render and deploy // +required diff --git a/api/v1alpha1/texttemplate_types.go b/api/v1alpha1/texttemplate_types.go index 6c980ce..988eade 100644 --- a/api/v1alpha1/texttemplate_types.go +++ b/api/v1alpha1/texttemplate_types.go @@ -33,7 +33,7 @@ type TextTemplateSpec struct { ServiceAccountName string `json:"serviceAccountName,omitempty"` // +optional - Inputs []*TextTemplateInput `json:"inputs,omitempty"` + Inputs []TextTemplateInput `json:"inputs,omitempty"` // +optional Template *string `json:"template,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 1b2ab65..d852af4 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -987,13 +987,9 @@ func (in *ObjectTemplateSpec) DeepCopyInto(out *ObjectTemplateSpec) { out.Interval = in.Interval if in.Matrix != nil { in, out := &in.Matrix, &out.Matrix - *out = make([]*MatrixEntry, len(*in)) + *out = make([]MatrixEntry, len(*in)) for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(MatrixEntry) - (*in).DeepCopyInto(*out) - } + (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Templates != nil { @@ -1221,13 +1217,9 @@ func (in *TextTemplateSpec) DeepCopyInto(out *TextTemplateSpec) { *out = *in if in.Inputs != nil { in, out := &in.Inputs, &out.Inputs - *out = make([]*TextTemplateInput, len(*in)) + *out = make([]TextTemplateInput, len(*in)) for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(TextTemplateInput) - (*in).DeepCopyInto(*out) - } + (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Template != nil { diff --git a/controllers/objecttemplate_controller_test.go b/controllers/objecttemplate_controller_test.go index c155b75..0610d31 100644 --- a/controllers/objecttemplate_controller_test.go +++ b/controllers/objecttemplate_controller_test.go @@ -67,7 +67,7 @@ func buildTestSecret(name string, namespace string, data map[string]string) *uns } } -func buildObjectTemplate(name string, namespace string, matrixEntries []*templatesv1alpha1.MatrixEntry, templates []templatesv1alpha1.Template) *templatesv1alpha1.ObjectTemplate { +func buildObjectTemplate(name string, namespace string, matrixEntries []templatesv1alpha1.MatrixEntry, templates []templatesv1alpha1.Template) *templatesv1alpha1.ObjectTemplate { t := &templatesv1alpha1.ObjectTemplate{ TypeMeta: metav1.TypeMeta{ APIVersion: templatesv1alpha1.GroupVersion.String(), @@ -86,8 +86,8 @@ func buildObjectTemplate(name string, namespace string, matrixEntries []*templat return t } -func buildMatrixListEntry(name string) *templatesv1alpha1.MatrixEntry { - return &templatesv1alpha1.MatrixEntry{ +func buildMatrixListEntry(name string) templatesv1alpha1.MatrixEntry { + return templatesv1alpha1.MatrixEntry{ Name: name, List: []runtime.RawExtension{ { @@ -97,12 +97,12 @@ func buildMatrixListEntry(name string) *templatesv1alpha1.MatrixEntry { } } -func buildMatrixObjectEntry(name string, objName string, objNamespace string, objKind string, jsonPath string, expandLists bool) *templatesv1alpha1.MatrixEntry { +func buildMatrixObjectEntry(name string, objName string, objNamespace string, objKind string, jsonPath string, expandLists bool) templatesv1alpha1.MatrixEntry { var jsonPathPtr *string if jsonPath != "" { jsonPathPtr = &jsonPath } - return &templatesv1alpha1.MatrixEntry{ + return templatesv1alpha1.MatrixEntry{ Name: name, Object: &templatesv1alpha1.MatrixEntryObject{ Ref: templatesv1alpha1.ObjectRef{ @@ -207,7 +207,7 @@ var _ = Describe("ObjectTemplate controller", func() { cmKey := client2.ObjectKey{Name: "cm1", Namespace: ns} t := buildObjectTemplate(key.Name, key.Namespace, - []*templatesv1alpha1.MatrixEntry{buildMatrixListEntry("m1")}, + []templatesv1alpha1.MatrixEntry{buildMatrixListEntry("m1")}, []templatesv1alpha1.Template{ {Object: buildTestConfigMap(cmKey.Name, cmKey.Namespace, map[string]string{ "k1": `{{ matrix.m1.k1 + matrix.m1.k2 }}`, @@ -271,7 +271,7 @@ var _ = Describe("ObjectTemplate controller", func() { createRoleWithBinding("default", ns, []string{"configmaps"}) t := buildObjectTemplate(key.Name, key.Namespace, - []*templatesv1alpha1.MatrixEntry{ + []templatesv1alpha1.MatrixEntry{ buildMatrixObjectEntry("m1", "m1", ns, "Secret", "", false), }, []templatesv1alpha1.Template{ diff --git a/docs/api/template-controller.md b/docs/api/template-controller.md index ecd4a02..d3937e3 100644 --- a/docs/api/template-controller.md +++ b/docs/api/template-controller.md @@ -1971,6 +1971,10 @@ string

MatrixEntry

+

+(Appears on: +ObjectTemplateSpec) +

@@ -2242,8 +2246,8 @@ bool @@ -2353,8 +2357,8 @@ bool @@ -2669,8 +2673,8 @@ when reconciling this TextTemplate. If omitted, the “default” servic @@ -2723,6 +2727,10 @@ TextTemplateStatus

TextTemplateInput

+

+(Appears on: +TextTemplateSpec) +

matrix
- -[]*github.com/kluctl/template-controller/api/v1alpha1.MatrixEntry + +[]MatrixEntry
matrix
- -[]*github.com/kluctl/template-controller/api/v1alpha1.MatrixEntry + +[]MatrixEntry
inputs
- -[]*github.com/kluctl/template-controller/api/v1alpha1.TextTemplateInput + +[]TextTemplateInput
@@ -2849,8 +2857,8 @@ when reconciling this TextTemplate. If omitted, the “default” servic
inputs
- -[]*github.com/kluctl/template-controller/api/v1alpha1.TextTemplateInput + +[]TextTemplateInput