From 6167fd8a5ebf6f62094264f618cb384aba15bf46 Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Tue, 19 Nov 2024 17:47:24 +1300 Subject: [PATCH] fix(collector): fix dns collector limited to 63 chars (#1690) --- pkg/collect/host_network.go | 4 ++-- pkg/collect/host_network_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/collect/host_network.go b/pkg/collect/host_network.go index 32c367093..41f8988b7 100644 --- a/pkg/collect/host_network.go +++ b/pkg/collect/host_network.go @@ -65,8 +65,8 @@ func isValidLoadBalancerAddress(address string) bool { } - errs := validation.IsQualifiedName(hostAddress) - + // Checking for DNS name for RFC1123, DNS1123SubdomainMaxLength int = 253 + errs := validation.IsDNS1123Subdomain(hostAddress) return len(errs) == 0 } diff --git a/pkg/collect/host_network_test.go b/pkg/collect/host_network_test.go index d9e2ea32d..e65a8be5a 100644 --- a/pkg/collect/host_network_test.go +++ b/pkg/collect/host_network_test.go @@ -44,8 +44,13 @@ func Test_isValidLoadBalancerAddress(t *testing.T) { want: false, }, { - name: "Too many characters", + name: "Valid long DNS domain but less than 255 characters, RFC1123 compliant", args: args{address: "howlongcanwemakethiswithoutrunningoutofwordsbecasueweneedtohitatleast64.com:80"}, + want: true, + }, + { + name: "Non-valid long DNS domain but more than 255 characters, RFC1123 not compliant", + args: args{address: "howlongcanwemakethiswithouthowlongcanwemakethiswithouthowlongcanwemakethiswithoutrunningoutofwordsbecasueweneedtohitatleast64howlongcanwemakethiswithouthowlongcanwemakethiswithouthowlongcanwemakethiswithoutrunningoutofwordsbecasueweneedtohitatleast64dssdfasdffs.com:80"}, want: false, }, {