@@ -679,6 +679,108 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
679
679
})
680
680
})
681
681
682
+ Describe ("Workload cluster providerID identityRef.Region field per OpenStackMachineTemplate override OpenStackCluster identityRef.Region field" , func () {
683
+ It ("should create machines with identityRef.Region field which override CLuster one" , func (ctx context.Context ) {
684
+ shared .Logf ("Creating a cluster" )
685
+ clusterName := fmt .Sprintf ("cluster-%s" , namespace .Name )
686
+ configCluster := defaultConfigCluster (clusterName , namespace .Name )
687
+ configCluster .ControlPlaneMachineCount = ptr .To (int64 (1 ))
688
+ configCluster .WorkerMachineCount = ptr .To (int64 (0 ))
689
+ configCluster .Flavor = shared .FlavorProviderIDWithRegionOverride
690
+ createCluster (ctx , configCluster , clusterResources )
691
+ md := clusterResources .MachineDeployments
692
+
693
+ workerMachines := framework .GetMachinesByMachineDeployments (ctx , framework.GetMachinesByMachineDeploymentsInput {
694
+ Lister : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
695
+ ClusterName : clusterName ,
696
+ Namespace : namespace .Name ,
697
+ MachineDeployment : * md [0 ],
698
+ })
699
+ controlPlaneMachines := framework .GetControlPlaneMachinesByCluster (ctx , framework.GetControlPlaneMachinesByClusterInput {
700
+ Lister : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
701
+ ClusterName : clusterName ,
702
+ Namespace : namespace .Name ,
703
+ })
704
+ Expect (workerMachines ).To (HaveLen (0 ))
705
+ Expect (controlPlaneMachines ).To (HaveLen (1 ))
706
+
707
+ shared .Logf ("Creating MachineDeployment with identityRef Region field defined" )
708
+ testSecurityGroupName := "testSecGroup"
709
+ // create required test security group
710
+ var securityGroupCleanup func (ctx context.Context )
711
+ securityGroupCleanup , err = shared .CreateOpenStackSecurityGroup (ctx , e2eCtx , testSecurityGroupName , "Test security group" )
712
+ Expect (err ).To (BeNil ())
713
+ postClusterCleanup = append (postClusterCleanup , securityGroupCleanup )
714
+
715
+ _ , clientOpts , _ , err := shared .GetTenantProviderClient (e2eCtx )
716
+ Expect (err ).To (BeNil (), "Cannot create providerClient" )
717
+
718
+ controlPlaneMachine := controlPlaneMachines [0 ]
719
+
720
+ shared .Logf ("Fetching serverID control plane" )
721
+ allControlPlaneServers , err := shared .DumpOpenStackServers (e2eCtx , servers.ListOpts {Name : controlPlaneMachine .Name })
722
+ Expect (err ).To (BeNil ())
723
+ Expect (allControlPlaneServers ).To (HaveLen (1 ))
724
+ controlPlaneServerID := allControlPlaneServers [0 ].ID
725
+ Expect (err ).To (BeNil ())
726
+
727
+ Expect (* (controlPlaneMachine .Spec .ProviderID )).To (
728
+ Equal (fmt .Sprintf ("openstack://%s/%s" , clientOpts .RegionName , controlPlaneServerID )),
729
+ fmt .Sprintf ("ControlPlane machine should have providerID string `openstack://%s/uuid`" , clientOpts .RegionName ))
730
+ })
731
+ })
732
+
733
+ Describe ("Workload cluster providerID identityRef.Region field herited from OpenStackCluster identityRef.Region field" , func () {
734
+ It ("should create machines without identityRef.Region field and herit from Cluster object" , func (ctx context.Context ) {
735
+ shared .Logf ("Creating a cluster" )
736
+ clusterName := fmt .Sprintf ("cluster-%s" , namespace .Name )
737
+ configCluster := defaultConfigCluster (clusterName , namespace .Name )
738
+ configCluster .ControlPlaneMachineCount = ptr .To (int64 (1 ))
739
+ configCluster .WorkerMachineCount = ptr .To (int64 (0 ))
740
+ configCluster .Flavor = shared .FlavorProviderIDWithRegionDefault
741
+ createCluster (ctx , configCluster , clusterResources )
742
+ md := clusterResources .MachineDeployments
743
+
744
+ workerMachines := framework .GetMachinesByMachineDeployments (ctx , framework.GetMachinesByMachineDeploymentsInput {
745
+ Lister : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
746
+ ClusterName : clusterName ,
747
+ Namespace : namespace .Name ,
748
+ MachineDeployment : * md [0 ],
749
+ })
750
+ controlPlaneMachines := framework .GetControlPlaneMachinesByCluster (ctx , framework.GetControlPlaneMachinesByClusterInput {
751
+ Lister : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
752
+ ClusterName : clusterName ,
753
+ Namespace : namespace .Name ,
754
+ })
755
+ Expect (workerMachines ).To (HaveLen (0 ))
756
+ Expect (controlPlaneMachines ).To (HaveLen (1 ))
757
+
758
+ shared .Logf ("Creating MachineDeployment with identityRef Region field defined" )
759
+ testSecurityGroupName := "testSecGroup"
760
+ // create required test security group
761
+ var securityGroupCleanup func (ctx context.Context )
762
+ securityGroupCleanup , err = shared .CreateOpenStackSecurityGroup (ctx , e2eCtx , testSecurityGroupName , "Test security group" )
763
+ Expect (err ).To (BeNil ())
764
+ postClusterCleanup = append (postClusterCleanup , securityGroupCleanup )
765
+
766
+ _ , clientOpts , _ , err := shared .GetTenantProviderClient (e2eCtx )
767
+ Expect (err ).To (BeNil (), "Cannot create providerClient" )
768
+
769
+ controlPlaneMachine := controlPlaneMachines [0 ]
770
+
771
+ shared .Logf ("Fetching serverID control plane" )
772
+ allControlPlaneServers , err := shared .DumpOpenStackServers (e2eCtx , servers.ListOpts {Name : controlPlaneMachine .Name })
773
+ Expect (err ).To (BeNil ())
774
+ Expect (allControlPlaneServers ).To (HaveLen (1 ))
775
+ controlPlaneServerID := allControlPlaneServers [0 ].ID
776
+ Expect (err ).To (BeNil ())
777
+
778
+ Expect (* (controlPlaneMachine .Spec .ProviderID )).To (
779
+ Equal (fmt .Sprintf ("openstack://%s/%s" , clientOpts .RegionName , controlPlaneServerID )),
780
+ fmt .Sprintf ("ControlPlane machine should have providerID string `openstack://%s/uuid`" , clientOpts .RegionName ))
781
+ })
782
+ })
783
+
682
784
Describe ("Workload cluster (multiple attached networks)" , func () {
683
785
var (
684
786
clusterName string
@@ -815,7 +917,7 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
815
917
Creator : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
816
918
MachineDeployment : makeMachineDeployment (namespace .Name , mdInvalidAZName , clusterName , "invalid-az" , 1 ),
817
919
BootstrapConfigTemplate : makeJoinBootstrapConfigTemplate (namespace .Name , mdInvalidAZName ),
818
- InfraMachineTemplate : makeOpenStackMachineTemplate (namespace .Name , clusterName , mdInvalidAZName ),
920
+ InfraMachineTemplate : makeOpenStackMachineTemplate (namespace .Name , clusterName , mdInvalidAZName , "" ),
819
921
})
820
922
821
923
shared .Logf ("Looking for failure event to be reported" )
@@ -1035,9 +1137,11 @@ func getInstanceIDForMachine(machine *clusterv1.Machine) string {
1035
1137
providerID := machine .Spec .ProviderID
1036
1138
Expect (providerID ).NotTo (BeNil ())
1037
1139
1038
- providerIDSplit := strings .SplitN (* providerID , ":/// " , 2 )
1140
+ providerIDSplit := strings .SplitN (* providerID , "://" , 2 )
1039
1141
Expect (providerIDSplit [0 ]).To (Equal ("openstack" ))
1040
- return providerIDSplit [1 ]
1142
+ providerIDPathSplit := strings .SplitN (providerIDSplit [1 ], "/" , 2 )
1143
+ // providerIDPathSplit[0] contain region name, could be empty
1144
+ return providerIDPathSplit [1 ]
1041
1145
}
1042
1146
1043
1147
func isErrorEventExists (namespace , machineDeploymentName , eventReason , errorMsg string , eList * corev1.EventList ) bool {
@@ -1072,7 +1176,7 @@ func isErrorEventExists(namespace, machineDeploymentName, eventReason, errorMsg
1072
1176
return len (openStackMachineList .Items ) == eventMachinesCnt
1073
1177
}
1074
1178
1075
- func makeOpenStackMachineTemplate (namespace , clusterName , name string ) * infrav1.OpenStackMachineTemplate {
1179
+ func makeOpenStackMachineTemplate (namespace , clusterName , name , regionName string ) * infrav1.OpenStackMachineTemplate {
1076
1180
return & infrav1.OpenStackMachineTemplate {
1077
1181
ObjectMeta : metav1.ObjectMeta {
1078
1182
Name : name ,
@@ -1091,14 +1195,15 @@ func makeOpenStackMachineTemplate(namespace, clusterName, name string) *infrav1.
1091
1195
IdentityRef : & infrav1.OpenStackIdentityReference {
1092
1196
Name : fmt .Sprintf ("%s-cloud-config" , clusterName ),
1093
1197
CloudName : e2eCtx .E2EConfig .GetVariable (shared .OpenStackCloud ),
1198
+ Region : regionName ,
1094
1199
},
1095
1200
},
1096
1201
},
1097
1202
},
1098
1203
}
1099
1204
}
1100
1205
1101
- func makeOpenStackMachineTemplateWithPortOptions (namespace , clusterName , name string , portOpts * []infrav1.PortOpts , machineTags []string ) * infrav1.OpenStackMachineTemplate {
1206
+ func makeOpenStackMachineTemplateWithPortOptions (namespace , clusterName , name , regionName string , portOpts * []infrav1.PortOpts , machineTags []string ) * infrav1.OpenStackMachineTemplate {
1102
1207
return & infrav1.OpenStackMachineTemplate {
1103
1208
ObjectMeta : metav1.ObjectMeta {
1104
1209
Name : name ,
@@ -1117,6 +1222,7 @@ func makeOpenStackMachineTemplateWithPortOptions(namespace, clusterName, name st
1117
1222
IdentityRef : & infrav1.OpenStackIdentityReference {
1118
1223
Name : fmt .Sprintf ("%s-cloud-config" , clusterName ),
1119
1224
CloudName : e2eCtx .E2EConfig .GetVariable (shared .OpenStackCloud ),
1225
+ Region : regionName ,
1120
1226
},
1121
1227
Ports : * portOpts ,
1122
1228
Tags : machineTags ,
0 commit comments