mirror of https://github.com/k3s-io/k3s
Make (Docker) RunOnNode a method
Signed-off-by: Derek Nola <derek.nola@suse.com>pull/11673/head
parent
669c11a686
commit
7392806b7f
|
@ -59,9 +59,9 @@ var _ = Describe("Basic Tests", Ordered, func() {
|
|||
Context("Verify Binaries and Images", func() {
|
||||
It("has valid bundled binaries", func() {
|
||||
for _, server := range config.Servers {
|
||||
Expect(tester.VerifyValidVersion(server.Name, "kubectl")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server.Name, "ctr")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server.Name, "crictl")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server, "kubectl")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server, "ctr")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server, "crictl")).To(Succeed())
|
||||
}
|
||||
})
|
||||
It("has valid airgap images", func() {
|
||||
|
|
|
@ -37,7 +37,7 @@ var _ = Describe("Boostrap Token Tests", Ordered, func() {
|
|||
var newSecret string
|
||||
It("creates a bootstrap token", func() {
|
||||
var err error
|
||||
newSecret, err = tester.RunCmdOnDocker(config.Servers[0].Name, "k3s token create --ttl=5m --description=Test")
|
||||
newSecret, err = config.Servers[0].RunCmdOnNode("k3s token create --ttl=5m --description=Test")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(newSecret).NotTo(BeEmpty())
|
||||
})
|
||||
|
|
|
@ -84,7 +84,7 @@ func lookLayers(node, layer string) error {
|
|||
layersNum := 0
|
||||
var err error
|
||||
for layersNum = 0; layersNum < 100; layersNum++ {
|
||||
// We use RunCommand instead of RunCmdOnDocker because we pipe the output to jq
|
||||
// We use RunCommand instead of RunCmdOnNode because we pipe the output to jq
|
||||
cmd := fmt.Sprintf("docker exec -i %s ctr --namespace=k8s.io snapshot --snapshotter=stargz info %s | jq -r '.Parent'", node, layer)
|
||||
layer, err = tester.RunCommand(cmd)
|
||||
if err != nil {
|
||||
|
|
|
@ -72,7 +72,7 @@ var _ = Describe("Skew Tests", Ordered, func() {
|
|||
})
|
||||
It("should match respective versions", func() {
|
||||
for _, server := range config.Servers {
|
||||
out, err := tester.RunCmdOnDocker(server.Name, "k3s --version")
|
||||
out, err := server.RunCmdOnNode("k3s --version")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
// The k3s image is in the format rancher/k3s:v1.20.0-k3s1
|
||||
cVersion := strings.Split(*k3sImage, ":")[1]
|
||||
|
@ -81,7 +81,7 @@ var _ = Describe("Skew Tests", Ordered, func() {
|
|||
Expect(out).To(ContainSubstring(cVersion))
|
||||
}
|
||||
for _, agent := range config.Agents {
|
||||
Expect(tester.RunCmdOnDocker(agent.Name, "k3s --version")).
|
||||
Expect(agent.RunCmdOnNode("k3s --version")).
|
||||
To(ContainSubstring(strings.Replace(lastMinorVersion, "-", "+", 1)))
|
||||
}
|
||||
})
|
||||
|
@ -120,11 +120,11 @@ var _ = Describe("Skew Tests", Ordered, func() {
|
|||
}, "60s", "5s").Should(Succeed())
|
||||
})
|
||||
It("should match respective versions", func() {
|
||||
out, err := tester.RunCmdOnDocker(config.Servers[0].Name, "k3s --version")
|
||||
out, err := config.Servers[0].RunCmdOnNode("k3s --version")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(out).To(ContainSubstring(strings.Replace(lastMinorVersion, "-", "+", 1)))
|
||||
for _, server := range config.Servers[1:] {
|
||||
out, err := tester.RunCmdOnDocker(server.Name, "k3s --version")
|
||||
out, err := server.RunCmdOnNode("k3s --version")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
// The k3s image is in the format rancher/k3s:v1.20.0-k3s1-amd64
|
||||
cVersion := strings.Split(*k3sImage, ":")[1]
|
||||
|
|
|
@ -32,21 +32,20 @@ type TestConfig struct {
|
|||
NumAgents int
|
||||
NeedRestart bool
|
||||
Servers []Server
|
||||
Agents []Agent
|
||||
Agents []DockerNode
|
||||
ServerYaml string
|
||||
AgentYaml string
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
type DockerNode struct {
|
||||
Name string
|
||||
Port int
|
||||
IP string
|
||||
URL string
|
||||
}
|
||||
|
||||
type Agent struct {
|
||||
Name string
|
||||
IP string
|
||||
type Server struct {
|
||||
DockerNode
|
||||
Port int
|
||||
URL string
|
||||
}
|
||||
|
||||
// NewTestConfig initializes the test environment and returns the configuration
|
||||
|
@ -140,6 +139,12 @@ func (config *TestConfig) ProvisionServers(numOfServers int) error {
|
|||
joinOrStart = fmt.Sprintf("--server %s", config.Servers[0].URL)
|
||||
}
|
||||
}
|
||||
newServer := Server{
|
||||
DockerNode: DockerNode{
|
||||
Name: name,
|
||||
},
|
||||
Port: port,
|
||||
}
|
||||
|
||||
// If we need restarts, we use the systemd-node container, volume mount the k3s binary
|
||||
// and start the server using the install script
|
||||
|
@ -167,7 +172,7 @@ func (config *TestConfig) ProvisionServers(numOfServers int) error {
|
|||
// The pipe requires that we use sh -c with "" to run the command
|
||||
sCmd := fmt.Sprintf("/bin/sh -c \"curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC='%s' INSTALL_K3S_SKIP_DOWNLOAD=true sh -\"",
|
||||
joinOrStart+" "+os.Getenv(fmt.Sprintf("SERVER_%d_ARGS", i)))
|
||||
if out, err := RunCmdOnDocker(name, sCmd); err != nil {
|
||||
if out, err := newServer.RunCmdOnNode(sCmd); err != nil {
|
||||
return fmt.Errorf("failed to start server: %s: %v", out, err)
|
||||
}
|
||||
} else {
|
||||
|
@ -199,13 +204,9 @@ func (config *TestConfig) ProvisionServers(numOfServers int) error {
|
|||
ip := strings.TrimSpace(ipOutput)
|
||||
|
||||
url := fmt.Sprintf("https://%s:6443", ip)
|
||||
|
||||
config.Servers = append(config.Servers, Server{
|
||||
Name: name,
|
||||
Port: port,
|
||||
IP: ip,
|
||||
URL: url,
|
||||
})
|
||||
newServer.URL = url
|
||||
newServer.IP = ip
|
||||
config.Servers = append(config.Servers, newServer)
|
||||
|
||||
fmt.Printf("Started %s @ %s\n", name, url)
|
||||
|
||||
|
@ -235,6 +236,9 @@ func (config *TestConfig) ProvisionAgents(numOfAgents int) error {
|
|||
name := fmt.Sprintf("k3s-agent-%d-%s", i, strings.ToLower(testID))
|
||||
|
||||
agentInstanceArgs := fmt.Sprintf("AGENT_%d_ARGS", i)
|
||||
newAgent := DockerNode{
|
||||
Name: name,
|
||||
}
|
||||
|
||||
if config.NeedRestart {
|
||||
dRun := strings.Join([]string{"docker run -d",
|
||||
|
@ -257,7 +261,8 @@ func (config *TestConfig) ProvisionAgents(numOfAgents int) error {
|
|||
// The pipe requires that we use sh -c with "" to run the command
|
||||
sCmd := fmt.Sprintf("/bin/sh -c \"curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC='agent %s' INSTALL_K3S_SKIP_DOWNLOAD=true sh -\"",
|
||||
os.Getenv(agentInstanceArgs))
|
||||
if out, err := RunCmdOnDocker(name, sCmd); err != nil {
|
||||
|
||||
if out, err := newAgent.RunCmdOnNode(sCmd); err != nil {
|
||||
return fmt.Errorf("failed to start server: %s: %v", out, err)
|
||||
}
|
||||
} else {
|
||||
|
@ -285,11 +290,9 @@ func (config *TestConfig) ProvisionAgents(numOfAgents int) error {
|
|||
return err
|
||||
}
|
||||
ip := strings.TrimSpace(ipOutput)
|
||||
newAgent.IP = ip
|
||||
config.Agents = append(config.Agents, newAgent)
|
||||
|
||||
config.Agents = append(config.Agents, Agent{
|
||||
Name: name,
|
||||
IP: ip,
|
||||
})
|
||||
fmt.Printf("Started %s\n", name)
|
||||
return nil
|
||||
})
|
||||
|
@ -385,9 +388,9 @@ func copyAndModifyKubeconfig(config *TestConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// RunCmdOnDocker runs a command on a docker container
|
||||
func RunCmdOnDocker(container, cmd string) (string, error) {
|
||||
dCmd := fmt.Sprintf("docker exec %s %s", container, cmd)
|
||||
// RunCmdOnNode runs a command on a docker container
|
||||
func (node DockerNode) RunCmdOnNode(cmd string) (string, error) {
|
||||
dCmd := fmt.Sprintf("docker exec %s %s", node.Name, cmd)
|
||||
return RunCommand(dCmd)
|
||||
}
|
||||
|
||||
|
@ -425,8 +428,8 @@ func getEnvOrDefault(key, defaultValue string) string {
|
|||
}
|
||||
|
||||
// VerifyValidVersion checks for invalid version strings
|
||||
func VerifyValidVersion(container string, binary string) error {
|
||||
output, err := RunCmdOnDocker(container, binary+" version")
|
||||
func VerifyValidVersion(node Server, binary string) error {
|
||||
output, err := node.RunCmdOnNode(binary + " version")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
@ -81,7 +81,7 @@ var _ = Describe("Upgrade Tests", Ordered, func() {
|
|||
})
|
||||
It("should confirm latest version", func() {
|
||||
for _, server := range config.Servers {
|
||||
out, err := tester.RunCmdOnDocker(server.Name, "k3s --version")
|
||||
out, err := server.RunCmdOnNode("k3s --version")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(out).To(ContainSubstring(strings.Replace(latestVersion, "-", "+", 1)))
|
||||
}
|
||||
|
@ -127,11 +127,11 @@ var _ = Describe("Upgrade Tests", Ordered, func() {
|
|||
})
|
||||
It("should confirm commit version", func() {
|
||||
for _, server := range config.Servers {
|
||||
Expect(tester.VerifyValidVersion(server.Name, "kubectl")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server.Name, "ctr")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server.Name, "crictl")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server, "kubectl")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server, "ctr")).To(Succeed())
|
||||
Expect(tester.VerifyValidVersion(server, "crictl")).To(Succeed())
|
||||
|
||||
out, err := tester.RunCmdOnDocker(server.Name, "k3s --version")
|
||||
out, err := server.RunCmdOnNode("k3s --version")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
cVersion := strings.Split(*k3sImage, ":")[1]
|
||||
cVersion = strings.Replace(cVersion, "-amd64", "", 1)
|
||||
|
|
Loading…
Reference in New Issue