Files
kubernetes/test/images/agnhost/utils.go
Claudiu Belu 625a9d98a8 tests: Adds agnhost image
The new image is meant to be used for testing purposes, whenever there
are significant differences between Linux and Windows in the way
something is obtained or tested. For example, the DNS suffix list can
be found in ``/etc/resolv.conf`` on Linux, but on Windows, such file
does not exist, and one way to obtain the mentioned list would be
through some powershell commands.

The image contains an extendable CLI as the entrypoint, the tests
only having to add the necessary arguments. For the previous example,
passing the ``dns-suffix`` argument will print out the comma separated
DNS suffix list, on both Linux and Windows.

The image name means that it should behave the same way on any host,
no matter the host OS.
2019-03-30 06:04:56 -07:00

47 lines
1.2 KiB
Go

// +build !windows
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"io/ioutil"
"strings"
)
func getDNSSuffixList() []string {
// A /etc/resolv.conf file managed by kubelet looks like this:
// nameserver DNS_CLUSTER_IP
// search test-dns.svc.cluster.local svc.cluster.local cluster.local q53aahaikqaehcai3ylfqdtc5b.bx.internal.cloudapp.net
// options ndots:5
fileData, err := ioutil.ReadFile("/etc/resolv.conf")
if err != nil {
panic(err)
}
lines := strings.Split(string(fileData), "\n")
for _, line := range lines {
if strings.HasPrefix(line, "search") {
// omit the starting "search".
return strings.Split(line, " ")[1:]
}
}
panic("Could not find DNS search list!")
}