Skip to content

OCPCLOUD-2716: add ownerReference to resource builders #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ func OpenStackMachine() OpenStackMachineBuilder {
// OpenStackMachineBuilder is used to build out an OpenStackMachine object.
type OpenStackMachineBuilder struct {
// ObjectMeta fields.
annotations map[string]string
labels map[string]string
name string
namespace string
annotations map[string]string
labels map[string]string
name string
namespace string
ownerReferences []metav1.OwnerReference

// Spec fields.
additionalBlockDevices []capov1.AdditionalBlockDevice
Expand Down Expand Up @@ -75,10 +76,11 @@ func (a OpenStackMachineBuilder) Build() *capov1.OpenStackMachine {
Kind: "OpenStackMachine",
},
ObjectMeta: metav1.ObjectMeta{
Name: a.name,
Namespace: a.namespace,
Labels: a.labels,
Annotations: a.annotations,
Name: a.name,
Namespace: a.namespace,
Labels: a.labels,
Annotations: a.annotations,
OwnerReferences: a.ownerReferences,
},
Spec: capov1.OpenStackMachineSpec{
AdditionalBlockDevices: a.additionalBlockDevices,
Expand Down Expand Up @@ -138,6 +140,12 @@ func (a OpenStackMachineBuilder) WithNamespace(namespace string) OpenStackMachin
return a
}

// WithOwnerReferences sets the OwnerReferences for the machine builder.
func (a OpenStackMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) OpenStackMachineBuilder {
a.ownerReferences = ownerRefs
return a
}

// Spec fields.

// WithAdditionalBlockDevices sets the additionalBlockDevices for the OpenStackMachine builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capov1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
)

Expand All @@ -44,6 +45,14 @@ var _ = Describe("OpenStackMachineBuilder", func() {
})
})

Describe("WithOwnerReferences", func() {
It("should return the custom value when specified", func() {
ownerReferences := []metav1.OwnerReference{{Name: "machine"}}
openstackMachine := OpenStackMachine().WithOwnerReferences(ownerReferences).Build()
Expect(openstackMachine.OwnerReferences).To(Equal(ownerReferences))
})
})

// Spec fields.

Describe("WithAdditionalBlockDevices", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type OpenStackMachineTemplateBuilder struct {
labels map[string]string
name string
namespace string
ownerReference []metav1.OwnerReference

// Spec fields.
additionalBlockDevices []capov1.AdditionalBlockDevice
Expand Down Expand Up @@ -72,6 +73,7 @@ func (a OpenStackMachineTemplateBuilder) Build() *capov1.OpenStackMachineTemplat
Labels: a.labels,
Name: a.name,
Namespace: a.namespace,
OwnerReferences: a.ownerReference,
},
Spec: capov1.OpenStackMachineTemplateSpec{
Template: capov1.OpenStackMachineTemplateResource{
Expand Down Expand Up @@ -144,6 +146,12 @@ func (a OpenStackMachineTemplateBuilder) WithNamespace(namespace string) OpenSta
return a
}

// WithOwnerReferences sets the OwnerReferences for the OpenStackMachineTemplate builder.
func (a OpenStackMachineTemplateBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) OpenStackMachineTemplateBuilder {
a.ownerReference = ownerRefs
return a
}

// Spec fields.

// WithAdditionalBlockDevices sets the additionalBlockDevices for the OpenStackMachine builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

capov1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
)
Expand All @@ -43,6 +44,14 @@ var _ = Describe("OpenStackMachineTemplateBuilder", func() {
})
})

Describe("WithOwnerReferences", func() {
It("should return the custom value when specified", func() {
ownerReferences := []metav1.OwnerReference{{Name: "cluster"}}
openstackMachineTemplate := OpenStackMachineTemplate().WithOwnerReferences(ownerReferences).Build()
Expect(openstackMachineTemplate.OwnerReferences).To(Equal(ownerReferences))
})
})

// Spec fields.

