Skip to content

Commit

Permalink
e2e test with windows
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Buil <mbuil@suse.com>
  • Loading branch information
manuelbuil committed May 13, 2024
1 parent 8337ba3 commit e09f4b6
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 0 deletions.
69 changes: 69 additions & 0 deletions e2e/windows/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
NODE_ROLES = (ENV['E2E_NODE_ROLES'] ||
["server-0", "agent-1"])
NODE_BOXES = (ENV['E2E_NODE_BOXES'] ||
['generic/ubuntu2310', 'jborean93/WindowsServer2022'])
NODE_CPUS = (ENV['E2E_NODE_CPUS'] || 2).to_i
NODE_MEMORY = (ENV['E2E_NODE_MEMORY'] || 2048).to_i
NETWORK_PREFIX = "10.10.10"
install_type = ""

def provision(vm, role, role_num, node_num)
vm.box = NODE_BOXES[node_num]
vm.hostname = role
# An expanded netmask is required to allow VM<-->VM communication, virtualbox defaults to /32
node_ip = "#{NETWORK_PREFIX}.#{100+node_num}"
vm.network "private_network", ip: node_ip, netmask: "255.255.255.0"

scripts_location = Dir.exist?("./scripts") ? "./scripts" : "../scripts"
vagrant_defaults = File.exist?("./vagrantdefaults.rb") ? "./vagrantdefaults.rb" : "../vagrantdefaults.rb"
load vagrant_defaults

defaultOSConfigure(vm)

vm.provision "shell", inline: "ping -c 2 k3s.io"

if !REGISTRY.empty?
vm.provision "Set private registry", type: "shell", path: scripts_location + "/registry.sh", args: [ "#{NETWORK_PREFIX}.1" ]
end
addCoverageDir(vm, role, GOCOVER)

if role.include?("server") && role_num == 0
vm.provision 'k3s-primary-server', type: 'k3s', run: 'once' do |k3s|
k3s.args = "server "
k3s.config = <<~YAML
token: vagrant
node-external-ip: #{NETWORK_PREFIX}.100
flannel-iface: eth1
YAML
k3s.env = %W[K3S_KUBECONFIG_MODE=0644 INSTALL_K3S_CHANNEL=latest]
k3s.config_mode = '0644' # side-step https://github.com/k3s-io/k3s/issues/4321
end
end
end

Vagrant.configure("2") do |config|
config.vagrant.plugins = ["vagrant-k3s", "vagrant-reload", "vagrant-scp"]
# For windows, just use the password not the private key
config.ssh.password = "vagrant"
# Default provider is libvirt, virtualbox is only provided as a backup
config.vm.provider "libvirt" do |v|
v.cpus = NODE_CPUS
v.memory = NODE_MEMORY
# We replicate the default prefix, but add a timestamp to enable parallel runs and cleanup of old VMs
v.default_prefix = File.basename(Dir.getwd) + "_" + Time.now.to_i.to_s + "_"
end

if NODE_ROLES.kind_of?(String)
NODE_ROLES = NODE_ROLES.split(" ", -1)
end
if NODE_BOXES.kind_of?(String)
NODE_BOXES = NODE_BOXES.split(" ", -1)
end

NODE_ROLES.each_with_index do |role, i|
role_num = role.split("-", -1).pop.to_i
config.vm.define role do |node|
provision(node.vm, role, role_num, i)
end
end
end
109 changes: 109 additions & 0 deletions e2e/windows/windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package windows

import (
"flag"
"fmt"
"os"
"strconv"
"strings"
"testing"

"github.com/k3s-io/k3s/tests/e2e"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

// Valid nodeOS: generic/ubuntu2004, opensuse/Leap-15.3.x86_64
var nodeOS = flag.String("nodeOS", "generic/ubuntu2004", "operating system for linux nodes")
var serverCount = flag.Int("serverCount", 1, "number of server nodes")
var windowsAgentCount = flag.Int("windowsAgentCount", 1, "number of windows agent nodes")

const defaultWindowsOS = "jborean93/WindowsServer2022"

func Test_WindowsValidation(t *testing.T) {
flag.Parse()
RegisterFailHandler(Fail)
suiteConfig, reporterConfig := GinkgoConfiguration()
RunSpecs(t, "Validate Windows Test Suite", suiteConfig, reporterConfig)
}

func createVMs(nodeOS string, serverCount, linuxAgentCount, windowsAgentCount int) ([]string, []string, []string, error) {
serverNodeNames := []string{}
for i := 0; i < serverCount; i++ {
serverNodeNames = append(serverNodeNames, "server-"+strconv.Itoa(i))
}
windowsAgentNames := []string{}
for i := 0; i < linuxAgentCount; i++ {
windowsAgentNames = append(windowsAgentNames, "windows-agent-"+strconv.Itoa(i))
}
nodeRoles := strings.Join(serverNodeNames, " ") + " " + " " + strings.Join(windowsAgentNames, " ")
nodeRoles = strings.TrimSpace(nodeRoles)
nodeBoxes := strings.Repeat(nodeOS+" ", serverCount)
nodeBoxes += strings.Repeat(defaultWindowsOS+" ", windowsAgentCount)
nodeBoxes = strings.TrimSpace(nodeBoxes)

cmd := fmt.Sprintf("NODE_ROLES=\"%s\" NODE_BOXES=\"%s\" %s vagrant up &> vagrant.log", nodeRoles, nodeBoxes, testOptions)
fmt.Println(cmd)
if _, err := e2e.RunCommand(cmd); err != nil {
fmt.Println("Error Creating Cluster", err)
return nil, nil, nil, err
}
return serverNodeNames, windowsAgentNames, nil
}

var (
kubeConfigFile string
serverNodeNames []string
windowsAgentNames []string
)

var _ = ReportAfterEach(e2e.GenReport)
var _ = Describe("Verify Basic Cluster Creation", Ordered, func() {

It("Starts up with no issues", func() {
var err error
serverNodeNames, windowsAgentNames, err = createVMs(*nodeOS, *serverCount, *windowsAgentCount)
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
fmt.Println("Windows Agent Nodes:", windowsAgentNames)
kubeConfigFile, err = e2e.GenKubeConfigFile(serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())
})

It("Checks Node Status", func() {
Eventually(func(g Gomega) {
nodes, err := e2e.ParseNodes(kubeConfigFile, false)
g.Expect(err).NotTo(HaveOccurred())
for _, node := range nodes {
g.Expect(node.Status).Should(Equal("Ready"))
}
}, "420s", "5s").Should(Succeed())
_, err := e2e.ParseNodes(kubeConfigFile, true)
Expect(err).NotTo(HaveOccurred())
})

//Copy flanneld.exe binary to windows VM

//Create token on server node

//Download flannel CNI binary

//Write net-conf.json

})

var failed bool
var _ = AfterEach(func() {
failed = failed || CurrentSpecReport().Failed()
})

var _ = AfterSuite(func() {
if failed && !*ci {
fmt.Println("FAILED!")
} else {
Expect(e2e.DestroyCluster()).To(Succeed())
Expect(os.Remove(kubeConfigFile)).To(Succeed())
}
})
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ require (

require (
github.com/avast/retry-go/v4 v4.5.1
github.com/k3s-io/k3s v1.27.13+k3s1
github.com/onsi/ginkgo/v2 v2.16.0
github.com/onsi/gomega v1.31.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.905
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.894
sigs.k8s.io/knftables v0.0.14
Expand All @@ -50,9 +53,11 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
Expand Down
Loading

0 comments on commit e09f4b6

Please sign in to comment.