Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Remove pointer to BundleTemplate from spec
Browse files Browse the repository at this point in the history
`Template` field in `BundleDeploymentSpec` seems to have
unnecessary pointer as we expect to always populate this field.

Signed-off-by: Mikalai Radchuk <[email protected]>
  • Loading branch information
Mikalai Radchuk authored and stevekuznetsov committed Nov 7, 2023
1 parent ee9a975 commit 4f952d4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/bundledeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 1 addition & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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])
Expand Down
14 changes: 7 additions & 7 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/api_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/helm_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/plain_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/registry_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 4f952d4

Please sign in to comment.