@@ -22,6 +22,7 @@ import (
22
22
corev1 "k8s.io/api/core/v1"
23
23
conv "k8s.io/apimachinery/pkg/conversion"
24
24
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
25
+ "sigs.k8s.io/cluster-api-provider-cloudstack/controllers"
25
26
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
26
27
"sigs.k8s.io/controller-runtime/pkg/client"
27
28
)
@@ -31,7 +32,7 @@ const DefaultEndpointCredential = "global"
31
32
//nolint:golint,revive,stylecheck
32
33
func Convert_v1beta1_CloudStackCluster_To_v1beta2_CloudStackCluster (in * CloudStackCluster , out * v1beta2.CloudStackCluster , s conv.Scope ) error {
33
34
out .ObjectMeta = in .ObjectMeta
34
- failureDomains , err := getFailureDomains (in )
35
+ failureDomains , err := GetFailureDomains (in )
35
36
if err != nil {
36
37
return err
37
38
}
@@ -80,8 +81,8 @@ func getZones(csCluster *v1beta2.CloudStackCluster) []Zone {
80
81
return zones
81
82
}
82
83
83
- // getFailureDomains maps v1beta1 zones to v1beta2 failure domains.
84
- func getFailureDomains (csCluster * CloudStackCluster ) ([]v1beta2.CloudStackFailureDomainSpec , error ) {
84
+ // GetFailureDomains maps v1beta1 zones to v1beta2 failure domains.
85
+ func GetFailureDomains (csCluster * CloudStackCluster ) ([]v1beta2.CloudStackFailureDomainSpec , error ) {
85
86
var failureDomains []v1beta2.CloudStackFailureDomainSpec
86
87
namespace := csCluster .Namespace
87
88
for _ , zone := range csCluster .Spec .Zones {
@@ -103,7 +104,7 @@ func getFailureDomains(csCluster *CloudStackCluster) ([]v1beta2.CloudStackFailur
103
104
Domain : csCluster .Spec .Domain ,
104
105
Account : csCluster .Spec .Account ,
105
106
ACSEndpoint : corev1.SecretReference {
106
- Namespace : csCluster . Namespace ,
107
+ Namespace : namespace ,
107
108
Name : DefaultEndpointCredential ,
108
109
},
109
110
})
@@ -119,7 +120,7 @@ func getFailureDomains(csCluster *CloudStackCluster) ([]v1beta2.CloudStackFailur
119
120
// When upgrading cluster using clusterctl directly, zoneID is fetched directly from kubernetes cluster in cloudstackzones.
120
121
func GetDefaultFailureDomainName (namespace string , clusterName string , zoneID string , zoneName string ) (string , error ) {
121
122
if len (zoneID ) > 0 {
122
- return zoneID + "-" + clusterName , nil
123
+ return WithZoneID ( zoneID , clusterName ) , nil
123
124
}
124
125
125
126
secret , err := GetK8sSecret (DefaultEndpointCredential , namespace )
@@ -130,14 +131,18 @@ func GetDefaultFailureDomainName(namespace string, clusterName string, zoneID st
130
131
// try fetch zoneID using zoneName through cloudstack client
131
132
zoneID , err = fetchZoneIDUsingCloudStack (secret , zoneName )
132
133
if err == nil {
133
- return zoneID + "-" + clusterName , nil
134
+ return WithZoneID ( zoneID , clusterName ) , nil
134
135
}
135
136
136
137
zoneID , err = fetchZoneIDUsingK8s (namespace , zoneName )
137
138
if err != nil {
138
139
return "" , nil
139
140
}
140
- return zoneID + "-" + clusterName , nil
141
+ return WithZoneID (zoneID , clusterName ), nil
142
+ }
143
+
144
+ func WithZoneID (zoneID , clusterName string ) string {
145
+ return controllers .WithClusterSuffix (zoneID [len (zoneID )- 8 :], clusterName )
141
146
}
142
147
143
148
func fetchZoneIDUsingK8s (namespace string , zoneName string ) (string , error ) {
0 commit comments