diff --git a/test/images/BUILD b/test/images/BUILD index d0a5e79af1..ece39e914d 100644 --- a/test/images/BUILD +++ b/test/images/BUILD @@ -11,6 +11,7 @@ filegroup( name = "all-srcs", srcs = [ ":package-srcs", + "//test/images/agnhost:all-srcs", "//test/images/apparmor-loader:all-srcs", "//test/images/audit-proxy:all-srcs", "//test/images/crd-conversion-webhook:all-srcs", diff --git a/test/images/agnhost/BUILD b/test/images/agnhost/BUILD new file mode 100644 index 0000000000..c578d81c42 --- /dev/null +++ b/test/images/agnhost/BUILD @@ -0,0 +1,39 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_binary", + "go_library", +) + +go_binary( + name = "agnhost", + embed = [":go_default_library"], +) + +go_library( + name = "go_default_library", + srcs = [ + "agnhost.go", + "common.go", + "utils.go", + "utils_windows.go", + ], + importpath = "k8s.io/kubernetes/test/images/agnhost", + deps = [ + "//vendor/github.com/spf13/cobra:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/test/images/agnhost/Dockerfile b/test/images/agnhost/Dockerfile new file mode 100644 index 0000000000..faee07a694 --- /dev/null +++ b/test/images/agnhost/Dockerfile @@ -0,0 +1,18 @@ +# 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. + +FROM scratch + +ADD agnhost agnhost +ENTRYPOINT ["/agnhost"] diff --git a/test/images/agnhost/Makefile b/test/images/agnhost/Makefile new file mode 100644 index 0000000000..c21639c38c --- /dev/null +++ b/test/images/agnhost/Makefile @@ -0,0 +1,25 @@ +# 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. + +SRCS=agnhost +ARCH ?= amd64 +TARGET ?= $(CURDIR) +GOLANG_VERSION ?= latest +SRC_DIR = $(notdir $(shell pwd)) +export + +bin: + ../image-util.sh bin $(SRCS) + +.PHONY: bin diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION new file mode 100644 index 0000000000..d3827e75a5 --- /dev/null +++ b/test/images/agnhost/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/test/images/agnhost/agnhost.go b/test/images/agnhost/agnhost.go new file mode 100644 index 0000000000..8b75955cbf --- /dev/null +++ b/test/images/agnhost/agnhost.go @@ -0,0 +1,35 @@ +/* +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 ( + "github.com/spf13/cobra" +) + +func main() { + cmdDNSSuffix := &cobra.Command{ + Use: "dns-suffix", + Short: "Prints the host's DNS suffix list.", + Long: `prints the DNS suffixes of this host.`, + Args: cobra.MaximumNArgs(0), + Run: printDNSSuffixList, + } + + rootCmd := &cobra.Command{Use: "app"} + rootCmd.AddCommand(cmdDNSSuffix) + rootCmd.Execute() +} diff --git a/test/images/agnhost/common.go b/test/images/agnhost/common.go new file mode 100644 index 0000000000..e0df5e7a01 --- /dev/null +++ b/test/images/agnhost/common.go @@ -0,0 +1,29 @@ +/* +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 ( + "fmt" + "strings" + + "github.com/spf13/cobra" +) + +func printDNSSuffixList(cmd *cobra.Command, args []string) { + dnsSuffixList := getDNSSuffixList() + fmt.Println(strings.Join(dnsSuffixList, ",")) +} diff --git a/test/images/agnhost/utils.go b/test/images/agnhost/utils.go new file mode 100644 index 0000000000..950903e249 --- /dev/null +++ b/test/images/agnhost/utils.go @@ -0,0 +1,46 @@ +// +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!") +} diff --git a/test/images/agnhost/utils_windows.go b/test/images/agnhost/utils_windows.go new file mode 100644 index 0000000000..2199ac048b --- /dev/null +++ b/test/images/agnhost/utils_windows.go @@ -0,0 +1,41 @@ +/* +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 ( + "bytes" + "os/exec" + "strings" +) + +func getDNSSuffixList() []string { + var out bytes.Buffer + cmd := exec.Command("powershell", "-Command", "(Get-DnsClient)[0].SuffixSearchList") + cmd.Stdout = &out + + err := cmd.Run() + if err != nil { + panic(err) + } + + output := strings.TrimSpace(out.String()) + if len(output) > 0 { + return strings.Split(output, "\r\n") + } + + panic("Could not find DNS search list!") +} diff --git a/test/utils/image/manifest.go b/test/utils/image/manifest.go index 2f9e3b40b1..d2437dadb0 100644 --- a/test/utils/image/manifest.go +++ b/test/utils/image/manifest.go @@ -101,6 +101,8 @@ const ( CRDConversionWebhook = iota // AdmissionWebhook image AdmissionWebhook + // Agnhost image + Agnhost // APIServer image APIServer // AppArmorLoader image @@ -196,6 +198,7 @@ func initImageConfigs() map[int]Config { configs := map[int]Config{} configs[CRDConversionWebhook] = Config{e2eRegistry, "crd-conversion-webhook", "1.13rev2"} configs[AdmissionWebhook] = Config{e2eRegistry, "webhook", "1.14v1"} + configs[Agnhost] = Config{e2eRegistry, "agnhost", "1.0"} configs[APIServer] = Config{e2eRegistry, "sample-apiserver", "1.10"} configs[AppArmorLoader] = Config{e2eRegistry, "apparmor-loader", "1.0"} configs[AuditProxy] = Config{e2eRegistry, "audit-proxy", "1.0"}