@@ -660,10 +660,15 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
660
660
rulesToApply := customIngressRules .Difference (kubeletRules )
661
661
return append (kubeletRules , rulesToApply ... ), nil
662
662
case infrav1 .SecurityGroupLB :
663
+ rules := infrav1.IngressRules {}
664
+ allowedNLBTraffic := false
663
665
// We hand this group off to the in-cluster cloud provider, so these rules aren't used
664
666
// Except if the load balancer type is NLB, and we have an AWS Cluster in which case we
665
667
// need to open port 6443 to the NLB traffic and health check inside the VPC.
666
- if s .scope .ControlPlaneLoadBalancer () != nil && s .scope .ControlPlaneLoadBalancer ().LoadBalancerType == infrav1 .LoadBalancerTypeNLB {
668
+ for _ , lb := range s .scope .ControlPlaneLoadBalancers () {
669
+ if lb == nil || lb .LoadBalancerType != infrav1 .LoadBalancerTypeNLB {
670
+ continue
671
+ }
667
672
var (
668
673
ipv4CidrBlocks []string
669
674
ipv6CidrBlocks []string
@@ -673,25 +678,26 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
673
678
if s .scope .VPC ().IsIPv6Enabled () {
674
679
ipv6CidrBlocks = []string {s .scope .VPC ().IPv6 .CidrBlock }
675
680
}
676
- if s . scope . ControlPlaneLoadBalancer () .PreserveClientIP {
681
+ if lb .PreserveClientIP {
677
682
ipv4CidrBlocks = []string {services .AnyIPv4CidrBlock }
678
683
if s .scope .VPC ().IsIPv6Enabled () {
679
684
ipv6CidrBlocks = []string {services .AnyIPv6CidrBlock }
680
685
}
681
686
}
682
687
683
- rules := infrav1. IngressRules {
684
- {
688
+ if ! allowedNLBTraffic {
689
+ rules = append ( rules , infrav1. IngressRule {
685
690
Description : "Allow NLB traffic to the control plane instances." ,
686
691
Protocol : infrav1 .SecurityGroupProtocolTCP ,
687
692
FromPort : int64 (s .scope .APIServerPort ()),
688
693
ToPort : int64 (s .scope .APIServerPort ()),
689
694
CidrBlocks : ipv4CidrBlocks ,
690
695
IPv6CidrBlocks : ipv6CidrBlocks ,
691
- },
696
+ })
697
+ allowedNLBTraffic = true
692
698
}
693
699
694
- for _ , ln := range s . scope . ControlPlaneLoadBalancer () .AdditionalListeners {
700
+ for _ , ln := range lb .AdditionalListeners {
695
701
rules = append (rules , infrav1.IngressRule {
696
702
Description : fmt .Sprintf ("Allow NLB traffic to the control plane instances on port %d." , ln .Port ),
697
703
Protocol : infrav1 .SecurityGroupProtocolTCP ,
@@ -701,10 +707,8 @@ func (s *Service) getSecurityGroupIngressRules(role infrav1.SecurityGroupRole) (
701
707
IPv6CidrBlocks : ipv6CidrBlocks ,
702
708
})
703
709
}
704
-
705
- return rules , nil
706
710
}
707
- return infrav1. IngressRules {} , nil
711
+ return rules , nil
708
712
}
709
713
710
714
return nil , errors .Errorf ("Cannot determine ingress rules for unknown security group role %q" , role )
@@ -915,8 +919,14 @@ func (s *Service) getIngressRulesToAllowKubeletToAccessTheControlPlaneLB() infra
915
919
// getControlPlaneLBIngressRules returns the ingress rules for the control plane LB.
916
920
// We allow all traffic when no other rules are defined.
917
921
func (s * Service ) getControlPlaneLBIngressRules () infrav1.IngressRules {
918
- if s .scope .ControlPlaneLoadBalancer () != nil && len (s .scope .ControlPlaneLoadBalancer ().IngressRules ) > 0 {
919
- return s .scope .ControlPlaneLoadBalancer ().IngressRules
922
+ ingressRules := infrav1.IngressRules {}
923
+ for _ , lb := range s .scope .ControlPlaneLoadBalancers () {
924
+ if lb != nil && len (lb .IngressRules ) > 0 {
925
+ ingressRules = append (ingressRules , lb .IngressRules ... )
926
+ }
927
+ }
928
+ if len (ingressRules ) > 0 {
929
+ return ingressRules
920
930
}
921
931
922
932
// If no custom ingress rules have been defined we allow all traffic so that the MC can access the WC API
0 commit comments