@@ -38,10 +38,10 @@ const (
3838 instanceStopping = "STOPPING"
3939)
4040
41- // If Instances.InstanceID or cloudprovider.GetInstanceProviderID is changed, the regexp should be changed too.
42- var providerIDRegexp = regexp .MustCompile (`^` + ProviderName + `://([^/]*)/([^/] +)$` )
41+ // If makeInstanceID is changed, the regexp should be changed too.
42+ var providerIDRegexp = regexp .MustCompile (`^` + ProviderName + `://([^/]+)$` )
4343
44- // TODO: remove old provider after migration
44+ // TODO(migration) : remove old provider support after migration
4545var oldProviderIDRegexp = regexp .MustCompile (`^` + oldProviderName + `://([^/]*)/([^/]+)$` )
4646
4747// Instances encapsulates an implementation of Instances for OpenStack.
@@ -114,7 +114,6 @@ func (i *Instances) InstanceMetadata(ctx context.Context, node *corev1.Node) (*c
114114 })
115115 }
116116
117- // TODO: where to find IPv6SupportDisabled
118117 if ipv6 , ok := nic .GetIpv6Ok (); ok {
119118 addToNodeAddresses (& addresses ,
120119 corev1.NodeAddress {
@@ -150,7 +149,7 @@ func (i *Instances) InstanceMetadata(ctx context.Context, node *corev1.Node) (*c
150149}
151150
152151func (i * Instances ) makeInstanceID (server * iaas.Server ) string {
153- return fmt .Sprintf ("%s:/// %s" , ProviderName , server .GetId ())
152+ return fmt .Sprintf ("%s://%s" , ProviderName , server .GetId ())
154153}
155154
156155// addToNodeAddresses appends the NodeAddresses to the passed-by-pointer slice,
@@ -174,20 +173,31 @@ func addToNodeAddresses(addresses *[]corev1.NodeAddress, addAddresses ...corev1.
174173// A providerID is build out of '${ProviderName}:///${instance-id}' which contains ':///'.
175174// or '${ProviderName}://${region}/${instance-id}' which contains '://'.
176175// See cloudprovider.GetInstanceProviderID and Instances.InstanceID.
176+ // TODO(migration): rework function once openstack:/// is no longer used
177177func instanceIDFromProviderID (providerID string ) (instanceID , region string , err error ) {
178178 // https://github.com/kubernetes/kubernetes/issues/85731
179179 if providerID != "" && ! strings .Contains (providerID , "://" ) {
180180 providerID = ProviderName + "://" + providerID
181181 }
182182
183- matches := providerIDRegexp .FindStringSubmatch (providerID )
184- if len (matches ) != 3 {
185- matches = oldProviderIDRegexp .FindStringSubmatch (providerID )
183+ switch {
184+ // TODO(migration): remove old provider support after migration
185+ case strings .HasPrefix (providerID , "openstack://" ):
186+ matches := oldProviderIDRegexp .FindStringSubmatch (providerID )
186187 if len (matches ) != 3 {
187- return "" , "" , fmt .Errorf ("ProviderID \" %s\" didn't match expected format \" %s://region/InstanceID\" " , ProviderName , providerID )
188+ return "" , "" , fmt .Errorf ("ProviderID \" %s\" didn't match expected format \" %s://region/InstanceID\" " , oldProviderName , providerID )
188189 }
190+ return matches [2 ], matches [1 ], nil
191+ case strings .HasPrefix (providerID , "stackit://" ):
192+ matches := providerIDRegexp .FindStringSubmatch (providerID )
193+ if len (matches ) != 2 {
194+ return "" , "" , fmt .Errorf ("ProviderID \" %s\" didn't match expected format \" %s://InstanceID\" " , ProviderName , providerID )
195+ }
196+ // The new stackit:// doesn't use the old regional providerID anymore and strictly follows the spec
197+ return matches [1 ], "" , nil
198+ default :
199+ return "" , "" , fmt .Errorf ("unknown ProviderName" )
189200 }
190- return matches [2 ], matches [1 ], nil
191201}
192202
193203func getServerByName (ctx context.Context , client stackit.NodeClient , name , projectID , region string ) (* iaas.Server , error ) {
0 commit comments