@@ -25,15 +25,17 @@ import (
25
25
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
26
26
)
27
27
28
- // Exported Constants can be used to calculate securitygroupnames in other packages
28
+ // export constants for use in loadbalancer-package
29
29
const (
30
- secGroupPrefix string = "k8s"
31
- ControlPlaneSuffix string = "controlplane"
32
- WorkerSuffix string = "worker"
33
- BastionSuffix string = "bastion"
34
- NeutronLbaasSuffix string = "lbaas"
35
- remoteGroupIDSelf string = "self"
36
- securityGroupNameFormatString string = "%s-cluster-%s-secgroup-%s"
30
+ SecGroupPrefix string = "k8s"
31
+ NeutronLbaasSuffix string = "lbaas"
32
+ )
33
+
34
+ const (
35
+ controlPlaneSuffix string = "controlplane"
36
+ workerSuffix string = "worker"
37
+ bastionSuffix string = "bastion"
38
+ remoteGroupIDSelf string = "self"
37
39
)
38
40
39
41
var defaultRules = []infrav1.SecurityGroupRule {
@@ -65,20 +67,20 @@ func (s *Service) ReconcileSecurityGroups(clusterName string, openStackCluster *
65
67
return nil
66
68
}
67
69
68
- secControlPlaneGroupName := GetSecurityGroupName ( clusterName , ControlPlaneSuffix )
69
- secWorkerGroupName := GetSecurityGroupName ( clusterName , WorkerSuffix )
70
+ secControlPlaneGroupName := fmt . Sprintf ( "%s-cluster-%s-secgroup-%s" , SecGroupPrefix , clusterName , controlPlaneSuffix )
71
+ secWorkerGroupName := fmt . Sprintf ( "%s-cluster-%s-secgroup-%s" , SecGroupPrefix , clusterName , workerSuffix )
70
72
secGroupNames := map [string ]string {
71
- ControlPlaneSuffix : secControlPlaneGroupName ,
72
- WorkerSuffix : secWorkerGroupName ,
73
+ controlPlaneSuffix : secControlPlaneGroupName ,
74
+ workerSuffix : secWorkerGroupName ,
73
75
}
74
76
75
77
if openStackCluster .Spec .Bastion != nil && openStackCluster .Spec .Bastion .Enabled {
76
- secBastionGroupName := GetSecurityGroupName ( clusterName , BastionSuffix )
77
- secGroupNames [BastionSuffix ] = secBastionGroupName
78
+ secBastionGroupName := fmt . Sprintf ( "%s-cluster-%s-secgroup-%s" , SecGroupPrefix , clusterName , bastionSuffix )
79
+ secGroupNames [bastionSuffix ] = secBastionGroupName
78
80
}
79
81
80
82
if openStackCluster .Spec .ManagedAPIServerLoadBalancer && ! openStackCluster .Spec .UseOctavia {
81
- secLbaasGroupName := GetSecurityGroupName ( clusterName , NeutronLbaasSuffix )
83
+ secLbaasGroupName := fmt . Sprintf ( "%s-cluster-%s-secgroup-%s" , SecGroupPrefix , clusterName , NeutronLbaasSuffix )
82
84
secGroupNames [NeutronLbaasSuffix ] = secLbaasGroupName
83
85
}
84
86
@@ -120,9 +122,9 @@ func (s *Service) ReconcileSecurityGroups(clusterName string, openStackCluster *
120
122
}
121
123
}
122
124
123
- openStackCluster .Status .ControlPlaneSecurityGroup = observedSecGroups [ControlPlaneSuffix ]
124
- openStackCluster .Status .WorkerSecurityGroup = observedSecGroups [WorkerSuffix ]
125
- openStackCluster .Status .BastionSecurityGroup = observedSecGroups [BastionSuffix ]
125
+ openStackCluster .Status .ControlPlaneSecurityGroup = observedSecGroups [controlPlaneSuffix ]
126
+ openStackCluster .Status .WorkerSecurityGroup = observedSecGroups [workerSuffix ]
127
+ openStackCluster .Status .BastionSecurityGroup = observedSecGroups [bastionSuffix ]
126
128
127
129
return nil
128
130
}
@@ -139,11 +141,11 @@ func (s *Service) generateDesiredSecGroups(secGroupNames map[string]string, open
139
141
return desiredSecGroups , err
140
142
}
141
143
switch i {
142
- case ControlPlaneSuffix :
144
+ case controlPlaneSuffix :
143
145
secControlPlaneGroupID = secGroup .ID
144
- case WorkerSuffix :
146
+ case workerSuffix :
145
147
secWorkerGroupID = secGroup .ID
146
- case BastionSuffix :
148
+ case bastionSuffix :
147
149
secBastionGroupID = secGroup .ID
148
150
}
149
151
}
@@ -317,8 +319,8 @@ func (s *Service) generateDesiredSecGroups(secGroupNames map[string]string, open
317
319
},
318
320
}... ,
319
321
)
320
- desiredSecGroups [BastionSuffix ] = infrav1.SecurityGroup {
321
- Name : secGroupNames [BastionSuffix ],
322
+ desiredSecGroups [bastionSuffix ] = infrav1.SecurityGroup {
323
+ Name : secGroupNames [bastionSuffix ],
322
324
Rules : append (
323
325
[]infrav1.SecurityGroupRule {
324
326
{
@@ -374,13 +376,13 @@ func (s *Service) generateDesiredSecGroups(secGroupNames map[string]string, open
374
376
}
375
377
}
376
378
377
- desiredSecGroups [ControlPlaneSuffix ] = infrav1.SecurityGroup {
378
- Name : secGroupNames [ControlPlaneSuffix ],
379
+ desiredSecGroups [controlPlaneSuffix ] = infrav1.SecurityGroup {
380
+ Name : secGroupNames [controlPlaneSuffix ],
379
381
Rules : controlPlaneRules ,
380
382
}
381
383
382
- desiredSecGroups [WorkerSuffix ] = infrav1.SecurityGroup {
383
- Name : secGroupNames [WorkerSuffix ],
384
+ desiredSecGroups [workerSuffix ] = infrav1.SecurityGroup {
385
+ Name : secGroupNames [workerSuffix ],
384
386
Rules : workerRules ,
385
387
}
386
388
@@ -577,8 +579,3 @@ func convertOSSecGroupRuleToConfigSecGroupRule(osSecGroupRule rules.SecGroupRule
577
579
RemoteIPPrefix : osSecGroupRule .RemoteIPPrefix ,
578
580
}
579
581
}
580
-
581
- // GetSecurityGroupName Calculate name of securitygroup
582
- func GetSecurityGroupName (clusterName string , suffix string ) string {
583
- return fmt .Sprintf (securityGroupNameFormatString , secGroupPrefix , clusterName , suffix )
584
- }
0 commit comments