@@ -45,7 +45,7 @@ type NetworkingManager interface {
45
45
46
46
// NewDefaultNetworkingManager constructs defaultNetworkingManager.
47
47
func NewDefaultNetworkingManager (k8sClient client.Client , podENIResolver networking.PodENIInfoResolver , nodeENIResolver networking.NodeENIInfoResolver ,
48
- sgManager networking.SecurityGroupManager , sgReconciler networking.SecurityGroupReconciler , vpcID string , clusterName string , logger logr.Logger , disabledRestrictedSGRulesFlag bool ) * defaultNetworkingManager {
48
+ sgManager networking.SecurityGroupManager , sgReconciler networking.SecurityGroupReconciler , vpcID string , clusterName string , endpointSGTags map [ string ] string , logger logr.Logger , disabledRestrictedSGRulesFlag bool ) * defaultNetworkingManager {
49
49
50
50
return & defaultNetworkingManager {
51
51
k8sClient : k8sClient ,
@@ -55,6 +55,7 @@ func NewDefaultNetworkingManager(k8sClient client.Client, podENIResolver network
55
55
sgReconciler : sgReconciler ,
56
56
vpcID : vpcID ,
57
57
clusterName : clusterName ,
58
+ endpointSGTags : endpointSGTags ,
58
59
logger : logger ,
59
60
60
61
mutex : sync.Mutex {},
@@ -74,6 +75,7 @@ type defaultNetworkingManager struct {
74
75
sgReconciler networking.SecurityGroupReconciler
75
76
vpcID string
76
77
clusterName string
78
+ endpointSGTags map [string ]string
77
79
logger logr.Logger
78
80
79
81
// mutex will serialize our TargetGroup's networking reconcile requests.
@@ -518,19 +520,36 @@ func (m *defaultNetworkingManager) resolveEndpointSGForENI(ctx context.Context,
518
520
return "" , err
519
521
}
520
522
clusterResourceTagKey := fmt .Sprintf ("kubernetes.io/cluster/%s" , m .clusterName )
521
- sgIDsWithClusterTag := sets .NewString ()
523
+ sgIDsWithMatchingEndpointSGTags := sets .NewString ()
522
524
for sgID , sgInfo := range sgInfoByID {
525
+ isMatch := true
523
526
if _ , ok := sgInfo .Tags [clusterResourceTagKey ]; ok {
524
- sgIDsWithClusterTag .Insert (sgID )
527
+ for endpointSGTagKey , endpointSGTagValue := range m .endpointSGTags {
528
+ if sgInfo .Tags [endpointSGTagKey ] != endpointSGTagValue {
529
+ isMatch = false
530
+ break
531
+ }
532
+ }
533
+ } else {
534
+ continue
535
+ }
536
+
537
+ if isMatch {
538
+ sgIDsWithMatchingEndpointSGTags .Insert (sgID )
525
539
}
526
540
}
527
- if len (sgIDsWithClusterTag ) != 1 {
541
+
542
+ if len (sgIDsWithMatchingEndpointSGTags ) != 1 {
528
543
// user may provide incorrect `--cluster-name` at bootstrap or modify the tag key unexpectedly, it is hard to find out if no clusterName included in error message.
529
544
// having `clusterName` included in error message might be helpful for shorten the troubleshooting time spent.
530
- return "" , errors .Errorf ("expect exactly one securityGroup tagged with %v for eni %v, got: %v (clusterName: %v)" ,
531
- clusterResourceTagKey , eniInfo .NetworkInterfaceID , sgIDsWithClusterTag .List (), m .clusterName )
545
+ if len (m .endpointSGTags ) == 0 {
546
+ return "" , errors .Errorf ("expect exactly one securityGroup tagged with %v for eni %v, got: %v (clusterName: %v)" ,
547
+ clusterResourceTagKey , eniInfo .NetworkInterfaceID , sgIDsWithMatchingEndpointSGTags .List (), m .clusterName )
548
+ }
549
+ return "" , errors .Errorf ("expect exactly one securityGroup tagged with %v and %v for eni %v, got: %v (clusterName: %v)" ,
550
+ clusterResourceTagKey , m .endpointSGTags , eniInfo .NetworkInterfaceID , sgIDsWithMatchingEndpointSGTags .List (), m .clusterName )
532
551
}
533
- sgID , _ := sgIDsWithClusterTag .PopAny ()
552
+ sgID , _ := sgIDsWithMatchingEndpointSGTags .PopAny ()
534
553
return sgID , nil
535
554
}
536
555
0 commit comments