Skip to content

Commit 0484e99

Browse files
committed
Move CloudName into IdentityRef and make cluster IdentityRef required
This change came from attempting to write validation markers for CloudName and IdentityRef in both the machine and cluster specs. Firstly I noticed that IdentityRef was marked optional in the cluster spec, but it is certainly required: the cluster cannot be provisioned without cloud credentials. I made IdentityRef required in the cluster spec. In contrast, IdentityRef is genuinely optional in the machine spec because, if not specified, we will use the credentials defined in the cluster spec. CloudName on the machine spec is also marked optional. However, it is required if IdentityRef was specified. This is because it refers to the same object as IdentityRef. The most sensible way to to represent this in the API is to put it in the IdentityRef. This means that if IdentityRef is provided, it must be provided completely, including CloudName.
1 parent 7b202d1 commit 0484e99

28 files changed

+431
-311
lines changed

api/v1alpha5/conversion.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha5_OpenStackClusterSpec(in *i
215215
out.AllowAllInClusterTraffic = in.ManagedSecurityGroups.AllowAllInClusterTraffic
216216
}
217217

218+
out.CloudName = in.IdentityRef.CloudName
219+
out.IdentityRef = &OpenStackIdentityReference{Name: in.IdentityRef.Name}
220+
218221
return nil
219222
}
220223

@@ -258,6 +261,11 @@ func Convert_v1alpha5_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
258261
}
259262
}
260263

264+
out.IdentityRef.CloudName = in.CloudName
265+
if in.IdentityRef != nil {
266+
out.IdentityRef.Name = in.IdentityRef.Name
267+
}
268+
261269
return nil
262270
}
263271

@@ -303,6 +311,16 @@ func Convert_v1alpha5_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O
303311
}
304312
out.Image = imageFilter
305313

314+
if in.IdentityRef != nil {
315+
out.IdentityRef = &infrav1.OpenStackIdentityReference{Name: in.IdentityRef.Name}
316+
}
317+
if in.CloudName != "" {
318+
if out.IdentityRef == nil {
319+
out.IdentityRef = &infrav1.OpenStackIdentityReference{}
320+
}
321+
out.IdentityRef.CloudName = in.CloudName
322+
}
323+
306324
return nil
307325
}
308326

@@ -544,6 +562,11 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *i
544562
out.ImageUUID = in.Image.ID
545563
}
546564

565+
if in.IdentityRef != nil {
566+
out.IdentityRef = &OpenStackIdentityReference{Name: in.IdentityRef.Name}
567+
out.CloudName = in.IdentityRef.CloudName
568+
}
569+
547570
return nil
548571
}
549572

@@ -628,3 +651,8 @@ func Convert_v1alpha5_SecurityGroup_To_v1beta1_SecurityGroupStatus(in *SecurityG
628651
func Convert_v1alpha5_OpenStackIdentityReference_To_v1beta1_OpenStackIdentityReference(in *OpenStackIdentityReference, out *infrav1.OpenStackIdentityReference, s conversion.Scope) error {
629652
return autoConvert_v1alpha5_OpenStackIdentityReference_To_v1beta1_OpenStackIdentityReference(in, out, s)
630653
}
654+
655+
func Convert_v1beta1_OpenStackIdentityReference_To_v1alpha5_OpenStackIdentityReference(in *infrav1.OpenStackIdentityReference, out *OpenStackIdentityReference, _ conversion.Scope) error {
656+
out.Name = in.Name
657+
return nil
658+
}

api/v1alpha5/conversion_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ func TestConvertFrom(t *testing.T) {
4646
Spec: infrav1.OpenStackClusterSpec{},
4747
},
4848
want: &OpenStackCluster{
49-
Spec: OpenStackClusterSpec{},
49+
Spec: OpenStackClusterSpec{
50+
IdentityRef: &OpenStackIdentityReference{},
51+
},
5052
ObjectMeta: metav1.ObjectMeta{
5153
Annotations: map[string]string{
52-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"managedSecurityGroups\":null,\"network\":{}},\"status\":{\"ready\":false}}",
54+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"apiServerLoadBalancer\":{},\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"identityRef\":{\"cloudName\":\"\",\"name\":\"\"},\"managedSecurityGroups\":null,\"network\":{}},\"status\":{\"ready\":false}}",
5355
},
5456
},
5557
},
@@ -61,10 +63,16 @@ func TestConvertFrom(t *testing.T) {
6163
Spec: infrav1.OpenStackClusterTemplateSpec{},
6264
},
6365
want: &OpenStackClusterTemplate{
64-
Spec: OpenStackClusterTemplateSpec{},
66+
Spec: OpenStackClusterTemplateSpec{
67+
Template: OpenStackClusterTemplateResource{
68+
Spec: OpenStackClusterSpec{
69+
IdentityRef: &OpenStackIdentityReference{},
70+
},
71+
},
72+
},
6573
ObjectMeta: metav1.ObjectMeta{
6674
Annotations: map[string]string{
67-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"managedSecurityGroups\":null,\"network\":{}}}}}",
75+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"apiServerLoadBalancer\":{},\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"identityRef\":{\"cloudName\":\"\",\"name\":\"\"},\"managedSecurityGroups\":null,\"network\":{}}}}}",
6876
},
6977
},
7078
},
@@ -79,7 +87,7 @@ func TestConvertFrom(t *testing.T) {
7987
Spec: OpenStackMachineSpec{},
8088
ObjectMeta: metav1.ObjectMeta{
8189
Annotations: map[string]string{
82-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"dependentResources\":{},\"ready\":false,\"referencedResources\":{}}}",
90+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"flavor\":\"\",\"image\":{}},\"status\":{\"dependentResources\":{},\"ready\":false,\"referencedResources\":{}}}",
8391
},
8492
},
8593
},
@@ -94,7 +102,7 @@ func TestConvertFrom(t *testing.T) {
94102
Spec: OpenStackMachineTemplateSpec{},
95103
ObjectMeta: metav1.ObjectMeta{
96104
Annotations: map[string]string{
97-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}}}}}",
105+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"flavor\":\"\",\"image\":{}}}}}",
98106
},
99107
},
100108
},

