Skip to content

Commit b0ec7ee

Browse files
author
Carlos Flores
committed
use 'service' prefix for var name
1 parent 1f6503d commit b0ec7ee

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func main() {
108108
tgbResManager := targetgroupbinding.NewDefaultResourceManager(mgr.GetClient(), cloud.ELBV2(), cloud.EC2(),
109109
podInfoRepo, sgManager, sgReconciler, vpcInfoProvider,
110110
cloud.VpcID(), controllerCFG.ClusterName, controllerCFG.FeatureGates.Enabled(config.EndpointsFailOpen), controllerCFG.EnableEndpointSlices, controllerCFG.DisableRestrictedSGRules,
111-
controllerCFG.EndpointENISGTags, mgr.GetEventRecorderFor("targetGroupBinding"), ctrl.Log)
111+
controllerCFG.ServiceTargetENISGTags, mgr.GetEventRecorderFor("targetGroupBinding"), ctrl.Log)
112112
backendSGProvider := networking.NewBackendSGProvider(controllerCFG.ClusterName, controllerCFG.BackendSecurityGroup,
113113
cloud.VpcID(), cloud.EC2(), mgr.GetClient(), controllerCFG.DefaultTags, ctrl.Log.WithName("backend-sg-provider"))
114114
sgResolver := networking.NewDefaultSecurityGroupResolver(cloud.EC2(), cloud.VpcID())

