From b4a77a0c1a5f6664afea7d21d84d032ed5b22bb5 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Mon, 6 Nov 2023 15:23:30 +0000 Subject: [PATCH] Remove pointer to `BundleTemplate` from spec `Template` field in `BundleDeploymentSpec` seems to have unnecessary pointer as we expect to always populate this field. Signed-off-by: Mikalai Radchuk --- api/v1alpha1/bundledeployment_types.go | 2 +- api/v1alpha1/zz_generated.deepcopy.go | 6 +----- internal/util/util.go | 6 +++--- internal/util/util_test.go | 14 +++++++------- test/e2e/api_validation_test.go | 6 +++--- test/e2e/helm_provisioner_test.go | 14 +++++++------- test/e2e/plain_provisioner_test.go | 18 +++++++++--------- test/e2e/registry_provisioner_test.go | 4 ++-- 8 files changed, 33 insertions(+), 37 deletions(-) diff --git a/api/v1alpha1/bundledeployment_types.go b/api/v1alpha1/bundledeployment_types.go index 8f147a37..5d5044d8 100644 --- a/api/v1alpha1/bundledeployment_types.go +++ b/api/v1alpha1/bundledeployment_types.go @@ -53,7 +53,7 @@ type BundleDeploymentSpec struct { // ProvisionerClassName sets the name of the provisioner that should reconcile this BundleDeployment. ProvisionerClassName string `json:"provisionerClassName"` // Template describes the generated Bundle that this deployment will manage. - Template *BundleTemplate `json:"template"` + Template BundleTemplate `json:"template"` // Config is provisioner specific configurations // +kubebuilder:pruning:PreserveUnknownFields Config runtime.RawExtension `json:"config,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 695db718..25fdf03f 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -131,11 +131,7 @@ func (in *BundleDeploymentList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BundleDeploymentSpec) DeepCopyInto(out *BundleDeploymentSpec) { *out = *in - if in.Template != nil { - in, out := &in.Template, &out.Template - *out = new(BundleTemplate) - (*in).DeepCopyInto(*out) - } + in.Template.DeepCopyInto(&out.Template) in.Config.DeepCopyInto(&out.Config) } diff --git a/internal/util/util.go b/internal/util/util.go index c940d93a..3648d74d 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -270,7 +270,7 @@ func GetBundlesForBundleDeploymentSelector(ctx context.Context, c client.Client, // CheckExistingBundlesMatchesTemplate evaluates whether the existing list of Bundle objects // match the desired Bundle template that's specified in a BundleDeployment object. If a match // is found, that Bundle object is returned, so callers are responsible for nil checking the result. -func CheckExistingBundlesMatchesTemplate(existingBundles *rukpakv1alpha1.BundleList, desiredBundleTemplate *rukpakv1alpha1.BundleTemplate) *rukpakv1alpha1.Bundle { +func CheckExistingBundlesMatchesTemplate(existingBundles *rukpakv1alpha1.BundleList, desiredBundleTemplate rukpakv1alpha1.BundleTemplate) *rukpakv1alpha1.Bundle { for i := range existingBundles.Items { if !CheckDesiredBundleTemplate(&existingBundles.Items[i], desiredBundleTemplate) { continue @@ -282,7 +282,7 @@ func CheckExistingBundlesMatchesTemplate(existingBundles *rukpakv1alpha1.BundleL // CheckDesiredBundleTemplate is responsible for determining whether the existingBundle // hash is equal to the desiredBundle Bundle template hash. -func CheckDesiredBundleTemplate(existingBundle *rukpakv1alpha1.Bundle, desiredBundle *rukpakv1alpha1.BundleTemplate) bool { +func CheckDesiredBundleTemplate(existingBundle *rukpakv1alpha1.Bundle, desiredBundle rukpakv1alpha1.BundleTemplate) bool { if len(existingBundle.Labels) == 0 { // Existing Bundle has no labels set, which should never be the case. // Return false so that the Bundle is forced to be recreated with the expected labels. @@ -301,7 +301,7 @@ func CheckDesiredBundleTemplate(existingBundle *rukpakv1alpha1.Bundle, desiredBu return existingHash == desiredHash } -func GenerateTemplateHash(template *rukpakv1alpha1.BundleTemplate) string { +func GenerateTemplateHash(template rukpakv1alpha1.BundleTemplate) string { hasher := fnv.New32a() DeepHashObject(hasher, template) return rand.SafeEncodeString(fmt.Sprintf("%x", hasher.Sum32())[:6]) diff --git a/internal/util/util_test.go b/internal/util/util_test.go index 4f2ecf69..5c832a87 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -21,7 +21,7 @@ var sampleSpec = rukpakv1alpha1.BundleSpec{ func TestCheckDesiredBundleTemplate(t *testing.T) { type args struct { existingBundle *rukpakv1alpha1.Bundle - desiredBundle *rukpakv1alpha1.BundleTemplate + desiredBundle rukpakv1alpha1.BundleTemplate } tests := []struct { name string @@ -40,7 +40,7 @@ func TestCheckDesiredBundleTemplate(t *testing.T) { }, Spec: sampleSpec, }, - desiredBundle: &rukpakv1alpha1.BundleTemplate{ + desiredBundle: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "stub", Labels: map[string]string{ @@ -66,7 +66,7 @@ func TestCheckDesiredBundleTemplate(t *testing.T) { ProvisionerClassName: "non-existent-provisioner-class-name", }, }, - desiredBundle: &rukpakv1alpha1.BundleTemplate{ + desiredBundle: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "stub", Labels: map[string]string{ @@ -90,7 +90,7 @@ func TestCheckDesiredBundleTemplate(t *testing.T) { }, Spec: sampleSpec, }, - desiredBundle: &rukpakv1alpha1.BundleTemplate{ + desiredBundle: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "stub", Labels: map[string]string{ @@ -117,7 +117,7 @@ func TestCheckDesiredBundleTemplate(t *testing.T) { }, Spec: sampleSpec, }, - desiredBundle: &rukpakv1alpha1.BundleTemplate{ + desiredBundle: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "stub", Labels: map[string]string{ @@ -144,7 +144,7 @@ func TestCheckDesiredBundleTemplate(t *testing.T) { }, Spec: sampleSpec, }, - desiredBundle: &rukpakv1alpha1.BundleTemplate{ + desiredBundle: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "stub-123", Labels: map[string]string{ @@ -180,7 +180,7 @@ func injectCoreLabels(bundle *rukpakv1alpha1.Bundle) { labels[CoreOwnerNameKey] = "" } -func injectTemplateHashLabel(bundle *rukpakv1alpha1.Bundle, template *rukpakv1alpha1.BundleTemplate, want bool) { +func injectTemplateHashLabel(bundle *rukpakv1alpha1.Bundle, template rukpakv1alpha1.BundleTemplate, want bool) { labels := bundle.GetLabels() if want { labels[CoreBundleTemplateHashKey] = GenerateTemplateHash(template) diff --git a/test/e2e/api_validation_test.go b/test/e2e/api_validation_test.go index 7a866b36..973a28b0 100644 --- a/test/e2e/api_validation_test.go +++ b/test/e2e/api_validation_test.go @@ -257,7 +257,7 @@ var _ = Describe("bundle deployment api validation", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ Spec: rukpakv1alpha1.BundleSpec{ ProvisionerClassName: plain.ProvisionerID, Source: rukpakv1alpha1.BundleSource{ @@ -302,7 +302,7 @@ var _ = Describe("bundle deployment api validation", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: "invalid/class-name", - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ Spec: rukpakv1alpha1.BundleSpec{ ProvisionerClassName: plain.ProvisionerID, Source: rukpakv1alpha1.BundleSource{ @@ -344,7 +344,7 @@ var _ = Describe("bundle deployment api validation", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ Spec: rukpakv1alpha1.BundleSpec{ ProvisionerClassName: "invalid/class-name", Source: rukpakv1alpha1.BundleSource{ diff --git a/test/e2e/helm_provisioner_test.go b/test/e2e/helm_provisioner_test.go index 9ad94ebe..6ac8e432 100644 --- a/test/e2e/helm_provisioner_test.go +++ b/test/e2e/helm_provisioner_test.go @@ -33,7 +33,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", @@ -147,7 +147,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", @@ -203,7 +203,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", @@ -259,7 +259,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", @@ -315,7 +315,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", @@ -439,7 +439,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", @@ -503,7 +503,7 @@ var _ = Describe("helm provisioner bundledeployment", func() { Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: helm.ProvisionerID, Config: runtime.RawExtension{Raw: []byte(`{"values": "# Default values for hello-world.\n# This is a YAML-formatted file.\n# Declare variables to be passed into your templates.\nreplicaCount: 1\nimage:\n repository: nginx\n pullPolicy: IfNotPresent\n # Overrides the image tag whose default is the chart appVersion.\n tag: \"\"\nnameOverride: \"fromvalues\"\nfullnameOverride: \"\"\nserviceAccount:\n # Specifies whether a service account should be created\n create: true\n # Annotations to add to the service account\n annotations: {}\n # The name of the service account to use.\n # If not set and create is true, a name is generated using the fullname template\n name: \"\"\nservice:\n type: ClusterIP\n port: 80\n"}`)}, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "ahoy", diff --git a/test/e2e/plain_provisioner_test.go b/test/e2e/plain_provisioner_test.go index 5d9e1373..04aed04f 100644 --- a/test/e2e/plain_provisioner_test.go +++ b/test/e2e/plain_provisioner_test.go @@ -1394,7 +1394,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ Spec: rukpakv1alpha1.BundleSpec{ ProvisionerClassName: plain.ProvisionerID, Source: rukpakv1alpha1.BundleSource{ @@ -1636,7 +1636,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "olm-crds", @@ -1695,7 +1695,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "olm-apis", @@ -1774,7 +1774,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "olm-apis", @@ -1838,7 +1838,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "e2e-dependent-bundle", @@ -1895,7 +1895,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "e2e-bundle-providing", @@ -1956,7 +1956,7 @@ var _ = Describe("plain provisioner bundledeployment", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "e2e-bundle-crds-and-crs", @@ -2090,7 +2090,7 @@ var _ = Describe("plain provisioner garbage collection", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, }, @@ -2182,7 +2182,7 @@ var _ = Describe("plain provisioner garbage collection", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "e2e-ownerref-bundle-valid", diff --git a/test/e2e/registry_provisioner_test.go b/test/e2e/registry_provisioner_test.go index 1154c6c4..c0f72d7b 100644 --- a/test/e2e/registry_provisioner_test.go +++ b/test/e2e/registry_provisioner_test.go @@ -30,7 +30,7 @@ var _ = Describe("registry provisioner bundle", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "prometheus", @@ -89,7 +89,7 @@ var _ = Describe("registry provisioner bundle", func() { }, Spec: rukpakv1alpha1.BundleDeploymentSpec{ ProvisionerClassName: plain.ProvisionerID, - Template: &rukpakv1alpha1.BundleTemplate{ + Template: rukpakv1alpha1.BundleTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app.kubernetes.io/name": "cincinnati",