diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index 28a91be97..ceb37260a 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -270,15 +270,15 @@ func (s *ClusterScope) GetIpSubnetRange(Name string) string { return "" } -// GetSecurityGroupRule return slices of securityGroupRule asscociated with securityGroup Name +// GetSecurityGroupRule returns slices of securityGroupRule associated with the given securityGroup Name. +// If no matching securityGroup is found, it returns a pointer to an empty slice. func (s *ClusterScope) GetSecurityGroupRule(Name string) *[]infrastructurev1beta1.OscSecurityGroupRule { - securityGroups := s.OscCluster.Spec.Network.SecurityGroups - for _, securityGroup := range securityGroups { + for _, securityGroup := range s.OscCluster.Spec.Network.SecurityGroups { if securityGroup.Name == Name { return &securityGroup.SecurityGroupRules } } - return nil + return new([]infrastructurev1beta1.OscSecurityGroupRule) // Return pointer to an empty slice } // GetLinkPublicIpRef get the status of linkPublicIpRef (a Map with tag name with bastion uid associate with resource response id) diff --git a/controllers/osccluster_net_controller_unit_test.go b/controllers/osccluster_net_controller_unit_test.go index 9ee120b9a..b6e784791 100644 --- a/controllers/osccluster_net_controller_unit_test.go +++ b/controllers/osccluster_net_controller_unit_test.go @@ -58,8 +58,6 @@ var ( // Setup set osccluster and clusterScope func Setup(t *testing.T, name string, spec infrastructurev1beta1.OscClusterSpec) (clusterScope *scope.ClusterScope) { - t.Logf("Validate to %s", name) - oscCluster := infrastructurev1beta1.OscCluster{ Spec: spec, ObjectMeta: metav1.ObjectMeta{ diff --git a/testenv/osccluster_controller_test.go b/testenv/osccluster_controller_test.go index 5de116424..26e7c9978 100644 --- a/testenv/osccluster_controller_test.go +++ b/testenv/osccluster_controller_test.go @@ -856,11 +856,12 @@ var _ = Describe("Outscale Cluster Reconciler", func() { }, SecurityGroups: []*infrastructurev1beta1.OscSecurityGroup{ { - Name: "cluster-api-securitygroups", - Description: "securitygroup", + Name: "cluster-api-securitygroups", + Description: "Security group for cluster API", + DeleteDefaultOutboundRule: false, // Do not delete the default outbound rule SecurityGroupRules: []infrastructurev1beta1.OscSecurityGroupRule{ { - Name: "cluster-api-securitygrouprule", + Name: "inbound-kube-api", Flow: "Inbound", IpProtocol: "tcp", IpRange: "0.0.0.0/0", @@ -874,6 +875,13 @@ var _ = Describe("Outscale Cluster Reconciler", func() { IpRange: "0.0.0.0/0", FromPortRange: 80, ToPortRange: 80, + TargetSecurityGroupName: "cluster-api-securitygroups", + }, + { + Name: "outbound-all", + Flow: "Outbound", + IpProtocol: "-1", // All protocols + IpRange: "0.0.0.0/0", }, }, }, @@ -1145,4 +1153,4 @@ var _ = Describe("Outscale Cluster Reconciler", func() { createCheckDeleteOscClusterMachine(ctx, infraClusterSpec, infraMachineSpec) }) }) -}) +}) \ No newline at end of file