Skip to content

Improvement for the error log while Subnet Discovery failed #3546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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