api/v1alpha5/zz_generated.conversion.go

Lines changed: 10 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/conversion.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O
529529
out.ServerMetadata = serverMetadata
530530
}
531531

532+
if in.IdentityRef != nil {
533+
out.IdentityRef = &infrav1.OpenStackIdentityReference{Name: in.IdentityRef.Name}
534+
}
535+
if in.CloudName != "" {
536+
if out.IdentityRef == nil {
537+
out.IdentityRef = &infrav1.OpenStackIdentityReference{}
538+
}
539+
out.IdentityRef.CloudName = in.CloudName
540+
}
541+
532542
return nil
533543
}
534544

@@ -624,6 +634,9 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *i
624634
out.AllowAllInClusterTraffic = in.ManagedSecurityGroups.AllowAllInClusterTraffic
625635
}
626636

637+
out.CloudName = in.IdentityRef.CloudName
638+
out.IdentityRef = &OpenStackIdentityReference{Name: in.IdentityRef.Name}
639+
627640
return nil
628641
}
629642

@@ -667,6 +680,11 @@ func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
667680
}
668681
}
669682

683+
out.IdentityRef.CloudName = in.CloudName
684+
if in.IdentityRef != nil {
685+
out.IdentityRef.Name = in.IdentityRef.Name
686+
}
687+
670688
return nil
671689
}
672690

@@ -919,6 +937,11 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *i
919937
out.ServerMetadata = serverMetadata
920938
}
921939

940+
if in.IdentityRef != nil {
941+
out.IdentityRef = &OpenStackIdentityReference{Name: in.IdentityRef.Name}
942+
out.CloudName = in.IdentityRef.CloudName
943+
}
944+
922945
return nil
923946
}
924947

@@ -1015,3 +1038,8 @@ func Convert_v1alpha6_SecurityGroup_To_v1beta1_SecurityGroupStatus(in *SecurityG
10151038
func Convert_v1alpha6_OpenStackIdentityReference_To_v1beta1_OpenStackIdentityReference(in *OpenStackIdentityReference, out *infrav1.OpenStackIdentityReference, s apiconversion.Scope) error {
10161039
return autoConvert_v1alpha6_OpenStackIdentityReference_To_v1beta1_OpenStackIdentityReference(in, out, s)
10171040
}
1041+
1042+
func Convert_v1beta1_OpenStackIdentityReference_To_v1alpha6_OpenStackIdentityReference(in *infrav1.OpenStackIdentityReference, out *OpenStackIdentityReference, _ apiconversion.Scope) error {
1043+
out.Name = in.Name
1044+
return nil
1045+
}

0 commit comments

Comments
 (0)