Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Aug 29, 2023
1 parent 48052e6 commit 0e1756c
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 73 deletions.
77 changes: 5 additions & 72 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion hack/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/kwokctl/kind-podman/kwok_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
94 changes: 94 additions & 0 deletions test/e2e/kwokctl/kind-podman/main_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
37 changes: 37 additions & 0 deletions test/e2e/kwokctl/kind/kwok_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
94 changes: 94 additions & 0 deletions test/e2e/kwokctl/kind/main_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
Loading

0 comments on commit 0e1756c

Please sign in to comment.