@@ -21,11 +21,13 @@ import (
21
21
"log"
22
22
"net/http"
23
23
"net/url"
24
+ "regexp"
24
25
"strconv"
25
26
"sync"
26
27
27
28
"github.com/spf13/cobra"
28
29
30
+ "k8s.io/kubernetes/test/images/agnhost/dns"
29
31
"k8s.io/kubernetes/test/images/resource-consumer/common"
30
32
)
31
33
43
45
consumerPort int
44
46
consumerServiceName string
45
47
consumerServiceNamespace string
48
+ dnsDomain string
46
49
)
47
50
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
+
48
73
func init () {
49
74
CmdResourceConsumerController .Flags ().IntVar (& port , "port" , 8080 , "Port number." )
50
75
CmdResourceConsumerController .Flags ().IntVar (& consumerPort , "consumer-port" , 8080 , "Port number of consumers." )
@@ -214,7 +239,8 @@ func (c *controller) sendConsumeCustomMetric(w http.ResponseWriter, metric strin
214
239
}
215
240
216
241
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 )
218
244
}
219
245
220
246
// sendOneConsumeCPURequest sends POST request for cpu consumption
0 commit comments