diff --git a/test/e2e/export_logs.go b/test/e2e/export_logs.go new file mode 100644 index 000000000..5154dc7f9 --- /dev/null +++ b/test/e2e/export_logs.go @@ -0,0 +1,45 @@ +/* +Copyright 2024 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 e2e + +import ( + "context" + "runtime" + "testing" + + "sigs.k8s.io/e2e-framework/pkg/envconf" + "sigs.k8s.io/e2e-framework/pkg/features" +) + +func CaseDryRunExportLogs(kwokctlPath, clusterName, clusterRuntime string, rootDir string, updateTestdata bool) *features.FeatureBuilder { + return features.New("Dryrun Export Logs"). + Assess("test dryrun export logs", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/export_logs.txt" + args := []string{ + "--name", clusterName, "--dry-run", "export", "logs", + } + diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) + if err != nil { + t.Fatal(err) + } + if diff != "" && runtime.GOOS == "linux" { + updateCmd := "go test -v ./test/e2e/kwokctl/" + clusterRuntime + " -args --update-testdata" + t.Fatalf("Expected vs got:\n%s\nExeceute this command to update the testdata manually:%s", diff, updateCmd) + } + return ctx + }) +} diff --git a/test/e2e/kwokctl/binary/kubectl_test.go b/test/e2e/kwokctl/binary/kubectl_test.go index dc52e2752..c9667a5a3 100644 --- a/test/e2e/kwokctl/binary/kubectl_test.go +++ b/test/e2e/kwokctl/binary/kubectl_test.go @@ -25,6 +25,12 @@ import ( "sigs.k8s.io/kwok/test/e2e" ) +func TestDryrunExportLogs(t *testing.T) { + f0 := e2e.CaseDryRunExportLogs(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). + Feature() + testEnv.Test(t, f0) +} + func TestHack(t *testing.T) { f0 := e2e.CaseHack(kwokctlPath, clusterName, envconf.RandomName("node", 16)). Feature() @@ -74,13 +80,13 @@ func TestExec(t *testing.T) { } func TestRestart(t *testing.T) { - f0 := e2e.CaseRestart(kwokctlPath, clusterName). + f0 := e2e.CaseRestart(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). Feature() testEnv.Test(t, f0) } func TestSnapshot(t *testing.T) { - f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, pwd). + f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata, pwd). Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/binary/main_test.go b/test/e2e/kwokctl/binary/main_test.go index bb9d7073a..041baf525 100644 --- a/test/e2e/kwokctl/binary/main_test.go +++ b/test/e2e/kwokctl/binary/main_test.go @@ -18,6 +18,7 @@ limitations under the License. package binary_test import ( + "flag" "os" "runtime" "testing" @@ -32,16 +33,17 @@ import ( ) var ( - runtimeEnv = consts.RuntimeTypeBinary - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-binary", 16) - namespace = envconf.RandomName("ns", 16) - kwokPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwok"+helper.BinSuffix) - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ + runtimeEnv = consts.RuntimeTypeBinary + testEnv env.Environment + updateTestdata = false + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + logsDir = path.Join(rootDir, "logs") + clusterName = envconf.RandomName("kwok-e2e-binary", 16) + namespace = envconf.RandomName("ns", 16) + kwokPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwok"+helper.BinSuffix) + kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) + baseArgs = []string{ "--kwok-controller-binary=" + kwokPath, "--runtime=" + runtimeEnv, "--enable-metrics-server", @@ -51,6 +53,7 @@ var ( func init() { _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) + flag.BoolVar(&updateTestdata, "update-testdata", false, "update all of testdata") } func TestMain(m *testing.M) { diff --git a/test/e2e/kwokctl/docker/kubectl_test.go b/test/e2e/kwokctl/docker/kubectl_test.go index 5c81c407d..4ef4d0569 100644 --- a/test/e2e/kwokctl/docker/kubectl_test.go +++ b/test/e2e/kwokctl/docker/kubectl_test.go @@ -24,6 +24,12 @@ import ( "sigs.k8s.io/kwok/test/e2e" ) +func TestDryrunExportLogs(t *testing.T) { + f0 := e2e.CaseDryRunExportLogs(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). + Feature() + testEnv.Test(t, f0) +} + func TestHack(t *testing.T) { f0 := e2e.CaseHack(kwokctlPath, clusterName, envconf.RandomName("node", 16)). Feature() @@ -67,13 +73,13 @@ func TestExec(t *testing.T) { } func TestRestart(t *testing.T) { - f0 := e2e.CaseRestart(kwokctlPath, clusterName). + f0 := e2e.CaseRestart(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). Feature() testEnv.Test(t, f0) } func TestSnapshot(t *testing.T) { - f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, pwd). + f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata, pwd). Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/docker/main_test.go b/test/e2e/kwokctl/docker/main_test.go index 1d026ec2e..93384134c 100644 --- a/test/e2e/kwokctl/docker/main_test.go +++ b/test/e2e/kwokctl/docker/main_test.go @@ -18,6 +18,7 @@ limitations under the License. package docker_test import ( + "flag" "os" "runtime" "testing" @@ -32,16 +33,17 @@ import ( ) var ( - runtimeEnv = consts.RuntimeTypeDocker - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-docker", 16) - namespace = envconf.RandomName("ns", 16) - testImage = "localhost/kwok:test" - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ + runtimeEnv = consts.RuntimeTypeDocker + updateTestdata = false + testEnv env.Environment + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + logsDir = path.Join(rootDir, "logs") + clusterName = envconf.RandomName("kwok-e2e-docker", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" + kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) + baseArgs = []string{ "--kwok-controller-image=" + testImage, "--runtime=" + runtimeEnv, "--enable-metrics-server", @@ -51,6 +53,7 @@ var ( func init() { _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) + flag.BoolVar(&updateTestdata, "update-testdata", false, "update all of testdata") } func TestMain(m *testing.M) { diff --git a/test/e2e/kwokctl/dryrun/testdata/binary/export_logs.txt b/test/e2e/kwokctl/dryrun/testdata/binary/export_logs.txt new file mode 100644 index 000000000..e34333af5 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/binary/export_logs.txt @@ -0,0 +1,10 @@ +mkdir -p /workdir/clusters//export/logs +cp /workdir/clusters//kwok.yaml /workdir/clusters//export/logs/kwok.yaml +mkdir -p /workdir/clusters//export/logs/components +echo / >/workdir/clusters//export/logs/binary-info.txt +cp /workdir/clusters//logs/etcd.log /workdir/clusters//export/logs/components/etcd.log +cp /workdir/clusters//logs/kube-apiserver.log /workdir/clusters//export/logs/components/kube-apiserver.log +cp /workdir/clusters//logs/kube-controller-manager.log /workdir/clusters//export/logs/components/kube-controller-manager.log +cp /workdir/clusters//logs/kube-scheduler.log /workdir/clusters//export/logs/components/kube-scheduler.log +cp /workdir/clusters//logs/kwok-controller.log /workdir/clusters//export/logs/components/kwok-controller.log +cp /workdir/clusters//logs/metrics-server.log /workdir/clusters//export/logs/components/metrics-server.log diff --git a/test/e2e/kwokctl/dryrun/testdata/binary/snapshot_restore_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/binary/snapshot_restore_etcd.txt new file mode 100644 index 000000000..9bffeb928 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/binary/snapshot_restore_etcd.txt @@ -0,0 +1,15 @@ +kill $(cat /workdir/clusters//pids/etcd.pid) +rm /workdir/clusters//pids/etcd.pid +kill $(cat /workdir/clusters//pids/kube-apiserver.pid) +rm /workdir/clusters//pids/kube-apiserver.pid +rm -rf /workdir/clusters//etcd-data +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:32765 snapshot restore /test/e2e/kwokctl/binary/snapshot.db --data-dir /workdir/clusters//etcd-data +rm -rf /workdir/clusters//etcd +mv /workdir/clusters//etcd-data /workdir/clusters//etcd +kill $(cat /workdir/clusters//pids/kwok-controller.pid) +rm /workdir/clusters//pids/kwok-controller.pid +kill $(cat /workdir/clusters//pids/kube-controller-manager.pid) +rm /workdir/clusters//pids/kube-controller-manager.pid +kill $(cat /workdir/clusters//pids/kube-scheduler.pid) +rm /workdir/clusters//pids/kube-scheduler.pid diff --git a/test/e2e/kwokctl/dryrun/testdata/binary/snapshot_save_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/binary/snapshot_save_etcd.txt new file mode 100644 index 000000000..7b5aad6a3 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/binary/snapshot_save_etcd.txt @@ -0,0 +1,2 @@ +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:32765 snapshot save /test/e2e/kwokctl/binary/snapshot.db diff --git a/test/e2e/kwokctl/dryrun/testdata/binary/start_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/binary/start_cluster.txt new file mode 100644 index 000000000..d00b0e527 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/binary/start_cluster.txt @@ -0,0 +1,12 @@ +cd /workdir/clusters/ && etcd --name=node0 --auto-compaction-retention=1 --quota-backend-bytes=8589934592 --data-dir=/workdir/clusters//etcd --initial-advertise-peer-urls=http://0.0.0.0:32766 --listen-peer-urls=http://0.0.0.0:32766 --advertise-client-urls=http://0.0.0.0:32765 --listen-client-urls=http://0.0.0.0:32765 --initial-cluster=node0=http://0.0.0.0:32766 >/workdir/clusters//logs/etcd.log 2>&1 & +echo $! >/workdir/clusters//pids/etcd.pid +cd /workdir/clusters/ && kube-apiserver --etcd-prefix=/registry --allow-privileged=true --etcd-servers=http://127.0.0.1:32765 --authorization-mode=Node,RBAC --bind-address=0.0.0.0 --secure-port=32764 --tls-cert-file=/workdir/clusters//pki/admin.crt --tls-private-key-file=/workdir/clusters//pki/admin.key --client-ca-file=/workdir/clusters//pki/ca.crt --service-account-key-file=/workdir/clusters//pki/admin.key --service-account-signing-key-file=/workdir/clusters//pki/admin.key --service-account-issuer=https://kubernetes.default.svc.cluster.local --proxy-client-key-file=/workdir/clusters//pki/admin.key --proxy-client-cert-file=/workdir/clusters//pki/admin.crt >/workdir/clusters//logs/kube-apiserver.log 2>&1 & +echo $! >/workdir/clusters//pids/kube-apiserver.pid +cd /workdir/clusters/ && kube-controller-manager --node-monitor-period=25s --node-monitor-grace-period=3m20s --kubeconfig=/workdir/clusters//kubeconfig.yaml --authorization-always-allow-paths=/healthz,/readyz,/livez,/metrics --bind-address=0.0.0.0 --secure-port=32763 --root-ca-file=/workdir/clusters//pki/ca.crt --service-account-private-key-file=/workdir/clusters//pki/admin.key >/workdir/clusters//logs/kube-controller-manager.log 2>&1 & +echo $! >/workdir/clusters//pids/kube-controller-manager.pid +cd /workdir/clusters/ && kube-scheduler --kubeconfig=/workdir/clusters//kubeconfig.yaml --authorization-always-allow-paths=/healthz,/readyz,/livez,/metrics --bind-address=0.0.0.0 --secure-port=32762 >/workdir/clusters//logs/kube-scheduler.log 2>&1 & +echo $! >/workdir/clusters//pids/kube-scheduler.pid +cd /workdir/clusters/ && kwok-controller --manage-all-nodes=true --kubeconfig=/workdir/clusters//kubeconfig.yaml --config=/workdir/clusters//kwok.yaml --tls-cert-file=/workdir/clusters//pki/admin.crt --tls-private-key-file=/workdir/clusters//pki/admin.key --node-ip= --node-name=localhost --node-port=10247 --server-address=0.0.0.0:10247 --node-lease-duration-seconds=200 >/workdir/clusters//logs/kwok-controller.log 2>&1 & +echo $! >/workdir/clusters//pids/kwok-controller.pid +cd /workdir/clusters/ && metrics-server --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname --kubelet-use-node-status-port --kubelet-insecure-tls --metric-resolution=15s --bind-address=0.0.0.0 --secure-port=32761 --kubeconfig=/workdir/clusters//kubeconfig.yaml --authentication-kubeconfig=/workdir/clusters//kubeconfig.yaml --authorization-kubeconfig=/workdir/clusters//kubeconfig.yaml --tls-cert-file=/workdir/clusters//pki/admin.crt --tls-private-key-file=/workdir/clusters//pki/admin.key >/workdir/clusters//logs/metrics-server.log 2>&1 & +echo $! >/workdir/clusters//pids/metrics-server.pid diff --git a/test/e2e/kwokctl/dryrun/testdata/binary/stop_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/binary/stop_cluster.txt new file mode 100644 index 000000000..523bf7ce5 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/binary/stop_cluster.txt @@ -0,0 +1,12 @@ +kill $(cat /workdir/clusters//pids/metrics-server.pid) +rm /workdir/clusters//pids/metrics-server.pid +kill $(cat /workdir/clusters//pids/kube-controller-manager.pid) +rm /workdir/clusters//pids/kube-controller-manager.pid +kill $(cat /workdir/clusters//pids/kube-scheduler.pid) +rm /workdir/clusters//pids/kube-scheduler.pid +kill $(cat /workdir/clusters//pids/kwok-controller.pid) +rm /workdir/clusters//pids/kwok-controller.pid +kill $(cat /workdir/clusters//pids/kube-apiserver.pid) +rm /workdir/clusters//pids/kube-apiserver.pid +kill $(cat /workdir/clusters//pids/etcd.pid) +rm /workdir/clusters//pids/etcd.pid diff --git a/test/e2e/kwokctl/dryrun/testdata/docker/export_logs.txt b/test/e2e/kwokctl/dryrun/testdata/docker/export_logs.txt new file mode 100644 index 000000000..6c9341b37 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/docker/export_logs.txt @@ -0,0 +1,10 @@ +mkdir -p /workdir/clusters//export/logs +cp /workdir/clusters//kwok.yaml /workdir/clusters//export/logs/kwok.yaml +mkdir -p /workdir/clusters//export/logs/components +docker info >/workdir/clusters//export/logs/docker-info.txt +etcd logs kwok--etcd >/workdir/clusters//export/logs/components/etcd.log +kube-apiserver logs kwok--kube-apiserver >/workdir/clusters//export/logs/components/kube-apiserver.log +kube-controller-manager logs kwok--kube-controller-manager >/workdir/clusters//export/logs/components/kube-controller-manager.log +kube-scheduler logs kwok--kube-scheduler >/workdir/clusters//export/logs/components/kube-scheduler.log +kwok-controller logs kwok--kwok-controller >/workdir/clusters//export/logs/components/kwok-controller.log +metrics-server logs kwok--metrics-server >/workdir/clusters//export/logs/components/metrics-server.log diff --git a/test/e2e/kwokctl/dryrun/testdata/docker/snapshot_restore_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/docker/snapshot_restore_etcd.txt new file mode 100644 index 000000000..fa45ab033 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/docker/snapshot_restore_etcd.txt @@ -0,0 +1,14 @@ +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl snapshot restore /test/e2e/kwokctl/docker/snapshot.db --data-dir /workdir/clusters//etcd-data +docker stop kwok--etcd --time=0 +docker stop kwok--kube-apiserver --time=0 +docker cp /workdir/clusters//etcd-data kwok--etcd:/ +docker start kwok--etcd +docker start kwok--kube-apiserver +docker stop kwok--kwok-controller --time=0 +docker start kwok--kwok-controller +docker stop kwok--kube-controller-manager --time=0 +docker start kwok--kube-controller-manager +docker stop kwok--kube-scheduler --time=0 +docker start kwok--kube-scheduler +rm -rf /workdir/clusters//etcd-data diff --git a/test/e2e/kwokctl/dryrun/testdata/docker/snapshot_save_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/docker/snapshot_save_etcd.txt new file mode 100644 index 000000000..563af38d8 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/docker/snapshot_save_etcd.txt @@ -0,0 +1,2 @@ +docker exec --env=ETCDCTL_API=3 -i kwok--etcd etcdctl snapshot save /snapshot.db +docker cp kwok--etcd:/snapshot.db /test/e2e/kwokctl/docker/snapshot.db diff --git a/test/e2e/kwokctl/dryrun/testdata/docker/start_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/docker/start_cluster.txt new file mode 100644 index 000000000..43c29e990 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/docker/start_cluster.txt @@ -0,0 +1,6 @@ +docker start kwok--etcd +docker start kwok--kube-apiserver +docker start kwok--kube-controller-manager +docker start kwok--kube-scheduler +docker start kwok--kwok-controller +docker start kwok--metrics-server diff --git a/test/e2e/kwokctl/dryrun/testdata/docker/stop_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/docker/stop_cluster.txt new file mode 100644 index 000000000..400e1b1fd --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/docker/stop_cluster.txt @@ -0,0 +1,6 @@ +docker stop kwok--metrics-server --time=0 +docker stop kwok--kube-controller-manager --time=0 +docker stop kwok--kube-scheduler --time=0 +docker stop kwok--kwok-controller --time=0 +docker stop kwok--kube-apiserver --time=0 +docker stop kwok--etcd --time=0 diff --git a/test/e2e/kwokctl/dryrun/testdata/kind-podman/export_logs.txt b/test/e2e/kwokctl/dryrun/testdata/kind-podman/export_logs.txt new file mode 100644 index 000000000..050207009 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind-podman/export_logs.txt @@ -0,0 +1,10 @@ +mkdir -p /workdir/clusters//export/logs +cp /workdir/clusters//kwok.yaml /workdir/clusters//export/logs/kwok.yaml +mkdir -p /workdir/clusters//export/logs/components +kind version >/workdir/clusters//export/logs/kind-podman-info.txt +etcd logs -n kube-system etcd-kwok--control-plane >/workdir/clusters//export/logs/components/etcd.log +kube-apiserver logs -n kube-system kube-apiserver-kwok--control-plane >/workdir/clusters//export/logs/components/kube-apiserver.log +kube-controller-manager logs -n kube-system kube-controller-manager-kwok--control-plane >/workdir/clusters//export/logs/components/kube-controller-manager.log +kube-scheduler logs -n kube-system kube-scheduler-kwok--control-plane >/workdir/clusters//export/logs/components/kube-scheduler.log +kwok-controller logs -n kube-system kwok-controller-kwok--control-plane >/workdir/clusters//export/logs/components/kwok-controller.log +metrics-server logs -n kube-system metrics-server-kwok--control-plane >/workdir/clusters//export/logs/components/metrics-server.log diff --git a/test/e2e/kwokctl/dryrun/testdata/kind-podman/snapshot_restore_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/kind-podman/snapshot_restore_etcd.txt new file mode 100644 index 000000000..24a35efd6 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind-podman/snapshot_restore_etcd.txt @@ -0,0 +1,8 @@ +podman exec kwok--control-plane mv /etc/kubernetes/manifests/etcd.yaml /etc/kubernetes/etcd.yaml.bak +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl snapshot restore /test/e2e/kwokctl/kind-podman/snapshot.db --data-dir /workdir/clusters//etcd +podman cp /workdir/clusters//etcd kwok--control-plane:/var/lib/ +rm -rf /workdir/clusters//etcd +podman exec kwok--control-plane mv /etc/kubernetes/etcd.yaml.bak /etc/kubernetes/manifests/etcd.yaml +podman stop kwok--control-plane +podman start kwok--control-plane diff --git a/test/e2e/kwokctl/dryrun/testdata/kind-podman/snapshot_save_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/kind-podman/snapshot_save_etcd.txt new file mode 100644 index 000000000..d7e9130c2 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind-podman/snapshot_save_etcd.txt @@ -0,0 +1,3 @@ +kubectl --kubeconfig /workdir/clusters//kubeconfig.yaml exec -i -n kube-system etcd-kwok--control-plane -- etcdctl --endpoints=127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt snapshot save /var/lib/etcd/snapshot.db +podman cp kwok--control-plane:/var/lib/etcd/snapshot.db /test/e2e/kwokctl/kind-podman/snapshot.db +podman exec -i kwok--control-plane rm -f /var/lib/etcd/snapshot.db diff --git a/test/e2e/kwokctl/dryrun/testdata/kind-podman/start_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/kind-podman/start_cluster.txt new file mode 100644 index 000000000..041be1db5 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind-podman/start_cluster.txt @@ -0,0 +1 @@ +podman start kwok--control-plane diff --git a/test/e2e/kwokctl/dryrun/testdata/kind-podman/stop_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/kind-podman/stop_cluster.txt new file mode 100644 index 000000000..dc367ab74 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind-podman/stop_cluster.txt @@ -0,0 +1 @@ +podman stop kwok--control-plane diff --git a/test/e2e/kwokctl/dryrun/testdata/kind/export_logs.txt b/test/e2e/kwokctl/dryrun/testdata/kind/export_logs.txt new file mode 100644 index 000000000..56394c463 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind/export_logs.txt @@ -0,0 +1,10 @@ +mkdir -p /workdir/clusters//export/logs +cp /workdir/clusters//kwok.yaml /workdir/clusters//export/logs/kwok.yaml +mkdir -p /workdir/clusters//export/logs/components +kind version >/workdir/clusters//export/logs/kind-info.txt +etcd logs -n kube-system etcd-kwok--control-plane >/workdir/clusters//export/logs/components/etcd.log +kube-apiserver logs -n kube-system kube-apiserver-kwok--control-plane >/workdir/clusters//export/logs/components/kube-apiserver.log +kube-controller-manager logs -n kube-system kube-controller-manager-kwok--control-plane >/workdir/clusters//export/logs/components/kube-controller-manager.log +kube-scheduler logs -n kube-system kube-scheduler-kwok--control-plane >/workdir/clusters//export/logs/components/kube-scheduler.log +kwok-controller logs -n kube-system kwok-controller-kwok--control-plane >/workdir/clusters//export/logs/components/kwok-controller.log +metrics-server logs -n kube-system metrics-server-kwok--control-plane >/workdir/clusters//export/logs/components/metrics-server.log diff --git a/test/e2e/kwokctl/dryrun/testdata/kind/snapshot_restore_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/kind/snapshot_restore_etcd.txt new file mode 100644 index 000000000..1eda63ff4 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind/snapshot_restore_etcd.txt @@ -0,0 +1,8 @@ +docker exec kwok--control-plane mv /etc/kubernetes/manifests/etcd.yaml /etc/kubernetes/etcd.yaml.bak +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl snapshot restore /test/e2e/kwokctl/kind/snapshot.db --data-dir /workdir/clusters//etcd +docker cp /workdir/clusters//etcd kwok--control-plane:/var/lib/ +rm -rf /workdir/clusters//etcd +docker exec kwok--control-plane mv /etc/kubernetes/etcd.yaml.bak /etc/kubernetes/manifests/etcd.yaml +docker stop kwok--control-plane +docker start kwok--control-plane diff --git a/test/e2e/kwokctl/dryrun/testdata/kind/snapshot_save_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/kind/snapshot_save_etcd.txt new file mode 100644 index 000000000..f3438c474 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind/snapshot_save_etcd.txt @@ -0,0 +1,3 @@ +kubectl --kubeconfig /workdir/clusters//kubeconfig.yaml exec -i -n kube-system etcd-kwok--control-plane -- etcdctl --endpoints=127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt snapshot save /var/lib/etcd/snapshot.db +docker cp kwok--control-plane:/var/lib/etcd/snapshot.db /test/e2e/kwokctl/kind/snapshot.db +docker exec -i kwok--control-plane rm -f /var/lib/etcd/snapshot.db diff --git a/test/e2e/kwokctl/dryrun/testdata/kind/start_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/kind/start_cluster.txt new file mode 100644 index 000000000..9ae0d8be5 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind/start_cluster.txt @@ -0,0 +1 @@ +docker start kwok--control-plane diff --git a/test/e2e/kwokctl/dryrun/testdata/kind/stop_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/kind/stop_cluster.txt new file mode 100644 index 000000000..67e6733c7 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/kind/stop_cluster.txt @@ -0,0 +1 @@ +docker stop kwok--control-plane diff --git a/test/e2e/kwokctl/dryrun/testdata/nerdctl/export_logs.txt b/test/e2e/kwokctl/dryrun/testdata/nerdctl/export_logs.txt new file mode 100644 index 000000000..5a6ec62a0 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/nerdctl/export_logs.txt @@ -0,0 +1,10 @@ +mkdir -p /workdir/clusters//export/logs +cp /workdir/clusters//kwok.yaml /workdir/clusters//export/logs/kwok.yaml +mkdir -p /workdir/clusters//export/logs/components +nerdctl info >/workdir/clusters//export/logs/nerdctl-info.txt +etcd logs kwok--etcd >/workdir/clusters//export/logs/components/etcd.log +kube-apiserver logs kwok--kube-apiserver >/workdir/clusters//export/logs/components/kube-apiserver.log +kube-controller-manager logs kwok--kube-controller-manager >/workdir/clusters//export/logs/components/kube-controller-manager.log +kube-scheduler logs kwok--kube-scheduler >/workdir/clusters//export/logs/components/kube-scheduler.log +kwok-controller logs kwok--kwok-controller >/workdir/clusters//export/logs/components/kwok-controller.log +metrics-server logs kwok--metrics-server >/workdir/clusters//export/logs/components/metrics-server.log diff --git a/test/e2e/kwokctl/dryrun/testdata/nerdctl/snapshot_restore_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/nerdctl/snapshot_restore_etcd.txt new file mode 100644 index 000000000..a1e222dea --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/nerdctl/snapshot_restore_etcd.txt @@ -0,0 +1,15 @@ +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl snapshot restore /test/e2e/kwokctl/nerdctl/snapshot.db --data-dir /workdir/clusters//etcd-data +nerdctl stop kwok--kube-apiserver --time=0 +nerdctl cp /workdir/clusters//etcd-data kwok--etcd:/ +nerdctl stop kwok--etcd --time=0 +nerdctl start kwok--etcd +nerdctl start kwok--kube-apiserver +nerdctl stop kwok--kwok-controller --time=0 +nerdctl start kwok--kwok-controller +nerdctl stop kwok--kube-controller-manager --time=0 +nerdctl start kwok--kube-controller-manager +nerdctl stop kwok--kube-scheduler --time=0 +nerdctl start kwok--kube-scheduler +nerdctl start kwok--kube-apiserver +rm -rf /workdir/clusters//etcd-data diff --git a/test/e2e/kwokctl/dryrun/testdata/nerdctl/snapshot_save_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/nerdctl/snapshot_save_etcd.txt new file mode 100644 index 000000000..de50b82c5 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/nerdctl/snapshot_save_etcd.txt @@ -0,0 +1,2 @@ +nerdctl exec --env=ETCDCTL_API=3 -i kwok--etcd etcdctl snapshot save /snapshot.db +nerdctl cp kwok--etcd:/snapshot.db /test/e2e/kwokctl/nerdctl/snapshot.db diff --git a/test/e2e/kwokctl/dryrun/testdata/nerdctl/start_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/nerdctl/start_cluster.txt new file mode 100644 index 000000000..079be781e --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/nerdctl/start_cluster.txt @@ -0,0 +1,6 @@ +nerdctl start kwok--etcd +nerdctl start kwok--kube-apiserver +nerdctl start kwok--kube-controller-manager +nerdctl start kwok--kube-scheduler +nerdctl start kwok--kwok-controller +nerdctl start kwok--metrics-server diff --git a/test/e2e/kwokctl/dryrun/testdata/nerdctl/stop_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/nerdctl/stop_cluster.txt new file mode 100644 index 000000000..efffcd192 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/nerdctl/stop_cluster.txt @@ -0,0 +1,6 @@ +nerdctl stop kwok--metrics-server --time=0 +nerdctl stop kwok--kube-controller-manager --time=0 +nerdctl stop kwok--kube-scheduler --time=0 +nerdctl stop kwok--kwok-controller --time=0 +nerdctl stop kwok--kube-apiserver --time=0 +nerdctl stop kwok--etcd --time=0 diff --git a/test/e2e/kwokctl/dryrun/testdata/podman/export_logs.txt b/test/e2e/kwokctl/dryrun/testdata/podman/export_logs.txt new file mode 100644 index 000000000..4187a0efb --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/podman/export_logs.txt @@ -0,0 +1,10 @@ +mkdir -p /workdir/clusters//export/logs +cp /workdir/clusters//kwok.yaml /workdir/clusters//export/logs/kwok.yaml +mkdir -p /workdir/clusters//export/logs/components +podman info >/workdir/clusters//export/logs/podman-info.txt +etcd logs kwok--etcd >/workdir/clusters//export/logs/components/etcd.log +kube-apiserver logs kwok--kube-apiserver >/workdir/clusters//export/logs/components/kube-apiserver.log +kube-controller-manager logs kwok--kube-controller-manager >/workdir/clusters//export/logs/components/kube-controller-manager.log +kube-scheduler logs kwok--kube-scheduler >/workdir/clusters//export/logs/components/kube-scheduler.log +kwok-controller logs kwok--kwok-controller >/workdir/clusters//export/logs/components/kwok-controller.log +metrics-server logs kwok--metrics-server >/workdir/clusters//export/logs/components/metrics-server.log diff --git a/test/e2e/kwokctl/dryrun/testdata/podman/snapshot_restore_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/podman/snapshot_restore_etcd.txt new file mode 100644 index 000000000..4b3795609 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/podman/snapshot_restore_etcd.txt @@ -0,0 +1,14 @@ +# Download https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11--. and extract etcdctl to /workdir/clusters//bin/etcdctl +ETCDCTL_API=3 etcdctl snapshot restore /test/e2e/kwokctl/podman/snapshot.db --data-dir /workdir/clusters//etcd-data +podman stop kwok--etcd --time=0 +podman stop kwok--kube-apiserver --time=0 +podman cp /workdir/clusters//etcd-data kwok--etcd:/ +podman start kwok--etcd +podman start kwok--kube-apiserver +podman stop kwok--kwok-controller --time=0 +podman start kwok--kwok-controller +podman stop kwok--kube-controller-manager --time=0 +podman start kwok--kube-controller-manager +podman stop kwok--kube-scheduler --time=0 +podman start kwok--kube-scheduler +rm -rf /workdir/clusters//etcd-data diff --git a/test/e2e/kwokctl/dryrun/testdata/podman/snapshot_save_etcd.txt b/test/e2e/kwokctl/dryrun/testdata/podman/snapshot_save_etcd.txt new file mode 100644 index 000000000..c07ff2510 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/podman/snapshot_save_etcd.txt @@ -0,0 +1,2 @@ +podman exec --env=ETCDCTL_API=3 -i kwok--etcd etcdctl snapshot save /snapshot.db +podman cp kwok--etcd:/snapshot.db /test/e2e/kwokctl/podman/snapshot.db diff --git a/test/e2e/kwokctl/dryrun/testdata/podman/start_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/podman/start_cluster.txt new file mode 100644 index 000000000..cad2859e3 --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/podman/start_cluster.txt @@ -0,0 +1,6 @@ +podman start kwok--etcd +podman start kwok--kube-apiserver +podman start kwok--kube-controller-manager +podman start kwok--kube-scheduler +podman start kwok--kwok-controller +podman start kwok--metrics-server diff --git a/test/e2e/kwokctl/dryrun/testdata/podman/stop_cluster.txt b/test/e2e/kwokctl/dryrun/testdata/podman/stop_cluster.txt new file mode 100644 index 000000000..97668d15b --- /dev/null +++ b/test/e2e/kwokctl/dryrun/testdata/podman/stop_cluster.txt @@ -0,0 +1,6 @@ +podman stop kwok--metrics-server --time=0 +podman stop kwok--kube-controller-manager --time=0 +podman stop kwok--kube-scheduler --time=0 +podman stop kwok--kwok-controller --time=0 +podman stop kwok--kube-apiserver --time=0 +podman stop kwok--etcd --time=0 diff --git a/test/e2e/kwokctl/kind-podman/kubectl_test.go b/test/e2e/kwokctl/kind-podman/kubectl_test.go index 0a3e24b1e..e79f7595a 100644 --- a/test/e2e/kwokctl/kind-podman/kubectl_test.go +++ b/test/e2e/kwokctl/kind-podman/kubectl_test.go @@ -25,6 +25,12 @@ import ( "sigs.k8s.io/kwok/test/e2e" ) +func TestDryrunExportLogs(t *testing.T) { + f0 := e2e.CaseDryRunExportLogs(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). + Feature() + testEnv.Test(t, f0) +} + func TestHack(t *testing.T) { f0 := e2e.CaseHack(kwokctlPath, clusterName, envconf.RandomName("node", 16)). Feature() @@ -82,7 +88,7 @@ func TestExec(t *testing.T) { // } func TestSnapshot(t *testing.T) { - f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, pwd). + f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata, pwd). Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/kind-podman/main_test.go b/test/e2e/kwokctl/kind-podman/main_test.go index 11f76d7ed..f267acefb 100644 --- a/test/e2e/kwokctl/kind-podman/main_test.go +++ b/test/e2e/kwokctl/kind-podman/main_test.go @@ -19,6 +19,7 @@ package kind_podman_test import ( "context" + "flag" "os" "runtime" "testing" @@ -35,16 +36,17 @@ import ( ) var ( - runtimeEnv = consts.RuntimeTypeKindPodman - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-kind-podman", 16) - namespace = envconf.RandomName("ns", 16) - testImage = "localhost/kwok:test" - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ + runtimeEnv = consts.RuntimeTypeKindPodman + testEnv env.Environment + updateTestdata = false + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + logsDir = path.Join(rootDir, "logs") + clusterName = envconf.RandomName("kwok-e2e-kind-podman", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" + kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) + baseArgs = []string{ "--kwok-controller-image=" + testImage, "--runtime=" + runtimeEnv, "--enable-metrics-server", @@ -54,6 +56,7 @@ var ( func init() { _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) + flag.BoolVar(&updateTestdata, "update-testdata", false, "update all of testdata") } func TestMain(m *testing.M) { diff --git a/test/e2e/kwokctl/kind/kubectl_test.go b/test/e2e/kwokctl/kind/kubectl_test.go index ecb464c05..9ed550938 100644 --- a/test/e2e/kwokctl/kind/kubectl_test.go +++ b/test/e2e/kwokctl/kind/kubectl_test.go @@ -25,6 +25,12 @@ import ( "sigs.k8s.io/kwok/test/e2e" ) +func TestDryrunExportLogs(t *testing.T) { + f0 := e2e.CaseDryRunExportLogs(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). + Feature() + testEnv.Test(t, f0) +} + func TestHack(t *testing.T) { f0 := e2e.CaseHack(kwokctlPath, clusterName, envconf.RandomName("node", 16)). Feature() @@ -82,7 +88,7 @@ func TestExec(t *testing.T) { // } func TestSnapshot(t *testing.T) { - f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, pwd). + f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata, pwd). Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/kind/main_test.go b/test/e2e/kwokctl/kind/main_test.go index 0300364b5..c46d444fd 100644 --- a/test/e2e/kwokctl/kind/main_test.go +++ b/test/e2e/kwokctl/kind/main_test.go @@ -19,6 +19,7 @@ package kind_test import ( "context" + "flag" "os" "runtime" "testing" @@ -35,16 +36,17 @@ import ( ) var ( - runtimeEnv = consts.RuntimeTypeKind - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-kind", 16) - namespace = envconf.RandomName("ns", 16) - testImage = "localhost/kwok:test" - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ + runtimeEnv = consts.RuntimeTypeKind + testEnv env.Environment + updateTestdata = false + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + logsDir = path.Join(rootDir, "logs") + clusterName = envconf.RandomName("kwok-e2e-kind", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" + kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) + baseArgs = []string{ "--kwok-controller-image=" + testImage, "--runtime=" + runtimeEnv, "--enable-metrics-server", @@ -54,6 +56,7 @@ var ( func init() { _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) + flag.BoolVar(&updateTestdata, "update-testdata", false, "update all of testdata") } func TestMain(m *testing.M) { diff --git a/test/e2e/kwokctl/nerdctl/kubectl_test.go b/test/e2e/kwokctl/nerdctl/kubectl_test.go index 7af1a928c..d32d275a6 100644 --- a/test/e2e/kwokctl/nerdctl/kubectl_test.go +++ b/test/e2e/kwokctl/nerdctl/kubectl_test.go @@ -24,6 +24,12 @@ import ( "sigs.k8s.io/kwok/test/e2e" ) +func TestDryrunExportLogs(t *testing.T) { + f0 := e2e.CaseDryRunExportLogs(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). + Feature() + testEnv.Test(t, f0) +} + func TestHack(t *testing.T) { f0 := e2e.CaseHack(kwokctlPath, clusterName, envconf.RandomName("node", 16)). Feature() @@ -67,13 +73,13 @@ func TestExec(t *testing.T) { } func TestRestart(t *testing.T) { - f0 := e2e.CaseRestart(kwokctlPath, clusterName). + f0 := e2e.CaseRestart(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). Feature() testEnv.Test(t, f0) } func TestSnapshot(t *testing.T) { - f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, pwd). + f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata, pwd). Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/nerdctl/main_test.go b/test/e2e/kwokctl/nerdctl/main_test.go index dd89a9e01..865f5e617 100644 --- a/test/e2e/kwokctl/nerdctl/main_test.go +++ b/test/e2e/kwokctl/nerdctl/main_test.go @@ -18,6 +18,7 @@ limitations under the License. package nerdctl_test import ( + "flag" "os" "runtime" "testing" @@ -32,16 +33,17 @@ import ( ) var ( - runtimeEnv = consts.RuntimeTypeNerdctl - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-nerdctl", 16) - namespace = envconf.RandomName("ns", 16) - testImage = "localhost/kwok:test" - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ + runtimeEnv = consts.RuntimeTypeNerdctl + testEnv env.Environment + updateTestdata = false + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + logsDir = path.Join(rootDir, "logs") + clusterName = envconf.RandomName("kwok-e2e-nerdctl", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" + kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) + baseArgs = []string{ "--kwok-controller-image=" + testImage, "--runtime=" + runtimeEnv, "--enable-metrics-server", @@ -51,6 +53,7 @@ var ( func init() { _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) + flag.BoolVar(&updateTestdata, "update-testdata", false, "update all of testdata") } func TestMain(m *testing.M) { diff --git a/test/e2e/kwokctl/podman/kubectl_test.go b/test/e2e/kwokctl/podman/kubectl_test.go index 3541bd91d..4272d6a31 100644 --- a/test/e2e/kwokctl/podman/kubectl_test.go +++ b/test/e2e/kwokctl/podman/kubectl_test.go @@ -24,6 +24,12 @@ import ( "sigs.k8s.io/kwok/test/e2e" ) +func TestDryrunExportLogs(t *testing.T) { + f0 := e2e.CaseDryRunExportLogs(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). + Feature() + testEnv.Test(t, f0) +} + func TestHack(t *testing.T) { f0 := e2e.CaseHack(kwokctlPath, clusterName, envconf.RandomName("node", 16)). Feature() @@ -67,13 +73,13 @@ func TestExec(t *testing.T) { } func TestRestart(t *testing.T) { - f0 := e2e.CaseRestart(kwokctlPath, clusterName). + f0 := e2e.CaseRestart(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata). Feature() testEnv.Test(t, f0) } func TestSnapshot(t *testing.T) { - f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, pwd). + f0 := e2e.CaseSnapshot(kwokctlPath, clusterName, runtimeEnv, rootDir, updateTestdata, pwd). Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/podman/main_test.go b/test/e2e/kwokctl/podman/main_test.go index 93f8cd548..6a6cc55a2 100644 --- a/test/e2e/kwokctl/podman/main_test.go +++ b/test/e2e/kwokctl/podman/main_test.go @@ -18,6 +18,7 @@ limitations under the License. package podman_test import ( + "flag" "os" "runtime" "testing" @@ -32,16 +33,17 @@ import ( ) var ( - runtimeEnv = consts.RuntimeTypePodman - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-podman", 16) - namespace = envconf.RandomName("ns", 16) - testImage = "localhost/kwok:test" - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ + runtimeEnv = consts.RuntimeTypePodman + testEnv env.Environment + updateTestdata = false + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + logsDir = path.Join(rootDir, "logs") + clusterName = envconf.RandomName("kwok-e2e-podman", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" + kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) + baseArgs = []string{ "--kwok-controller-image=" + testImage, "--runtime=" + runtimeEnv, "--enable-metrics-server", @@ -51,6 +53,7 @@ var ( func init() { _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) + flag.BoolVar(&updateTestdata, "update-testdata", false, "update all of testdata") } func TestMain(m *testing.M) { diff --git a/test/e2e/restart.go b/test/e2e/restart.go index 7659e95fa..5b206a7c6 100644 --- a/test/e2e/restart.go +++ b/test/e2e/restart.go @@ -18,6 +18,7 @@ package e2e import ( "context" + "runtime" "testing" "sigs.k8s.io/e2e-framework/pkg/envconf" @@ -28,7 +29,7 @@ import ( ) // CaseRestart is the restart of a test case. -func CaseRestart(kwokctlPath, clusterName string) *features.FeatureBuilder { +func CaseRestart(kwokctlPath, clusterName string, clusterRuntime string, rootDir string, updateTestdata bool) *features.FeatureBuilder { node := helper.NewNodeBuilder("node0"). Build() pod0 := helper.NewPodBuilder("pod0"). @@ -41,6 +42,21 @@ func CaseRestart(kwokctlPath, clusterName string) *features.FeatureBuilder { Setup(helper.CreatePod(pod0)). Teardown(helper.DeletePod(pod0)). Teardown(helper.DeleteNode(node)). + Assess("test stop dryrun", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/stop_cluster.txt" + args := []string{ + "stop", "cluster", "--name", clusterName, "--dry-run", + } + diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) + if err != nil { + t.Fatal(err) + } + if diff != "" && runtime.GOOS == "linux" { + updateCmd := "go test -v ./test/e2e/kwokctl/" + clusterRuntime + " -args --update-testdata" + t.Fatalf("Expected vs got:\n%s\nExeceute this command to update the testdata manually:%s", diff, updateCmd) + } + return ctx + }). Assess("test stop", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { _, err := exec.Command(ctx, kwokctlPath, "stop", "cluster", "--name", clusterName) if err != nil { @@ -49,6 +65,21 @@ func CaseRestart(kwokctlPath, clusterName string) *features.FeatureBuilder { return ctx }). + Assess("test start dryrun", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/start_cluster.txt" + args := []string{ + "start", "cluster", "--name", clusterName, "--dry-run", + } + diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) + if err != nil { + t.Fatal(err) + } + if diff != "" && runtime.GOOS == "linux" { + updateCmd := "go test -v ./test/e2e/kwokctl/" + clusterRuntime + " -args --update-testdata" + t.Fatalf("Expected vs got:\n%s\nExeceute this command to update the testdata manually:%s", diff, updateCmd) + } + return ctx + }). Assess("test start", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { _, err := exec.Command(ctx, kwokctlPath, "start", "cluster", "--name", clusterName) if err != nil { diff --git a/test/e2e/snapshot.go b/test/e2e/snapshot.go index a5af76ba0..60cb09660 100644 --- a/test/e2e/snapshot.go +++ b/test/e2e/snapshot.go @@ -19,6 +19,7 @@ package e2e import ( "context" "os" + "runtime" "testing" corev1 "k8s.io/api/core/v1" @@ -32,7 +33,7 @@ import ( ) // CaseSnapshot is the snapshot of a test case. -func CaseSnapshot(kwokctlPath, clusterName string, tmpDir string) *features.FeatureBuilder { +func CaseSnapshot(kwokctlPath, clusterName string, clusterRuntime string, rootDir string, updateTestdata bool, tmpDir string) *features.FeatureBuilder { node := helper.NewNodeBuilder("node0"). Build() pod0 := helper.NewPodBuilder("pod0"). @@ -44,6 +45,21 @@ func CaseSnapshot(kwokctlPath, clusterName string, tmpDir string) *features.Feat return features.New("Snapshot"). Setup(helper.CreateNode(node)). Setup(helper.CreatePod(pod0)). + Assess("test dryrun snapshot save", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/snapshot_save_etcd.txt" + args := []string{ + "--name", clusterName, "--dry-run", "snapshot", "save", "--path", dbPath, "--format", "etcd", + } + diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) + if err != nil { + t.Fatal(err) + } + if diff != "" && runtime.GOOS == "linux" { + updateCmd := "go test -v ./test/e2e/kwokctl/" + clusterRuntime + " -args --update-testdata" + t.Fatalf("Expected vs got:\n%s\nExeceute this command to update the testdata manually:%s", diff, updateCmd) + } + return ctx + }). Assess("test snapshot", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { _, err := exec.Command(ctx, kwokctlPath, "snapshot", "save", "--name", clusterName, "--path", dbPath) if err != nil { @@ -54,6 +70,21 @@ func CaseSnapshot(kwokctlPath, clusterName string, tmpDir string) *features.Feat }). Assess("delete pod", helper.DeletePod(pod0)). Assess("delete node", helper.DeleteNode(node)). + Assess("test dryrun snapshot restore", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/snapshot_restore_etcd.txt" + args := []string{ + "--name", clusterName, "--dry-run", "snapshot", "restore", "--path", dbPath, "--format", "etcd", + } + diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) + if err != nil { + t.Fatal(err) + } + if diff != "" && runtime.GOOS == "linux" { + updateCmd := "go test -v ./test/e2e/kwokctl/" + clusterRuntime + " -args --update-testdata" + t.Fatalf("Expected vs got:\n%s\nExeceute this command to update the testdata manually:%s", diff, updateCmd) + } + return ctx + }). Assess("test restore", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { _, err := exec.Command(ctx, kwokctlPath, "snapshot", "restore", "--name", clusterName, "--path", dbPath) if err != nil {