Skip to content

Commit 4feff25

Browse files
authored
Merge pull request #3546 from guessi/issue-3545
Improvement for the error log while Subnet Discovery failed
2 parents 41ebb0b + 1709ae0 commit 4feff25

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

pkg/networking/subnet_resolver.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ func (r *defaultSubnetsResolver) ResolveViaSelector(ctx context.Context, selecto
198198
},
199199
},
200200
}
201+
202+
targetTagKeys := []string{}
201203
for key, values := range selector.Tags {
204+
targetTagKeys = append(targetTagKeys, key)
202205
req.Filters = append(req.Filters, &ec2sdk.Filter{
203206
Name: awssdk.String("tag:" + key),
204207
Values: awssdk.StringSlice(values),
@@ -209,7 +212,8 @@ func (r *defaultSubnetsResolver) ResolveViaSelector(ctx context.Context, selecto
209212
if err != nil {
210213
return nil, err
211214
}
212-
explanation = fmt.Sprintf("%d match VPC and tags", len(allSubnets))
215+
explanation = fmt.Sprintf("%d match VPC and tags: %s", len(allSubnets), targetTagKeys)
216+
213217
var subnets []*ec2sdk.Subnet
214218
taggedOtherCluster := 0
215219
for _, subnet := range allSubnets {

pkg/networking/subnet_resolver_test.go

+33-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func Test_defaultSubnetsResolver_ResolveViaDiscovery(t *testing.T) {
203203
},
204204
},
205205
{
206-
name: "ALB with no matching subnets",
206+
name: "ALB with no matching subnets (internal)",
207207
fields: fields{
208208
vpcID: "vpc-1",
209209
clusterName: "kube-cluster",
@@ -231,7 +231,38 @@ func Test_defaultSubnetsResolver_ResolveViaDiscovery(t *testing.T) {
231231
WithSubnetsResolveLBScheme(elbv2model.LoadBalancerSchemeInternal),
232232
},
233233
},
234-
wantErr: errors.New("unable to resolve at least one subnet (0 match VPC and tags)"),
234+
wantErr: errors.New("unable to resolve at least one subnet (0 match VPC and tags: [kubernetes.io/role/internal-elb])"),
235+
},
236+
{
237+
name: "ALB with no matching subnets (internet-facing)",
238+
fields: fields{
239+
vpcID: "vpc-1",
240+
clusterName: "kube-cluster",
241+
describeSubnetsAsListCalls: []describeSubnetsAsListCall{
242+
{
243+
input: &ec2sdk.DescribeSubnetsInput{
244+
Filters: []*ec2sdk.Filter{
245+
{
246+
Name: awssdk.String("vpc-id"),
247+
Values: awssdk.StringSlice([]string{"vpc-1"}),
248+
},
249+
{
250+
Name: awssdk.String("tag:kubernetes.io/role/elb"),
251+
Values: awssdk.StringSlice([]string{"", "1"}),
252+
},
253+
},
254+
},
255+
output: nil,
256+
},
257+
},
258+
},
259+
args: args{
260+
opts: []SubnetsResolveOption{
261+
WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
262+
WithSubnetsResolveLBScheme(elbv2model.LoadBalancerSchemeInternetFacing),
263+
},
264+
},
265+
wantErr: errors.New("unable to resolve at least one subnet (0 match VPC and tags: [kubernetes.io/role/elb])"),
235266
},
236267
{
237268
name: "NLB with one matching subnet",

0 commit comments

Comments
 (0)