Skip to content

Commit

Permalink
Merge pull request #3546 from guessi/issue-3545
Browse files Browse the repository at this point in the history
 Improvement for the error log while Subnet Discovery failed
  • Loading branch information
k8s-ci-robot authored Jan 31, 2024
2 parents 41ebb0b + 1709ae0 commit 4feff25
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/networking/subnet_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ func (r *defaultSubnetsResolver) ResolveViaSelector(ctx context.Context, selecto
},
},
}

targetTagKeys := []string{}
for key, values := range selector.Tags {
targetTagKeys = append(targetTagKeys, key)
req.Filters = append(req.Filters, &ec2sdk.Filter{
Name: awssdk.String("tag:" + key),
Values: awssdk.StringSlice(values),
Expand All @@ -209,7 +212,8 @@ func (r *defaultSubnetsResolver) ResolveViaSelector(ctx context.Context, selecto
if err != nil {
return nil, err
}
explanation = fmt.Sprintf("%d match VPC and tags", len(allSubnets))
explanation = fmt.Sprintf("%d match VPC and tags: %s", len(allSubnets), targetTagKeys)

var subnets []*ec2sdk.Subnet
taggedOtherCluster := 0
for _, subnet := range allSubnets {
Expand Down
35 changes: 33 additions & 2 deletions pkg/networking/subnet_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func Test_defaultSubnetsResolver_ResolveViaDiscovery(t *testing.T) {
},
},
{
name: "ALB with no matching subnets",
name: "ALB with no matching subnets (internal)",
fields: fields{
vpcID: "vpc-1",
clusterName: "kube-cluster",
Expand Down Expand Up @@ -231,7 +231,38 @@ func Test_defaultSubnetsResolver_ResolveViaDiscovery(t *testing.T) {
WithSubnetsResolveLBScheme(elbv2model.LoadBalancerSchemeInternal),
},
},
wantErr: errors.New("unable to resolve at least one subnet (0 match VPC and tags)"),
wantErr: errors.New("unable to resolve at least one subnet (0 match VPC and tags: [kubernetes.io/role/internal-elb])"),
},
{
name: "ALB with no matching subnets (internet-facing)",
fields: fields{
vpcID: "vpc-1",
clusterName: "kube-cluster",
describeSubnetsAsListCalls: []describeSubnetsAsListCall{
{
input: &ec2sdk.DescribeSubnetsInput{
Filters: []*ec2sdk.Filter{
{
Name: awssdk.String("vpc-id"),
Values: awssdk.StringSlice([]string{"vpc-1"}),
},
{
Name: awssdk.String("tag:kubernetes.io/role/elb"),
Values: awssdk.StringSlice([]string{"", "1"}),
},
},
},
output: nil,
},
},
},
args: args{
opts: []SubnetsResolveOption{
WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
WithSubnetsResolveLBScheme(elbv2model.LoadBalancerSchemeInternetFacing),
},
},
wantErr: errors.New("unable to resolve at least one subnet (0 match VPC and tags: [kubernetes.io/role/elb])"),
},
{
name: "NLB with one matching subnet",
Expand Down

0 comments on commit 4feff25

Please sign in to comment.