From c55b6cdbb4281b4931a963fb4f512f97c8c13b96 Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Fri, 10 Jul 2020 13:37:38 +0300 Subject: [PATCH] agnhost image: use actual DNS domain instead of hardcoded cluster.local 'agnhost' image uses hardcoded 'cluster.local' value for DNS domain. It leads to failure of a bunch of HPA tests when test cluster is configured to use custom DNS domain and there is no alias for default 'cluster.local' one. So, fix it by reusing it's own function for reading DNS domain suffixes. Signed-off-by: Valerii Ponomarov --- build/dependencies.yaml | 2 +- test/images/agnhost/VERSION | 2 +- test/images/agnhost/agnhost.go | 2 +- test/images/agnhost/dns/common.go | 2 +- test/images/agnhost/dns/dns.go | 4 ++- test/images/agnhost/dns/dns_windows.go | 4 +-- .../resource-consumer-controller/BUILD | 1 + .../controller.go | 28 ++++++++++++++++++- 8 files changed, 37 insertions(+), 8 deletions(-) diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 9b1daa22ffa..72c97c5e65c 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -1,7 +1,7 @@ dependencies: # agnhost: bump this one first - name: "agnhost" - version: "2.23" + version: "2.24" refPaths: - path: test/images/agnhost/VERSION match: \d.\d diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index aac433c1a6b..fd6915cc46b 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.23 +2.24 diff --git a/test/images/agnhost/agnhost.go b/test/images/agnhost/agnhost.go index a2a718f1c59..3eacfebe11d 100644 --- a/test/images/agnhost/agnhost.go +++ b/test/images/agnhost/agnhost.go @@ -51,7 +51,7 @@ import ( func main() { rootCmd := &cobra.Command{ Use: "app", - Version: "2.23", + Version: "2.24", } rootCmd.AddCommand(auditproxy.CmdAuditProxy) diff --git a/test/images/agnhost/dns/common.go b/test/images/agnhost/dns/common.go index 92452abec67..cf2861e7b7f 100644 --- a/test/images/agnhost/dns/common.go +++ b/test/images/agnhost/dns/common.go @@ -52,7 +52,7 @@ var CmdEtcHosts = &cobra.Command{ } func printDNSSuffixList(cmd *cobra.Command, args []string) { - dnsSuffixList := getDNSSuffixList() + dnsSuffixList := GetDNSSuffixList() fmt.Println(strings.Join(dnsSuffixList, ",")) } diff --git a/test/images/agnhost/dns/dns.go b/test/images/agnhost/dns/dns.go index 6908dbfa0c9..ae525f20d5d 100644 --- a/test/images/agnhost/dns/dns.go +++ b/test/images/agnhost/dns/dns.go @@ -28,7 +28,9 @@ const etcHostsFile = "/etc/hosts" // nameserver DNS_CLUSTER_IP // search test-dns.svc.cluster.local svc.cluster.local cluster.local q53aahaikqaehcai3ylfqdtc5b.bx.internal.cloudapp.net // options ndots:5 -func getDNSSuffixList() []string { + +// GetDNSSuffixList reads DNS config file and returns the list of configured DNS suffixes +func GetDNSSuffixList() []string { fileData := readFile("/etc/resolv.conf") lines := strings.Split(fileData, "\n") for _, line := range lines { diff --git a/test/images/agnhost/dns/dns_windows.go b/test/images/agnhost/dns/dns_windows.go index bd408c99ccb..46206a90bf6 100644 --- a/test/images/agnhost/dns/dns_windows.go +++ b/test/images/agnhost/dns/dns_windows.go @@ -80,8 +80,8 @@ func getRegistryValue(reg, key string) string { return regValue } -// getDNSSuffixList reads DNS config file and returns the list of configured DNS suffixes -func getDNSSuffixList() []string { +// GetDNSSuffixList reads DNS config file and returns the list of configured DNS suffixes +func GetDNSSuffixList() []string { // We start with the general suffix list that apply to all network connections. allSuffixes := []string{} suffixes := getRegistryValue(netRegistry, "SearchList") diff --git a/test/images/agnhost/resource-consumer-controller/BUILD b/test/images/agnhost/resource-consumer-controller/BUILD index a87e0488e7b..71a590d97c3 100644 --- a/test/images/agnhost/resource-consumer-controller/BUILD +++ b/test/images/agnhost/resource-consumer-controller/BUILD @@ -10,6 +10,7 @@ go_library( srcs = ["controller.go"], importpath = "k8s.io/kubernetes/test/images/agnhost/resource-consumer-controller", deps = [ + "//test/images/agnhost/dns:go_default_library", "//test/images/resource-consumer/common:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library", ], diff --git a/test/images/agnhost/resource-consumer-controller/controller.go b/test/images/agnhost/resource-consumer-controller/controller.go index 20b6a52ce58..b79dd999e49 100644 --- a/test/images/agnhost/resource-consumer-controller/controller.go +++ b/test/images/agnhost/resource-consumer-controller/controller.go @@ -21,11 +21,13 @@ import ( "log" "net/http" "net/url" + "regexp" "strconv" "sync" "github.com/spf13/cobra" + "k8s.io/kubernetes/test/images/agnhost/dns" "k8s.io/kubernetes/test/images/resource-consumer/common" ) @@ -43,8 +45,31 @@ var ( consumerPort int consumerServiceName string consumerServiceNamespace string + dnsDomain string ) +// getDNSDomain walks through DNS configuration and looks for "svc.foo" record +// where "foo" is currently configured DNS suffix. Then picks that 'foo' part up +// and returns to a caller. +func getDNSDomain() string { + if dnsDomain != "" { + return dnsDomain + } + dnsSuffixList := dns.GetDNSSuffixList() + r, _ := regexp.Compile("^svc.") + for _, currentDNSSuffix := range dnsSuffixList { + if r.MatchString(currentDNSSuffix) { + // Save DNS suffix without the 'svc.' part + dnsDomain = currentDNSSuffix[4:] + break + } + } + if dnsDomain == "" { + panic("Could not find DNS suffix starting with 'svc.' substring") + } + return dnsDomain +} + func init() { CmdResourceConsumerController.Flags().IntVar(&port, "port", 8080, "Port number.") CmdResourceConsumerController.Flags().IntVar(&consumerPort, "consumer-port", 8080, "Port number of consumers.") @@ -214,7 +239,8 @@ func (c *controller) sendConsumeCustomMetric(w http.ResponseWriter, metric strin } func createConsumerURL(suffix string) string { - return fmt.Sprintf("http://%s.%s.svc.cluster.local:%d%s", consumerServiceName, consumerServiceNamespace, consumerPort, suffix) + // NOTE: full DNS name is used due to the Windows platform restriction where PQDNs are not supported. + return fmt.Sprintf("http://%s.%s.svc.%s:%d%s", consumerServiceName, consumerServiceNamespace, getDNSDomain(), consumerPort, suffix) } // sendOneConsumeCPURequest sends POST request for cpu consumption