Skip to content

Commit f2e8fac

Browse files
committed
- we do not export any constants
- add a GetterMethod for NeutronLBaasSecGroupName
1 parent 6c50ec7 commit f2e8fac

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (s *Service) ReconcileLoadBalancer(clusterName string, openStackCluster *in
178178
}
179179

180180
func (s *Service) assignNeutronLbaasAPISecGroup(clusterName string, lb *loadbalancers.LoadBalancer) error {
181-
neutronLbaasSecGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", networking.SecGroupPrefix, clusterName, networking.NeutronLbaasSuffix)
181+
neutronLbaasSecGroupName := networking.GetNeutronLBaasSecGroupName(clusterName)
182182
listOpts := groups.ListOpts{
183183
Name: neutronLbaasSecGroupName,
184184
}

pkg/cloud/services/networking/securitygroups.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,13 @@ import (
2525
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
2626
)
2727

28-
// export constants for use in loadbalancer-package
29-
const (
30-
SecGroupPrefix string = "k8s"
31-
NeutronLbaasSuffix string = "lbaas"
32-
)
33-
3428
const (
29+
secGroupPrefix string = "k8s"
3530
controlPlaneSuffix string = "controlplane"
3631
workerSuffix string = "worker"
3732
bastionSuffix string = "bastion"
3833
remoteGroupIDSelf string = "self"
34+
neutronLbaasSuffix string = "lbaas"
3935
)
4036

4137
var defaultRules = []infrav1.SecurityGroupRule{
@@ -67,21 +63,21 @@ func (s *Service) ReconcileSecurityGroups(clusterName string, openStackCluster *
6763
return nil
6864
}
6965

70-
secControlPlaneGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", SecGroupPrefix, clusterName, controlPlaneSuffix)
71-
secWorkerGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", SecGroupPrefix, clusterName, workerSuffix)
66+
secControlPlaneGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", secGroupPrefix, clusterName, controlPlaneSuffix)
67+
secWorkerGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", secGroupPrefix, clusterName, workerSuffix)
7268
secGroupNames := map[string]string{
7369
controlPlaneSuffix: secControlPlaneGroupName,
7470
workerSuffix: secWorkerGroupName,
7571
}
7672

7773
if openStackCluster.Spec.Bastion != nil && openStackCluster.Spec.Bastion.Enabled {
78-
secBastionGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", SecGroupPrefix, clusterName, bastionSuffix)
74+
secBastionGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", secGroupPrefix, clusterName, bastionSuffix)
7975
secGroupNames[bastionSuffix] = secBastionGroupName
8076
}
8177

8278
if openStackCluster.Spec.ManagedAPIServerLoadBalancer && !openStackCluster.Spec.UseOctavia {
83-
secLbaasGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", SecGroupPrefix, clusterName, NeutronLbaasSuffix)
84-
secGroupNames[NeutronLbaasSuffix] = secLbaasGroupName
79+
secLbaasGroupName := fmt.Sprintf("%s-cluster-%s-secgroup-%s", secGroupPrefix, clusterName, neutronLbaasSuffix)
80+
secGroupNames[neutronLbaasSuffix] = secLbaasGroupName
8581
}
8682

8783
//create security groups first, because desired rules use group ids.
@@ -370,8 +366,8 @@ func (s *Service) generateDesiredSecGroups(secGroupNames map[string]string, open
370366
)
371367
}
372368
}
373-
desiredSecGroups[NeutronLbaasSuffix] = infrav1.SecurityGroup{
374-
Name: secGroupNames[NeutronLbaasSuffix],
369+
desiredSecGroups[neutronLbaasSuffix] = infrav1.SecurityGroup{
370+
Name: secGroupNames[neutronLbaasSuffix],
375371
Rules: neutronLbaasRules,
376372
}
377373
}
@@ -579,3 +575,8 @@ func convertOSSecGroupRuleToConfigSecGroupRule(osSecGroupRule rules.SecGroupRule
579575
RemoteIPPrefix: osSecGroupRule.RemoteIPPrefix,
580576
}
581577
}
578+
579+
// GetNeutronLBaasSecGroupName export NeutronLBaasSecGroupName
580+
func GetNeutronLBaasSecGroupName(clusterName string) string {
581+
return fmt.Sprintf("%s-cluster-%s-secgroup-%s", secGroupPrefix, clusterName, neutronLbaasSuffix)
582+
}

0 commit comments

Comments
 (0)