pkg/config/controller_config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
flagDefaultTags = "default-tags"
1919
flagDefaultTargetType = "default-target-type"
2020
flagExternalManagedTags = "external-managed-tags"
21-
flagEndpointENISGTags = "endpoint-eni-security-group-tags"
21+
flagServiceTargetENISGTags = "service-target-eni-security-group-tags"
2222
flagServiceMaxConcurrentReconciles = "service-max-concurrent-reconciles"
2323
flagTargetGroupBindingMaxConcurrentReconciles = "targetgroupbinding-max-concurrent-reconciles"
2424
flagTargetGroupBindingMaxExponentialBackoffDelay = "targetgroupbinding-max-exponential-backoff-delay"
@@ -75,8 +75,8 @@ type ControllerConfig struct {
7575
// List of Tag keys on AWS resources that will be managed externally.
7676
ExternalManagedTags []string
7777

78-
// EndpointENISGTags are AWS tags, in addition to the cluster tags, for finding the target ENI security group to which to add inbound rules from NLBs.
79-
EndpointENISGTags map[string]string
78+
// ServiceTargetENISGTags are AWS tags, in addition to the cluster tags, for finding the target ENI security group to which to add inbound rules from NLBs.
79+
ServiceTargetENISGTags map[string]string
8080

8181
// Default SSL Policy that will be applied to all ingresses or services that do not have
8282
// the SSL Policy annotation.
@@ -132,7 +132,7 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
132132
"Enable EndpointSlices for IP targets instead of Endpoints")
133133
fs.BoolVar(&cfg.DisableRestrictedSGRules, flagDisableRestrictedSGRules, defaultDisableRestrictedSGRules,
134134
"Disable the usage of restricted security group rules")
135-
fs.StringToStringVar(&cfg.EndpointENISGTags, flagEndpointENISGTags, nil,
135+
fs.StringToStringVar(&cfg.ServiceTargetENISGTags, flagServiceTargetENISGTags, nil,
136136
"AWS Tags, in addition to cluster tags, for finding the target ENI security group to which to add inbound rules from NLBs")
137137
cfg.FeatureGates.BindFlags(fs)
138138
cfg.AWSConfig.BindFlags(fs)

pkg/targetgroupbinding/networking_manager.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ type NetworkingManager interface {
4545

4646
// NewDefaultNetworkingManager constructs defaultNetworkingManager.
4747
func NewDefaultNetworkingManager(k8sClient client.Client, podENIResolver networking.PodENIInfoResolver, nodeENIResolver networking.NodeENIInfoResolver,
48-
sgManager networking.SecurityGroupManager, sgReconciler networking.SecurityGroupReconciler, vpcID string, clusterName string, endpointENISGTags map[string]string, logger logr.Logger, disabledRestrictedSGRulesFlag bool) *defaultNetworkingManager {
48+
sgManager networking.SecurityGroupManager, sgReconciler networking.SecurityGroupReconciler, vpcID string, clusterName string, serviceTargetENISGTags map[string]string, logger logr.Logger, disabledRestrictedSGRulesFlag bool) *defaultNetworkingManager {
4949

5050
return &defaultNetworkingManager{
51-
k8sClient: k8sClient,
52-
podENIResolver: podENIResolver,
53-
nodeENIResolver: nodeENIResolver,
54-
sgManager: sgManager,
55-
sgReconciler: sgReconciler,
56-
vpcID: vpcID,
57-
clusterName: clusterName,
58-
endpointENISGTags: endpointENISGTags,
59-
logger: logger,
51+
k8sClient: k8sClient,
52+
podENIResolver: podENIResolver,
53+
nodeENIResolver: nodeENIResolver,
54+
sgManager: sgManager,
55+
sgReconciler: sgReconciler,
56+
vpcID: vpcID,
57+
clusterName: clusterName,
58+
serviceTargetENISGTags: serviceTargetENISGTags,
59+
logger: logger,
6060

6161
mutex: sync.Mutex{},
6262
ingressPermissionsPerSGByTGB: make(map[types.NamespacedName]map[string][]networking.IPPermissionInfo),
@@ -68,15 +68,15 @@ func NewDefaultNetworkingManager(k8sClient client.Client, podENIResolver network
6868

6969
// default implementation for NetworkingManager.
7070
type defaultNetworkingManager struct {
71-
k8sClient client.Client
72-
podENIResolver networking.PodENIInfoResolver
73-
nodeENIResolver networking.NodeENIInfoResolver
74-
sgManager networking.SecurityGroupManager
75-
sgReconciler networking.SecurityGroupReconciler
76-
vpcID string
77-
clusterName string
78-
endpointENISGTags map[string]string
79-
logger logr.Logger
71+
k8sClient client.Client
72+
podENIResolver networking.PodENIInfoResolver
73+
nodeENIResolver networking.NodeENIInfoResolver
74+
sgManager networking.SecurityGroupManager
75+
sgReconciler networking.SecurityGroupReconciler
76+
vpcID string
77+
clusterName string
78+
serviceTargetENISGTags map[string]string
79+
logger logr.Logger
8080

8181
// mutex will serialize our TargetGroup's networking reconcile requests.
8282
mutex sync.Mutex
@@ -524,7 +524,7 @@ func (m *defaultNetworkingManager) resolveEndpointSGForENI(ctx context.Context,
524524
for sgID, sgInfo := range sgInfoByID {
525525
if _, ok := sgInfo.Tags[clusterResourceTagKey]; ok {
526526
matchesEndpointSGTags := true
527-
for endpointSGTagKey, endpointSGTagValue := range m.endpointENISGTags {
527+
for endpointSGTagKey, endpointSGTagValue := range m.serviceTargetENISGTags {
528528
if _, ok := sgInfo.Tags[endpointSGTagKey]; !ok || sgInfo.Tags[endpointSGTagKey] != endpointSGTagValue {
529529
matchesEndpointSGTags = false
530530
break
@@ -539,12 +539,12 @@ func (m *defaultNetworkingManager) resolveEndpointSGForENI(ctx context.Context,
539539
if len(sgIDsWithMatchingEndpointSGTags) != 1 {
540540
// 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.
541541
// having `clusterName` included in error message might be helpful for shorten the troubleshooting time spent.
542-
if len(m.endpointENISGTags) == 0 {
542+
if len(m.serviceTargetENISGTags) == 0 {
543543
return "", errors.Errorf("expect exactly one securityGroup tagged with %v for eni %v, got: %v (clusterName: %v)",
544544
clusterResourceTagKey, eniInfo.NetworkInterfaceID, sgIDsWithMatchingEndpointSGTags.List(), m.clusterName)
545545
}
546546
return "", errors.Errorf("expect exactly one securityGroup tagged with %v and %v for eni %v, got: %v (clusterName: %v)",
547-
clusterResourceTagKey, m.endpointENISGTags, eniInfo.NetworkInterfaceID, sgIDsWithMatchingEndpointSGTags.List(), m.clusterName)
547+
clusterResourceTagKey, m.serviceTargetENISGTags, eniInfo.NetworkInterfaceID, sgIDsWithMatchingEndpointSGTags.List(), m.clusterName)
548548
}
549549
sgID, _ := sgIDsWithMatchingEndpointSGTags.PopAny()
550550
return sgID, nil

pkg/targetgroupbinding/networking_manager_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14241424

14251425
type fields struct {
14261426
fetchSGInfosByRequestCalls []fetchSGInfosByIDCall
1427-
endpointENISGTags map[string]string
1427+
serviceTargetENISGTags map[string]string
14281428
}
14291429
type args struct {
14301430
ctx context.Context
@@ -1440,7 +1440,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14401440
{
14411441
name: "Only one security group in eniInfo returns early",
14421442
fields: fields{
1443-
endpointENISGTags: map[string]string{},
1443+
serviceTargetENISGTags: map[string]string{},
14441444
},
14451445
args: args{
14461446
ctx: context.Background(),
@@ -1455,7 +1455,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14551455
{
14561456
name: "No security group in eniInfo returns error",
14571457
fields: fields{
1458-
endpointENISGTags: map[string]string{},
1458+
serviceTargetENISGTags: map[string]string{},
14591459
fetchSGInfosByRequestCalls: []fetchSGInfosByIDCall{
14601460
{
14611461
req: []string{},
@@ -1476,7 +1476,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14761476
{
14771477
name: "A single security group with cluster name tag and no service target tags set",
14781478
fields: fields{
1479-
endpointENISGTags: map[string]string{},
1479+
serviceTargetENISGTags: map[string]string{},
14801480
fetchSGInfosByRequestCalls: []fetchSGInfosByIDCall{
14811481
{
14821482
req: []string{"sg-a", "sg-b"},
@@ -1513,7 +1513,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
15131513
{
15141514
name: "A single security group with cluster name tag and one service target tag set",
15151515
fields: fields{
1516-
endpointENISGTags: map[string]string{
1516+
serviceTargetENISGTags: map[string]string{
15171517
"keyA": "valueA",
15181518
},
15191519
fetchSGInfosByRequestCalls: []fetchSGInfosByIDCall{
@@ -1553,7 +1553,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
15531553
{
15541554
name: "A single security group with cluster name tag and one service target tag set with no matches",
15551555
fields: fields{
1556-
endpointENISGTags: map[string]string{
1556+
serviceTargetENISGTags: map[string]string{
15571557
"keyA": "valueNotA",
15581558
},
15591559
fetchSGInfosByRequestCalls: []fetchSGInfosByIDCall{
@@ -1593,7 +1593,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
15931593
{
15941594
name: "A single security group with cluster name tag and multiple service target tags set",
15951595
fields: fields{
1596-
endpointENISGTags: map[string]string{
1596+
serviceTargetENISGTags: map[string]string{
15971597
"keyA": "valueA",
15981598
"keyB": "valueB2",
15991599
},
@@ -1634,7 +1634,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
16341634
{
16351635
name: "A single security group with cluster name tag and multiple service target tags set with no matches",
16361636
fields: fields{
1637-
endpointENISGTags: map[string]string{
1637+
serviceTargetENISGTags: map[string]string{
16381638
"keyA": "valueA",
16391639
"keyB": "valueNotB2",
16401640
},
@@ -1675,7 +1675,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
16751675
{
16761676
name: "A single security group with cluster name tag and a service target tags with an empty value",
16771677
fields: fields{
1678-
endpointENISGTags: map[string]string{
1678+
serviceTargetENISGTags: map[string]string{
16791679
"keyA": "",
16801680
},
16811681
fetchSGInfosByRequestCalls: []fetchSGInfosByIDCall{
@@ -1715,7 +1715,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
17151715
{
17161716
name: "A single security group with cluster name tag and a service target tags with an empty value with no matches",
17171717
fields: fields{
1718-
endpointENISGTags: map[string]string{
1718+
serviceTargetENISGTags: map[string]string{
17191719
"keyE": "",
17201720
},
17211721
fetchSGInfosByRequestCalls: []fetchSGInfosByIDCall{
@@ -1764,9 +1764,9 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
17641764

17651765
t.Run(tt.name, func(t *testing.T) {
17661766
m := &defaultNetworkingManager{
1767-
sgManager: sgManager,
1768-
clusterName: "cluster-a",
1769-
endpointENISGTags: tt.fields.endpointENISGTags,
1767+
sgManager: sgManager,
1768+
clusterName: "cluster-a",
1769+
serviceTargetENISGTags: tt.fields.serviceTargetENISGTags,
17701770
}
17711771
got, err := m.resolveEndpointSGForENI(tt.args.ctx, tt.args.eniInfo)
17721772
if (err != nil) != tt.wantErr {

0 commit comments

Comments
 (0)