Skip to content

Commit 44e6187

Browse files
Merge pull request #390 from RadekManak/ownerrefbuilders
OCPCLOUD-2716: add ownerReference to resource builders
2 parents 157f88e + 998198b commit 44e6187

12 files changed

+124
-24
lines changed

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta1/openstackmachine.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ func OpenStackMachine() OpenStackMachineBuilder {
3434
// OpenStackMachineBuilder is used to build out an OpenStackMachine object.
3535
type OpenStackMachineBuilder struct {
3636
// ObjectMeta fields.
37-
annotations map[string]string
38-
labels map[string]string
39-
name string
40-
namespace string
37+
annotations map[string]string
38+
labels map[string]string
39+
name string
40+
namespace string
41+
ownerReferences []metav1.OwnerReference
4142

4243
// Spec fields.
4344
additionalBlockDevices []capov1.AdditionalBlockDevice
@@ -75,10 +76,11 @@ func (a OpenStackMachineBuilder) Build() *capov1.OpenStackMachine {
7576
Kind: "OpenStackMachine",
7677
},
7778
ObjectMeta: metav1.ObjectMeta{
78-
Name: a.name,
79-
Namespace: a.namespace,
80-
Labels: a.labels,
81-
Annotations: a.annotations,
79+
Name: a.name,
80+
Namespace: a.namespace,
81+
Labels: a.labels,
82+
Annotations: a.annotations,
83+
OwnerReferences: a.ownerReferences,
8284
},
8385
Spec: capov1.OpenStackMachineSpec{
8486
AdditionalBlockDevices: a.additionalBlockDevices,
@@ -138,6 +140,12 @@ func (a OpenStackMachineBuilder) WithNamespace(namespace string) OpenStackMachin
138140
return a
139141
}
140142

143+
// WithOwnerReferences sets the OwnerReferences for the machine builder.
144+
func (a OpenStackMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) OpenStackMachineBuilder {
145+
a.ownerReferences = ownerRefs
146+
return a
147+
}
148+
141149
// Spec fields.
142150

143151
// WithAdditionalBlockDevices sets the additionalBlockDevices for the OpenStackMachine builder.

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta1/openstackmachine_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
. "github.com/onsi/gomega"
2222

2323
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
capov1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
2526
)
2627

@@ -44,6 +45,14 @@ var _ = Describe("OpenStackMachineBuilder", func() {
4445
})
4546
})
4647

48+
Describe("WithOwnerReferences", func() {
49+
It("should return the custom value when specified", func() {
50+
ownerReferences := []metav1.OwnerReference{{Name: "machine"}}
51+
openstackMachine := OpenStackMachine().WithOwnerReferences(ownerReferences).Build()
52+
Expect(openstackMachine.OwnerReferences).To(Equal(ownerReferences))
53+
})
54+
})
55+
4756
// Spec fields.
4857

