diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 02006f0553..b799c2f06e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -88,78 +88,6 @@ jobs: run: | ./hack/e2e-test.sh e2e/kwok/${{ matrix.case }} - test-kwokctl-e2e: - strategy: - fail-fast: false - matrix: - include: - # Windows - # Linux containers are not supported on Windows Runner - # https://github.com/orgs/community/discussions/25491#discussioncomment-3248089 - - os: windows-latest - kwokctl-runtime: binary - - # MacOS - - os: macos-latest - kwokctl-runtime: binary - - os: macos-latest - kwokctl-runtime: docker - - # Linux - - os: ubuntu-latest - kwokctl-runtime: binary - - os: ubuntu-latest - kwokctl-runtime: docker - - os: ubuntu-latest - kwokctl-runtime: podman - - continue-on-error: false - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - # No binary is provided by default for control plane components outside of Linux - # https://www.downloadkubernetes.com - - name: Download Kubernetes Source Code - uses: actions/checkout@v3 - if: ${{ matrix.kwokctl-runtime == 'binary' && ( matrix.os == 'macos-latest' || matrix.os == 'windows-latest' ) }} - with: - repository: kubernetes/kubernetes - path: kubernetes - ref: v1.28.0 - - name: Build Kubernetes Binary for Windows - if: ${{ matrix.kwokctl-runtime == 'binary' && matrix.os == 'windows-latest' }} - shell: bash - run: | - export GOBIN="$(go env GOPATH)/bin" - cd "${GITHUB_WORKSPACE}/kubernetes" && go install ./cmd/{kube-apiserver,kube-controller-manager,kube-scheduler} - mkdir -p "${GITHUB_WORKSPACE//\\//}/workdir" && cat >"${GITHUB_WORKSPACE//\\//}/workdir/kwok.yaml" << EOF - kind: KwokctlConfiguration - apiVersion: config.kwok.x-k8s.io/v1alpha1 - options: - kubeBinaryPrefix: "${GOBIN//\\//}" - EOF - - name: Build Kubernetes Binary for MacOS - if: ${{ matrix.kwokctl-runtime == 'binary' && matrix.os == 'macos-latest' }} - shell: bash - run: | - cd "${GITHUB_WORKSPACE}/kubernetes" && make WHAT="cmd/kube-apiserver cmd/kube-controller-manager cmd/kube-scheduler" - mkdir -p "${GITHUB_WORKSPACE}/workdir" && cat >"${GITHUB_WORKSPACE}/workdir/kwok.yaml" << EOF - kind: KwokctlConfiguration - apiVersion: config.kwok.x-k8s.io/v1alpha1 - options: - kubeBinaryPrefix: "${GITHUB_WORKSPACE}/kubernetes/_output/bin" - EOF - - - name: Test Workable - shell: bash - run: | - ./hack/e2e-test.sh e2e/kwokctl/${{ matrix.kwokctl-runtime }} - test-kwok: strategy: fail-fast: false @@ -355,6 +283,11 @@ jobs: run: | ./hack/e2e-test.sh kwokctl/kwokctl_with_dryrun + - name: Test e2e + shell: bash + run: | + ./hack/e2e-test.sh e2e/kwokctl/${{ matrix.kwokctl-runtime }} + - name: Test Export Logs shell: bash run: | diff --git a/hack/e2e-test.sh b/hack/e2e-test.sh index d861fa9a16..a082763ce7 100755 --- a/hack/e2e-test.sh +++ b/hack/e2e-test.sh @@ -78,7 +78,7 @@ function main() { echo "================================================================================" if [[ "${target}" == "e2e/"* ]]; then echo "Testing ${target}..." - if ! go test -v "sigs.k8s.io/kwok/test/${target}" -args --v=8; then + if ! go test -v "sigs.k8s.io/kwok/test/${target}" -args --v=6; then failed+=("${target}") echo "------------------------------" echo "Test ${target} failed." diff --git a/test/e2e/kwokctl/kind-podman/kwok_test.go b/test/e2e/kwokctl/kind-podman/kwok_test.go new file mode 100644 index 0000000000..958b5f04f2 --- /dev/null +++ b/test/e2e/kwokctl/kind-podman/kwok_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2023 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 docker_test + +import ( + "testing" + + "sigs.k8s.io/e2e-framework/pkg/envconf" + + "sigs.k8s.io/kwok/test/e2e" +) + +func TestNode(t *testing.T) { + f0 := e2e.CaseNode(envconf.RandomName("node", 16)). + Feature() + testEnv.Test(t, f0) +} + +func TestPod(t *testing.T) { + f0 := e2e.CasePod(envconf.RandomName("node", 16), namespace). + 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 new file mode 100644 index 0000000000..6e96878c99 --- /dev/null +++ b/test/e2e/kwokctl/kind-podman/main_test.go @@ -0,0 +1,94 @@ +/* +Copyright 2023 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 docker_test is a test environment for kwok. +package docker_test + +import ( + "context" + "os" + "runtime" + "testing" + + "sigs.k8s.io/e2e-framework/pkg/env" + "sigs.k8s.io/e2e-framework/pkg/envconf" + "sigs.k8s.io/e2e-framework/pkg/envfuncs" + "sigs.k8s.io/e2e-framework/support/kwok" + + "sigs.k8s.io/kwok/pkg/consts" + "sigs.k8s.io/kwok/pkg/utils/path" + "sigs.k8s.io/kwok/test/e2e/helper" +) + +var ( + testEnv env.Environment + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + clusterName = envconf.RandomName("kwok-e2e", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" +) + +func init() { + _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) +} + +func TestMain(m *testing.M) { + ctx := context.Background() + cfg, _ := envconf.NewFromFlags() + + testEnv, _ = env.NewWithContext(ctx, cfg) + namespace = envconf.RandomName("ns", 16) + + kwokctlPath := path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl") + + k := kwok.NewProvider(). + WithName(clusterName). + WithPath(kwokctlPath) + testEnv.Setup( + helper.BuildKwokImage(rootDir, testImage, consts.RuntimeTypePodman), + helper.BuildKwokctlBinary(rootDir), + func(ctx context.Context, cfg *envconf.Config) (context.Context, error) { + kubecfg, err := k.Create(ctx, + "--kwok-controller-image", testImage, + "--runtime", consts.RuntimeTypeKindPodman, + ) + if err != nil { + return ctx, err + } + + cfg.WithKubeconfigFile(kubecfg) + + if err := k.WaitForControlPlane(ctx, cfg.Client()); err != nil { + return ctx, err + } + + return ctx, nil + }, + envfuncs.CreateNamespace(namespace), + ) + testEnv.Finish( + func(ctx context.Context, config *envconf.Config) (context.Context, error) { + err := k.Destroy(ctx) + if err != nil { + return ctx, err + } + + return ctx, nil + }, + ) + os.Exit(testEnv.Run(m)) +} diff --git a/test/e2e/kwokctl/kind/kwok_test.go b/test/e2e/kwokctl/kind/kwok_test.go new file mode 100644 index 0000000000..958b5f04f2 --- /dev/null +++ b/test/e2e/kwokctl/kind/kwok_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2023 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 docker_test + +import ( + "testing" + + "sigs.k8s.io/e2e-framework/pkg/envconf" + + "sigs.k8s.io/kwok/test/e2e" +) + +func TestNode(t *testing.T) { + f0 := e2e.CaseNode(envconf.RandomName("node", 16)). + Feature() + testEnv.Test(t, f0) +} + +func TestPod(t *testing.T) { + f0 := e2e.CasePod(envconf.RandomName("node", 16), namespace). + Feature() + testEnv.Test(t, f0) +} diff --git a/test/e2e/kwokctl/kind/main_test.go b/test/e2e/kwokctl/kind/main_test.go new file mode 100644 index 0000000000..1dc4ea7146 --- /dev/null +++ b/test/e2e/kwokctl/kind/main_test.go @@ -0,0 +1,94 @@ +/* +Copyright 2023 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 docker_test is a test environment for kwok. +package docker_test + +import ( + "context" + "os" + "runtime" + "testing" + + "sigs.k8s.io/e2e-framework/pkg/env" + "sigs.k8s.io/e2e-framework/pkg/envconf" + "sigs.k8s.io/e2e-framework/pkg/envfuncs" + "sigs.k8s.io/e2e-framework/support/kwok" + + "sigs.k8s.io/kwok/pkg/consts" + "sigs.k8s.io/kwok/pkg/utils/path" + "sigs.k8s.io/kwok/test/e2e/helper" +) + +var ( + testEnv env.Environment + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + clusterName = envconf.RandomName("kwok-e2e", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" +) + +func init() { + _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) +} + +func TestMain(m *testing.M) { + ctx := context.Background() + cfg, _ := envconf.NewFromFlags() + + testEnv, _ = env.NewWithContext(ctx, cfg) + namespace = envconf.RandomName("ns", 16) + + kwokctlPath := path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl") + + k := kwok.NewProvider(). + WithName(clusterName). + WithPath(kwokctlPath) + testEnv.Setup( + helper.BuildKwokImage(rootDir, testImage, consts.RuntimeTypeDocker), + helper.BuildKwokctlBinary(rootDir), + func(ctx context.Context, cfg *envconf.Config) (context.Context, error) { + kubecfg, err := k.Create(ctx, + "--kwok-controller-image", testImage, + "--runtime", consts.RuntimeTypeKind, + ) + if err != nil { + return ctx, err + } + + cfg.WithKubeconfigFile(kubecfg) + + if err := k.WaitForControlPlane(ctx, cfg.Client()); err != nil { + return ctx, err + } + + return ctx, nil + }, + envfuncs.CreateNamespace(namespace), + ) + testEnv.Finish( + func(ctx context.Context, config *envconf.Config) (context.Context, error) { + err := k.Destroy(ctx) + if err != nil { + return ctx, err + } + + return ctx, nil + }, + ) + os.Exit(testEnv.Run(m)) +} diff --git a/test/e2e/kwokctl/nerdctl/kwok_test.go b/test/e2e/kwokctl/nerdctl/kwok_test.go new file mode 100644 index 0000000000..958b5f04f2 --- /dev/null +++ b/test/e2e/kwokctl/nerdctl/kwok_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2023 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 docker_test + +import ( + "testing" + + "sigs.k8s.io/e2e-framework/pkg/envconf" + + "sigs.k8s.io/kwok/test/e2e" +) + +func TestNode(t *testing.T) { + f0 := e2e.CaseNode(envconf.RandomName("node", 16)). + Feature() + testEnv.Test(t, f0) +} + +func TestPod(t *testing.T) { + f0 := e2e.CasePod(envconf.RandomName("node", 16), namespace). + Feature() + testEnv.Test(t, f0) +} diff --git a/test/e2e/kwokctl/nerdctl/main_test.go b/test/e2e/kwokctl/nerdctl/main_test.go new file mode 100644 index 0000000000..663f68ce00 --- /dev/null +++ b/test/e2e/kwokctl/nerdctl/main_test.go @@ -0,0 +1,94 @@ +/* +Copyright 2023 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 docker_test is a test environment for kwok. +package docker_test + +import ( + "context" + "os" + "runtime" + "testing" + + "sigs.k8s.io/e2e-framework/pkg/env" + "sigs.k8s.io/e2e-framework/pkg/envconf" + "sigs.k8s.io/e2e-framework/pkg/envfuncs" + "sigs.k8s.io/e2e-framework/support/kwok" + + "sigs.k8s.io/kwok/pkg/consts" + "sigs.k8s.io/kwok/pkg/utils/path" + "sigs.k8s.io/kwok/test/e2e/helper" +) + +var ( + testEnv env.Environment + pwd = os.Getenv("PWD") + rootDir = path.Join(pwd, "../../../..") + clusterName = envconf.RandomName("kwok-e2e", 16) + namespace = envconf.RandomName("ns", 16) + testImage = "localhost/kwok:test" +) + +func init() { + _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) +} + +func TestMain(m *testing.M) { + ctx := context.Background() + cfg, _ := envconf.NewFromFlags() + + testEnv, _ = env.NewWithContext(ctx, cfg) + namespace = envconf.RandomName("ns", 16) + + kwokctlPath := path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl") + + k := kwok.NewProvider(). + WithName(clusterName). + WithPath(kwokctlPath) + testEnv.Setup( + helper.BuildKwokImage(rootDir, testImage, consts.RuntimeTypeNerdctl), + helper.BuildKwokctlBinary(rootDir), + func(ctx context.Context, cfg *envconf.Config) (context.Context, error) { + kubecfg, err := k.Create(ctx, + "--kwok-controller-image", testImage, + "--runtime", consts.RuntimeTypeNerdctl, + ) + if err != nil { + return ctx, err + } + + cfg.WithKubeconfigFile(kubecfg) + + if err := k.WaitForControlPlane(ctx, cfg.Client()); err != nil { + return ctx, err + } + + return ctx, nil + }, + envfuncs.CreateNamespace(namespace), + ) + testEnv.Finish( + func(ctx context.Context, config *envconf.Config) (context.Context, error) { + err := k.Destroy(ctx) + if err != nil { + return ctx, err + } + + return ctx, nil + }, + ) + os.Exit(testEnv.Run(m)) +}