@@ -34,9 +34,9 @@ import (
3434 "github.com/aws/aws-sdk-go/service/ec2"
3535 "github.com/aws/aws-sdk-go/service/elb"
3636 "github.com/aws/aws-sdk-go/service/elbv2"
37+ v1 "k8s.io/api/core/v1"
3738 "k8s.io/klog/v2"
3839
39- "k8s.io/api/core/v1"
4040 "k8s.io/apimachinery/pkg/types"
4141 "k8s.io/apimachinery/pkg/util/sets"
4242)
@@ -840,8 +840,12 @@ func (c *Cloud) updateInstanceSecurityGroupsForNLB(lbName string, instances map[
840840 for sgID , sg := range clusterSGs {
841841 sgPerms := NewIPPermissionSet (sg .IpPermissions ... ).Ungroup ()
842842 if desiredSGIDs .Has (sgID ) {
843- if err := c .updateInstanceSecurityGroupForNLBTraffic (sgID , sgPerms , healthRuleAnnotation , "tcp" , healthCheckPorts , subnetCIDRs ); err != nil {
844- return err
843+ // If the client rule is 1) all addresses 2) tcp and 3) has same ports as the healthcheck,
844+ // then the health rules are a subset of the client rule and are not needed.
845+ if len (clientCIDRs ) != 1 || clientCIDRs [0 ] != "0.0.0.0/0" || clientProtocol != "tcp" || ! healthCheckPorts .Equal (clientPorts ) {
846+ if err := c .updateInstanceSecurityGroupForNLBTraffic (sgID , sgPerms , healthRuleAnnotation , "tcp" , healthCheckPorts , subnetCIDRs ); err != nil {
847+ return err
848+ }
845849 }
846850 if err := c .updateInstanceSecurityGroupForNLBTraffic (sgID , sgPerms , clientRuleAnnotation , clientProtocol , clientPorts , clientCIDRs ); err != nil {
847851 return err
0 commit comments