4958
Describe("WithAdditionalBlockDevices", func() {

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta1/openstackmachinetemplate.go

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type OpenStackMachineTemplateBuilder struct {
3737
labels map[string]string
3838
name string
3939
namespace string
40+
ownerReference []metav1.OwnerReference
4041

4142
// Spec fields.
4243
additionalBlockDevices []capov1.AdditionalBlockDevice
@@ -72,6 +73,7 @@ func (a OpenStackMachineTemplateBuilder) Build() *capov1.OpenStackMachineTemplat
7273
Labels: a.labels,
7374
Name: a.name,
7475
Namespace: a.namespace,
76+
OwnerReferences: a.ownerReference,
7577
},
7678
Spec: capov1.OpenStackMachineTemplateSpec{
7779
Template: capov1.OpenStackMachineTemplateResource{
@@ -144,6 +146,12 @@ func (a OpenStackMachineTemplateBuilder) WithNamespace(namespace string) OpenSta
144146
return a
145147
}
146148

149+
// WithOwnerReferences sets the OwnerReferences for the OpenStackMachineTemplate builder.
150+
func (a OpenStackMachineTemplateBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) OpenStackMachineTemplateBuilder {
151+
a.ownerReference = ownerRefs
152+
return a
153+
}
154+
147155
// Spec fields.
148156

149157
// WithAdditionalBlockDevices sets the additionalBlockDevices for the OpenStackMachine builder.

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta1/openstackmachinetemplate_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
. "github.com/onsi/ginkgo/v2"
2121
. "github.com/onsi/gomega"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223

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

47+
Describe("WithOwnerReferences", func() {
48+
It("should return the custom value when specified", func() {
49+
ownerReferences := []metav1.OwnerReference{{Name: "cluster"}}
50+
openstackMachineTemplate := OpenStackMachineTemplate().WithOwnerReferences(ownerReferences).Build()
51+
Expect(openstackMachineTemplate.OwnerReferences).To(Equal(ownerReferences))
52+
})
53+
})
54+
4655
// Spec fields.
4756

4857
Describe("WithAdditionalBlockDevices", func() {

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/awsmachine.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ func AWSMachine() AWSMachineBuilder {
3030
// AWSMachineBuilder is used to build out an AWSMachine object.
3131
type AWSMachineBuilder struct {
3232
// ObjectMeta fields.
33-
annotations map[string]string
34-
labels map[string]string
35-
name string
36-
namespace string
33+
annotations map[string]string
34+
labels map[string]string
35+
name string
36+
namespace string
37+
ownerReferences []metav1.OwnerReference
3738

3839
// Spec fields.
3940
additionalSecurityGroups []capav1.AWSResourceReference
@@ -83,10 +84,11 @@ func (a AWSMachineBuilder) Build() *capav1.AWSMachine {
8384
Kind: "AWSMachine",
8485
},
8586
ObjectMeta: metav1.ObjectMeta{
86-
Name: a.name,
87-
Namespace: a.namespace,
88-
Labels: a.labels,
89-
Annotations: a.annotations,
87+
Name: a.name,
88+
Namespace: a.namespace,
89+
Labels: a.labels,
90+
Annotations: a.annotations,
91+
OwnerReferences: a.ownerReferences,
9092
},
9193
Spec: capav1.AWSMachineSpec{
9294
AdditionalSecurityGroups: a.additionalSecurityGroups,
@@ -158,6 +160,12 @@ func (a AWSMachineBuilder) WithNamespace(namespace string) AWSMachineBuilder {
158160
return a
159161
}
160162

163+
// WithOwnerReferences sets the OwnerReferences for the machine builder.
164+
func (a AWSMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) AWSMachineBuilder {
165+
a.ownerReferences = ownerRefs
166+
return a
167+
}
168+
161169
// Spec fields.
162170

163171
// WithAdditionalSecurityGroups sets the additionalSecurityGroups for the AWSMachine builder.

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/awsmachine_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
. "github.com/onsi/gomega"
2222

2323
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
"k8s.io/utils/ptr"
2526
capav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2627
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -68,6 +69,14 @@ var _ = Describe("AWSMachineBuilder", func() {
6869
})
6970
})
7071

72+
Describe("WithOwnerReferences", func() {
73+
It("should return the custom value when specified", func() {
74+
ownerRefs := []metav1.OwnerReference{{Name: "machineName"}}
75+
awsMachine := AWSMachine().WithOwnerReferences(ownerRefs).Build()
76+
Expect(awsMachine.OwnerReferences).To(Equal(ownerRefs))
77+
})
78+
})
79+
7180
// Spec fields
7281
Describe("WithAdditionalSecurityGroups", func() {
7382
It("should return the custom value when specified", func() {

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/awsmachinetemplate.go

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type AWSMachineTemplateBuilder struct {
3737
labels map[string]string
3838
name string
3939
namespace string
40+
ownerReferences []metav1.OwnerReference
4041

4142
// Spec fields.
4243
additionalSecurityGroups []capav1.AWSResourceReference
@@ -87,6 +88,7 @@ func (a AWSMachineTemplateBuilder) Build() *capav1.AWSMachineTemplate {
8788
Labels: a.labels,
8889
Name: a.name,
8990
Namespace: a.namespace,
91+
OwnerReferences: a.ownerReferences,
9092
},
9193
Spec: capav1.AWSMachineTemplateSpec{
9294
Template: capav1.AWSMachineTemplateResource{
@@ -174,6 +176,12 @@ func (a AWSMachineTemplateBuilder) WithNamespace(namespace string) AWSMachineTem
174176
return a
175177
}
176178

179+
// WithOwnerReferences sets the OwnerReferences for the AWSMachineTemplate builder.
180+
func (a AWSMachineTemplateBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) AWSMachineTemplateBuilder {
181+
a.ownerReferences = ownerRefs
182+
return a
183+
}
184+
177185
// Spec fields.
178186

179187
// WithAdditionalSecurityGroups sets the additionalSecurityGroups for the AWSMachineTemplate builder.

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/awsmachinetemplate_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ var _ = Describe("AWSMachineTemplate", func() {
9292
})
9393
})
9494

95+
Describe("WithOwnerReferences", func() {
96+
It("should return the custom value when specified", func() {
97+
ownerReferences := []metav1.OwnerReference{{Name: "cluster"}}
98+
awsMachineTemplate := AWSMachineTemplate().WithOwnerReferences(ownerReferences).Build()
99+
Expect(awsMachineTemplate.OwnerReferences).To(Equal(ownerReferences))
100+
})
101+
})
102+
95103
// Spec fields.
96104

97105
Describe("WithAdditionalSecurityGroups", func() {

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/powervsmachine.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ func PowerVSMachine() PowerVSMachineBuilder {
3232
// PowerVSMachineBuilder is used to build out an PowerVSMachine object.
3333
type PowerVSMachineBuilder struct {
3434
// ObjectMeta fields.
35-
annotations map[string]string
36-
labels map[string]string
37-
name string
38-
namespace string
35+
annotations map[string]string
36+
labels map[string]string
37+
name string
38+
namespace string
39+
ownerReferences []metav1.OwnerReference
3940

4041
// Spec fields.
4142
image *capibmv1.IBMPowerVSResourceReference
@@ -66,10 +67,11 @@ func (p PowerVSMachineBuilder) Build() *capibmv1.IBMPowerVSMachine {
6667
APIVersion: capibmv1.GroupVersion.String(),
6768
},
6869
ObjectMeta: metav1.ObjectMeta{
69-
Name: p.name,
70-
Namespace: p.namespace,
71-
Labels: p.labels,
72-
Annotations: p.annotations,
70+
Name: p.name,
71+
Namespace: p.namespace,
72+
Labels: p.labels,
73+
Annotations: p.annotations,
74+
OwnerReferences: p.ownerReferences,
7375
},
7476
Spec: capibmv1.IBMPowerVSMachineSpec{
7577
ServiceInstance: p.serviceInstance,
@@ -121,6 +123,12 @@ func (p PowerVSMachineBuilder) WithNamespace(namespace string) PowerVSMachineBui
121123
return p
122124
}
123125

126+
// WithOwnerReferences sets the OwnerReferences for the machine builder.
127+
func (p PowerVSMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) PowerVSMachineBuilder {
128+
p.ownerReferences = ownerRefs
129+
return p
130+
}
131+
124132
// Spec fields.
125133

126134
// WithImage sets the image for the PowerVSMachine builder.

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/powervsmachine_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
. "github.com/onsi/gomega"
2222

2323
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
"k8s.io/apimachinery/pkg/util/intstr"
2526
"k8s.io/utils/ptr"
2627
capibmv1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
@@ -70,6 +71,14 @@ var _ = Describe("PowerVSMachine", func() {
7071
})
7172
})
7273

74+
Describe("WithOwnerReferences", func() {
75+
It("should return the custom value when specified", func() {
76+
ownerReferences := []metav1.OwnerReference{{Name: "machine"}}
77+
PowerVSMachine := PowerVSMachine().WithOwnerReferences(ownerReferences).Build()
78+
Expect(PowerVSMachine.OwnerReferences).To(Equal(ownerReferences))
79+
})
80+
})
81+
7382
// Spec fields.
7483

7584
Describe("WithImage", func() {

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/powervsmachinetemplate.go

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type PowerVSMachineTemplateBuilder struct {
3838
labels map[string]string
3939
name string
4040
namespace string
41+
ownerReferences []metav1.OwnerReference
4142

4243
// Spec fields.
4344
image *capibmv1.IBMPowerVSResourceReference
@@ -70,6 +71,7 @@ func (p PowerVSMachineTemplateBuilder) Build() *capibmv1.IBMPowerVSMachineTempla
7071
Labels: p.labels,
7172
Name: p.name,
7273
Namespace: p.namespace,
74+
OwnerReferences: p.ownerReferences,
7375
},
7476
Spec: capibmv1.IBMPowerVSMachineTemplateSpec{
7577
Template: capibmv1.IBMPowerVSMachineTemplateResource{
@@ -137,6 +139,12 @@ func (p PowerVSMachineTemplateBuilder) WithNamespace(namespace string) PowerVSMa
137139
return p
138140
}
139141

142+
// WithOwnerReferences sets the OwnerReferences for the PowerVSMachineTemplate builder.
143+
func (p PowerVSMachineTemplateBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) PowerVSMachineTemplateBuilder {
144+
p.ownerReferences = ownerRefs
145+
return p
146+
}
147+
140148
// Spec fields.
141149

142150
// WithImage sets the image for the PowerVSMachineTemplate builder.

Diff for: testutils/resourcebuilder/cluster-api/infrastructure/v1beta2/powervsmachinetemplate_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ var _ = Describe("PowerVSMachineTemplate", func() {
9494
})
9595
})
9696

97+
Describe("WithOwnerReferences", func() {
98+
It("should return the custom value when specified", func() {
99+
ownerReferences := []metav1.OwnerReference{{Name: "cluster"}}
100+
powerVSMachineTemplate := PowerVSMachineTemplate().WithOwnerReferences(ownerReferences).Build()
101+
Expect(powerVSMachineTemplate.OwnerReferences).To(Equal(ownerReferences))
102+
})
103+
})
104+
97105
// Spec fields.
98106

99107
Describe("WithServiceInstance", func() {

0 commit comments

Comments
 (0)