Describe("WithAdditionalBlockDevices", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func AWSMachine() AWSMachineBuilder {
// AWSMachineBuilder is used to build out an AWSMachine object.
type AWSMachineBuilder struct {
// ObjectMeta fields.
annotations map[string]string
labels map[string]string
name string
namespace string
annotations map[string]string
labels map[string]string
name string
namespace string
ownerReferences []metav1.OwnerReference

// Spec fields.
additionalSecurityGroups []capav1.AWSResourceReference
Expand Down Expand Up @@ -83,10 +84,11 @@ func (a AWSMachineBuilder) Build() *capav1.AWSMachine {
Kind: "AWSMachine",
},
ObjectMeta: metav1.ObjectMeta{
Name: a.name,
Namespace: a.namespace,
Labels: a.labels,
Annotations: a.annotations,
Name: a.name,
Namespace: a.namespace,
Labels: a.labels,
Annotations: a.annotations,
OwnerReferences: a.ownerReferences,
},
Spec: capav1.AWSMachineSpec{
AdditionalSecurityGroups: a.additionalSecurityGroups,
Expand Down Expand Up @@ -158,6 +160,12 @@ func (a AWSMachineBuilder) WithNamespace(namespace string) AWSMachineBuilder {
return a
}

// WithOwnerReferences sets the OwnerReferences for the machine builder.
func (a AWSMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) AWSMachineBuilder {
a.ownerReferences = ownerRefs
return a
}

// Spec fields.

// WithAdditionalSecurityGroups sets the additionalSecurityGroups for the AWSMachine builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
capav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -68,6 +69,14 @@ var _ = Describe("AWSMachineBuilder", func() {
})
})

Describe("WithOwnerReferences", func() {
It("should return the custom value when specified", func() {
ownerRefs := []metav1.OwnerReference{{Name: "machineName"}}
awsMachine := AWSMachine().WithOwnerReferences(ownerRefs).Build()
Expect(awsMachine.OwnerReferences).To(Equal(ownerRefs))
})
})

// Spec fields
Describe("WithAdditionalSecurityGroups", func() {
It("should return the custom value when specified", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type AWSMachineTemplateBuilder struct {
labels map[string]string
name string
namespace string
ownerReferences []metav1.OwnerReference

// Spec fields.
additionalSecurityGroups []capav1.AWSResourceReference
Expand Down Expand Up @@ -87,6 +88,7 @@ func (a AWSMachineTemplateBuilder) Build() *capav1.AWSMachineTemplate {
Labels: a.labels,
Name: a.name,
Namespace: a.namespace,
OwnerReferences: a.ownerReferences,
},
Spec: capav1.AWSMachineTemplateSpec{
Template: capav1.AWSMachineTemplateResource{
Expand Down Expand Up @@ -174,6 +176,12 @@ func (a AWSMachineTemplateBuilder) WithNamespace(namespace string) AWSMachineTem
return a
}

// WithOwnerReferences sets the OwnerReferences for the AWSMachineTemplate builder.
func (a AWSMachineTemplateBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) AWSMachineTemplateBuilder {
a.ownerReferences = ownerRefs
return a
}

// Spec fields.

// WithAdditionalSecurityGroups sets the additionalSecurityGroups for the AWSMachineTemplate builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ var _ = Describe("AWSMachineTemplate", func() {
})
})

Describe("WithOwnerReferences", func() {
It("should return the custom value when specified", func() {
ownerReferences := []metav1.OwnerReference{{Name: "cluster"}}
awsMachineTemplate := AWSMachineTemplate().WithOwnerReferences(ownerReferences).Build()
Expect(awsMachineTemplate.OwnerReferences).To(Equal(ownerReferences))
})
})

// Spec fields.

Describe("WithAdditionalSecurityGroups", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ func PowerVSMachine() PowerVSMachineBuilder {
// PowerVSMachineBuilder is used to build out an PowerVSMachine object.
type PowerVSMachineBuilder struct {
// ObjectMeta fields.
annotations map[string]string
labels map[string]string
name string
namespace string
annotations map[string]string
labels map[string]string
name string
namespace string
ownerReferences []metav1.OwnerReference

// Spec fields.
image *capibmv1.IBMPowerVSResourceReference
Expand Down Expand Up @@ -66,10 +67,11 @@ func (p PowerVSMachineBuilder) Build() *capibmv1.IBMPowerVSMachine {
APIVersion: capibmv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: p.name,
Namespace: p.namespace,
Labels: p.labels,
Annotations: p.annotations,
Name: p.name,
Namespace: p.namespace,
Labels: p.labels,
Annotations: p.annotations,
OwnerReferences: p.ownerReferences,
},
Spec: capibmv1.IBMPowerVSMachineSpec{
ServiceInstance: p.serviceInstance,
Expand Down Expand Up @@ -121,6 +123,12 @@ func (p PowerVSMachineBuilder) WithNamespace(namespace string) PowerVSMachineBui
return p
}

// WithOwnerReferences sets the OwnerReferences for the machine builder.
func (p PowerVSMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) PowerVSMachineBuilder {
p.ownerReferences = ownerRefs
return p
}

// Spec fields.

// WithImage sets the image for the PowerVSMachine builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
capibmv1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
Expand Down Expand Up @@ -70,6 +71,14 @@ var _ = Describe("PowerVSMachine", func() {
})
})

Describe("WithOwnerReferences", func() {
It("should return the custom value when specified", func() {
ownerReferences := []metav1.OwnerReference{{Name: "machine"}}
PowerVSMachine := PowerVSMachine().WithOwnerReferences(ownerReferences).Build()
Expect(PowerVSMachine.OwnerReferences).To(Equal(ownerReferences))
})
})

// Spec fields.

Describe("WithImage", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type PowerVSMachineTemplateBuilder struct {
labels map[string]string
name string
namespace string
ownerReferences []metav1.OwnerReference

// Spec fields.
image *capibmv1.IBMPowerVSResourceReference
Expand Down Expand Up @@ -70,6 +71,7 @@ func (p PowerVSMachineTemplateBuilder) Build() *capibmv1.IBMPowerVSMachineTempla
Labels: p.labels,
Name: p.name,
Namespace: p.namespace,
OwnerReferences: p.ownerReferences,
},
Spec: capibmv1.IBMPowerVSMachineTemplateSpec{
Template: capibmv1.IBMPowerVSMachineTemplateResource{
Expand Down Expand Up @@ -137,6 +139,12 @@ func (p PowerVSMachineTemplateBuilder) WithNamespace(namespace string) PowerVSMa
return p
}

// WithOwnerReferences sets the OwnerReferences for the PowerVSMachineTemplate builder.
func (p PowerVSMachineTemplateBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) PowerVSMachineTemplateBuilder {
p.ownerReferences = ownerRefs
return p
}

// Spec fields.

// WithImage sets the image for the PowerVSMachineTemplate builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ var _ = Describe("PowerVSMachineTemplate", func() {
})
})

Describe("WithOwnerReferences", func() {
It("should return the custom value when specified", func() {
ownerReferences := []metav1.OwnerReference{{Name: "cluster"}}
powerVSMachineTemplate := PowerVSMachineTemplate().WithOwnerReferences(ownerReferences).Build()
Expect(powerVSMachineTemplate.OwnerReferences).To(Equal(ownerReferences))
})
})

// Spec fields.

Describe("WithServiceInstance", func() {
Expand Down