Skip to content

Commit b58777e

Browse files
authored
Merge pull request kubernetes#92964 from vponomaryov/issue-88752-in-master
agnhost image: use actual DNS domain instead of hardcoded cluster.local
2 parents d9b576d + c55b6cd commit b58777e

File tree

8 files changed

+37
-8
lines changed

8 files changed

+37
-8
lines changed

build/dependencies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dependencies:
22
# agnhost: bump this one first
33
- name: "agnhost"
4-
version: "2.23"
4+
version: "2.24"
55
refPaths:
66
- path: test/images/agnhost/VERSION
77
match: \d.\d

test/images/agnhost/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.23
1+
2.24

test/images/agnhost/agnhost.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import (
5151
func main() {
5252
rootCmd := &cobra.Command{
5353
Use: "app",
54-
Version: "2.23",
54+
Version: "2.24",
5555
}
5656

5757
rootCmd.AddCommand(auditproxy.CmdAuditProxy)

test/images/agnhost/dns/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var CmdEtcHosts = &cobra.Command{
5252
}
5353

5454
func printDNSSuffixList(cmd *cobra.Command, args []string) {
55-
dnsSuffixList := getDNSSuffixList()
55+
dnsSuffixList := GetDNSSuffixList()
5656
fmt.Println(strings.Join(dnsSuffixList, ","))
5757
}
5858

test/images/agnhost/dns/dns.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const etcHostsFile = "/etc/hosts"
2828
// nameserver DNS_CLUSTER_IP
2929
// search test-dns.svc.cluster.local svc.cluster.local cluster.local q53aahaikqaehcai3ylfqdtc5b.bx.internal.cloudapp.net
3030
// options ndots:5
31-
func getDNSSuffixList() []string {
31+
32+
// GetDNSSuffixList reads DNS config file and returns the list of configured DNS suffixes
33+
func GetDNSSuffixList() []string {
3234
fileData := readFile("/etc/resolv.conf")
3335
lines := strings.Split(fileData, "\n")
3436
for _, line := range lines {

test/images/agnhost/dns/dns_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func getRegistryValue(reg, key string) string {
8080
return regValue
8181
}
8282

83-
// getDNSSuffixList reads DNS config file and returns the list of configured DNS suffixes
84-
func getDNSSuffixList() []string {
83+
// GetDNSSuffixList reads DNS config file and returns the list of configured DNS suffixes
84+
func GetDNSSuffixList() []string {
8585
// We start with the general suffix list that apply to all network connections.
8686
allSuffixes := []string{}
8787
suffixes := getRegistryValue(netRegistry, "SearchList")

test/images/agnhost/resource-consumer-controller/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
srcs = ["controller.go"],
1111
importpath = "k8s.io/kubernetes/test/images/agnhost/resource-consumer-controller",
1212
deps = [
13+
"//test/images/agnhost/dns:go_default_library",
1314
"//test/images/resource-consumer/common:go_default_library",
1415
"//vendor/github.com/spf13/cobra:go_default_library",
1516
],

test/images/agnhost/resource-consumer-controller/controller.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import (
2121
"log"
2222
"net/http"
2323
"net/url"
24+
"regexp"
2425
"strconv"
2526
"sync"
2627

2728
"github.com/spf13/cobra"
2829

30+
"k8s.io/kubernetes/test/images/agnhost/dns"
2931
"k8s.io/kubernetes/test/images/resource-consumer/common"
3032
)
3133

@@ -43,8 +45,31 @@ var (
4345
consumerPort int
4446
consumerServiceName string
4547
consumerServiceNamespace string
48+
dnsDomain string
4649
)
4750

51+
// getDNSDomain walks through DNS configuration and looks for "svc.foo" record
52+
// where "foo" is currently configured DNS suffix. Then picks that 'foo' part up
53+
// and returns to a caller.
54+
func getDNSDomain() string {
55+
if dnsDomain != "" {
56+
return dnsDomain
57+
}
58+
dnsSuffixList := dns.GetDNSSuffixList()
59+
r, _ := regexp.Compile("^svc.")
60+
for _, currentDNSSuffix := range dnsSuffixList {
61+
if r.MatchString(currentDNSSuffix) {
62+
// Save DNS suffix without the 'svc.' part
63+
dnsDomain = currentDNSSuffix[4:]
64+
break
65+
}
66+
}
67+
if dnsDomain == "" {
68+
panic("Could not find DNS suffix starting with 'svc.' substring")
69+
}
70+
return dnsDomain
71+
}
72+
4873
func init() {
4974
CmdResourceConsumerController.Flags().IntVar(&port, "port", 8080, "Port number.")
5075
CmdResourceConsumerController.Flags().IntVar(&consumerPort, "consumer-port", 8080, "Port number of consumers.")
@@ -214,7 +239,8 @@ func (c *controller) sendConsumeCustomMetric(w http.ResponseWriter, metric strin
214239
}
215240

216241
func createConsumerURL(suffix string) string {
217-
return fmt.Sprintf("http://%s.%s.svc.cluster.local:%d%s", consumerServiceName, consumerServiceNamespace, consumerPort, suffix)
242+
// NOTE: full DNS name is used due to the Windows platform restriction where PQDNs are not supported.
243+
return fmt.Sprintf("http://%s.%s.svc.%s:%d%s", consumerServiceName, consumerServiceNamespace, getDNSDomain(), consumerPort, suffix)
218244
}
219245

220246
// sendOneConsumeCPURequest sends POST request for cpu consumption

0 commit comments

Comments
 (0)