44 "context"
55 "fmt"
66
7+ "k8s.io/apimachinery/pkg/types"
78 goClient "sigs.k8s.io/controller-runtime/pkg/client"
89)
910
@@ -14,18 +15,20 @@ func GetExistingProvServerPorts(
1415 instance * OpenStackProvisionServer ,
1516) (map [string ]int32 , error ) {
1617 found := map [string ]int32 {}
17-
1818 provServerList := & OpenStackProvisionServerList {}
1919
2020 listOpts := []goClient.ListOption {}
2121
2222 err := c .List (ctx , provServerList , listOpts ... )
2323 if err != nil {
24- return nil , fmt .Errorf ("Failed to get list of all OpenStackProvisionServer(s): %s" , err .Error ())
24+ return nil , fmt .Errorf ("failed to get list of all OpenStackProvisionServer(s): %s" , err .Error ())
2525 }
2626
2727 for _ , provServer := range provServerList .Items {
28- found [fmt .Sprintf ("%s-%s" , provServer .Name , provServer .Namespace )] = provServer .Spec .Port
28+ namespacedName := types.NamespacedName {
29+ Namespace : provServer .Namespace ,
30+ Name : provServer .Name }
31+ found [namespacedName .String ()] = provServer .Spec .Port
2932 }
3033
3134 return found , nil
@@ -44,10 +47,12 @@ func AssignProvisionServerPort(
4447 return err
4548 }
4649
50+ namespacedName := types.NamespacedName {
51+ Namespace : instance .Namespace ,
52+ Name : instance .Name }
4753 // It's possible that this prov server already exists and we are just dealing with
4854 // a minimized version of it (only its ObjectMeta is set, etc)
49- instanceKey := fmt .Sprintf ("%s-%s" , instance .GetName (), instance .GetNamespace ())
50- cur := existingPorts [instanceKey ]
55+ cur := existingPorts [namespacedName .String ()]
5156 if cur == 0 {
5257 cur = portStart
5358 }
@@ -65,7 +70,7 @@ func AssignProvisionServerPort(
6570 }
6671
6772 if found {
68- if existingPorts [instanceKey ] != cur {
73+ if existingPorts [namespacedName . String () ] != cur {
6974 // continue to use the next port in the port range.
7075 continue
7176 } else {
0 commit comments