mirror of https://github.com/k3s-io/k3s
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.k3s-v1.15.3
parent
5716127cff
commit
625a9d98a8
|
@ -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",
|
||||
|
|
|
@ -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"],
|
||||
)
|
|
@ -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"]
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
1.0
|
|
@ -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()
|
||||
}
|
|
@ -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, ","))
|
||||
}
|
|
@ -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!")
|
||||
}
|
|
@ -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!")
|
||||
}
|
|
@ -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"}
|
||||
|
|
Loading…
Reference in New Issue