Skip to content

Commit 4de9b6e

Browse files
author
Matt Pryor
committed
Support for additional controlplane and worker secgroup rules
1 parent 880a5f6 commit 4de9b6e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

api/v1beta1/openstackcluster_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,22 @@ type ManagedSecurityGroups struct {
320320
// +optional
321321
AllNodesSecurityGroupRules []SecurityGroupRuleSpec `json:"allNodesSecurityGroupRules,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
322322

323+
// controlPlaneNodesSecurityGroupRules defines the rules that should be applied to control plane nodes.
324+
// +patchMergeKey=name
325+
// +patchStrategy=merge
326+
// +listType=map
327+
// +listMapKey=name
328+
// +optional
329+
ControlPlaneNodesSecurityGroupRules []SecurityGroupRuleSpec `json:"controlPlaneNodesSecurityGroupRules,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
330+
331+
// workerNodesSecurityGroupRules defines the rules that should be applied to worker nodes.
332+
// +patchMergeKey=name
333+
// +patchStrategy=merge
334+
// +listType=map
335+
// +listMapKey=name
336+
// +optional
337+
WorkerNodesSecurityGroupRules []SecurityGroupRuleSpec `json:"workerNodesSecurityGroupRules,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
338+
323339
// AllowAllInClusterTraffic allows all ingress and egress traffic between cluster nodes when set to true.
324340
// +kubebuilder:default=false
325341
// +kubebuilder:validation:Required

pkg/cloud/services/networking/securitygroups.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,21 @@ func (s *Service) generateDesiredSecGroups(openStackCluster *infrav1.OpenStackCl
229229
workerRules = append(workerRules, getSGWorkerGeneral(remoteGroupIDSelf, secControlPlaneGroupID)...)
230230
}
231231

232+
// Append any additional rules for control plane and worker nodes
233+
controlPlaneExtraRules, err := getRulesFromSpecs(remoteManagedGroups, openStackCluster.Spec.ManagedSecurityGroups.ControlPlaneNodesSecurityGroupRules)
234+
if err != nil {
235+
return nil, err
236+
}
237+
controlPlaneRules = append(controlPlaneRules, controlPlaneExtraRules...)
238+
workersExtraRules, err := getRulesFromSpecs(remoteManagedGroups, openStackCluster.Spec.ManagedSecurityGroups.WorkerNodesSecurityGroupRules)
239+
if err != nil {
240+
return nil, err
241+
}
242+
workerRules = append(workerRules, workersExtraRules...)
243+
232244
// For now, we do not create a separate security group for allNodes.
233245
// Instead, we append the rules for allNodes to the control plane and worker security groups.
234-
allNodesRules, err := getAllNodesRules(remoteManagedGroups, openStackCluster.Spec.ManagedSecurityGroups.AllNodesSecurityGroupRules)
246+
allNodesRules, err := getRulesFromSpecs(remoteManagedGroups, openStackCluster.Spec.ManagedSecurityGroups.AllNodesSecurityGroupRules)
235247
if err != nil {
236248
return nil, err
237249
}
@@ -275,9 +287,9 @@ func (s *Service) generateDesiredSecGroups(openStackCluster *infrav1.OpenStackCl
275287
}
276288

277289
// getAllNodesRules returns the rules for the allNodes security group that should be created.
278-
func getAllNodesRules(remoteManagedGroups map[string]string, allNodesSecurityGroupRules []infrav1.SecurityGroupRuleSpec) ([]resolvedSecurityGroupRuleSpec, error) {
279-
rules := make([]resolvedSecurityGroupRuleSpec, 0, len(allNodesSecurityGroupRules))
280-
for _, rule := range allNodesSecurityGroupRules {
290+
func getRulesFromSpecs(remoteManagedGroups map[string]string, securityGroupRules []infrav1.SecurityGroupRuleSpec) ([]resolvedSecurityGroupRuleSpec, error) {
291+
rules := make([]resolvedSecurityGroupRuleSpec, 0, len(securityGroupRules))
292+
for _, rule := range securityGroupRules {
281293
if err := validateRemoteManagedGroups(remoteManagedGroups, rule.RemoteManagedGroups); err != nil {
282294
return nil, err
283295
}

0 commit comments

Comments
 (0)