forked from flannel-io/flannel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Manuel Buil <mbuil@suse.com>
- Loading branch information
1 parent
8337ba3
commit e09f4b6
Showing
4 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.