
Adds the following subcommands to the agnhost binary: - dns-server-list: outputs the host's DNS server list with which it was configured with. This can be found in /etc/resolv.conf on Linux and through some powershell commands on Windows. - etc-hosts: outputs the host's hosts file. This can be found in /etc/hosts for Linux, and C:/Windows/System32/drivers/etc/hosts for Windows. - pause: pauses the binary's execution. This can be used to keep the Pod in a Running state for various reasons, including executing additional agnhost commands. Refactors bits of the code to avoid duplication. Adds a README for the agnhost image.
56 lines
1.5 KiB
Go
56 lines
1.5 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 (
|
|
"strings"
|
|
)
|
|
|
|
const etcHostsFile = "/etc/hosts"
|
|
|
|
// 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
|
|
func getDNSSuffixList() []string {
|
|
fileData := readFile("/etc/resolv.conf")
|
|
lines := strings.Split(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!")
|
|
}
|
|
|
|
func getDNSServerList() []string {
|
|
fileData := readFile("/etc/resolv.conf")
|
|
lines := strings.Split(fileData, "\n")
|
|
for _, line := range lines {
|
|
if strings.HasPrefix(line, "nameserver") {
|
|
// omit the starting "nameserver".
|
|
return strings.Split(line, " ")[1:]
|
|
}
|
|
}
|
|
|
|
panic("Could not find DNS search list!")
|
|
}
|