generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 211
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: Neeraj Nagure <nagureneeraj@gmail.com> fixed linting error fixed lint error shifted dryrun test to binary Signed-off-by: Neeraj Nagure <nagureneeraj@gmail.com> fixed kwokctl cmd fixed cluster details removed space fixed errors fixed path fixed path fixed path fixed path logged path fixed path fixed path fixed get cluster fixed expected cluster fixed exec added binary runtime fixed cmd fixed cmd logged got set the runtime set runtime logged replaced kwokctl output removed unnecessary logs fixed lint fixed lint error migrated normal dry run to e2e moved dryrun tests to a new folder Signed-off-by: Neeraj Nagure <nagureneeraj@gmail.com> added dry run tests for other runtimes fixed lint error added dryrun to ci and added two new dry run cases Signed-off-by: Neeraj Nagure <nagureneeraj@gmail.com> cleaned args and added dry run extra tests Signed-off-by: Neeraj Nagure <nagureneeraj@gmail.com> fixed lint error removed newlines added testdata for dryrun tests Signed-off-by: Neeraj Nagure <nagureneeraj@gmail.com> logged got cluster updated testdata fixed lint error fixed lint error added update testdata script Signed-off-by: Neeraj Nagure <nagureneeraj@gmail.com> added verify testdata added newline fixed update-testdata gave permission added permission for update testdata added default values fixed testdata fixed script fixed verify fixed verify fixed verify fixed indentations fixed testdata fixed update-testdata script changed the update testdata script to go test fixed conflict added verify-testdata fixed lint fixed verify Combined the logic in a single function fixed fixed
- Loading branch information
1 parent
429ae66
commit 3b60a27
Showing
31 changed files
with
4,179 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
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
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,28 @@ | ||
#!/usr/bin/env bash | ||
# 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. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
DIR="$(dirname "${BASH_SOURCE[0]}")" | ||
|
||
ROOT_DIR="$(realpath "${DIR}/..")" | ||
|
||
function update() { | ||
go test -v ./test/e2e/kwokctl/dryrun -args --update-testdata | ||
} | ||
|
||
cd "${ROOT_DIR}" && update |
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
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,31 @@ | ||
#!/usr/bin/env bash | ||
# 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. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
DIR="$(dirname "${BASH_SOURCE[0]}")" | ||
|
||
ROOT_DIR="$(realpath "${DIR}/..")" | ||
|
||
function check() { | ||
if [[ "${UPDATE_DRY_RUN_TESTDATA:-"false"}" == "true" ]]; then | ||
"${ROOT_DIR}"/hack/update-testdata.sh | ||
fi | ||
git --no-pager diff --exit-code | ||
} | ||
|
||
cd "${ROOT_DIR}" && check |
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,146 @@ | ||
/* | ||
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" | ||
"io/fs" | ||
"os" | ||
"os/exec" | ||
"regexp" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/features" | ||
|
||
"sigs.k8s.io/kwok/pkg/utils/path" | ||
) | ||
|
||
var ( | ||
emptyLine = regexp.MustCompile("\n{2,}") | ||
homeDir, _ = os.UserHomeDir() | ||
) | ||
|
||
func formatCmdOutput(got, clusterName, rootDir string) string { | ||
got = strings.ReplaceAll(got, clusterName, "<CLUSTER_NAME>") | ||
got = strings.ReplaceAll(got, rootDir, "<ROOT_DIR>") | ||
got = strings.ReplaceAll(got, runtime.GOOS, "<OS>") | ||
got = strings.ReplaceAll(got, runtime.GOARCH, "<ARCH>") | ||
got = strings.ReplaceAll(got, ".zip", ".<TAR>") | ||
got = strings.ReplaceAll(got, ".tar.gz", ".<TAR>") | ||
got = strings.ReplaceAll(got, homeDir, "~") | ||
got = emptyLine.ReplaceAllLiteralString(got, "\n") | ||
return got | ||
} | ||
|
||
func executeCommand(args []string, absPath string, clusterName string, kwokctlPath string, rootDir string, updateTestdata bool) (string, error) { | ||
testdataPath := path.Join(rootDir, absPath) | ||
expected, err := os.ReadFile(testdataPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
cmd := exec.Command(kwokctlPath, args...) | ||
output, err := cmd.Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
want := string(expected) | ||
got := string(output) | ||
got = formatCmdOutput(got, clusterName, rootDir) | ||
if diff := cmp.Diff(got, want); diff != "" { | ||
if updateTestdata { | ||
err = os.WriteFile(testdataPath, []byte(got), fs.FileMode(0644)) | ||
if err != nil { | ||
return "", err | ||
} | ||
} else { | ||
return diff, nil | ||
} | ||
} | ||
return "", nil | ||
} | ||
|
||
func CaseDryrun(clusterName string, kwokctlPath string, rootDir string, clusterRuntime string, updateTestdata bool) *features.FeatureBuilder { | ||
f := features.New("Dry run") | ||
f = f.Assess("test cluster dryrun", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||
absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/create_cluster.txt" | ||
args := []string{ | ||
"create", "cluster", "--dry-run", "--name", clusterName, "--timeout=30m", | ||
"--wait=30m", "--quiet-pull", "--disable-qps-limits", "--kube-authorization=false", | ||
"--runtime", clusterRuntime, | ||
} | ||
diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff != "" { | ||
t.Fatalf("Expected vs got:\n%s", diff) | ||
} | ||
return ctx | ||
}) | ||
return f | ||
} | ||
|
||
func CaseDryrunWithExtra(clusterName string, kwokctlPath string, rootDir string, clusterRuntime string, updateTestdata bool) *features.FeatureBuilder { | ||
f := features.New("Dry run with extra") | ||
f = f.Assess("test cluster dryrun with extra", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||
absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/create_cluster_with_extra.txt" | ||
extraPath := path.Join(rootDir, "test/kwokctl/testdata/extra.yaml") | ||
args := []string{ | ||
"create", "cluster", "--dry-run", "--name", clusterName, "--timeout=30m", | ||
"--wait=30m", "--quiet-pull", "--disable-qps-limits", "--runtime", clusterRuntime, | ||
"--config", extraPath, | ||
} | ||
diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff != "" { | ||
t.Fatalf("Expected vs got:\n%s", diff) | ||
} | ||
return ctx | ||
}) | ||
return f | ||
} | ||
|
||
func CaseDryrunWithVerbosity(clusterName string, kwokctlPath string, rootDir string, clusterRuntime string, updateTestdata bool) *features.FeatureBuilder { | ||
f := features.New("Dry run with verbosity") | ||
f = f.Assess("test cluster dryrun with verbosity", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||
absPath := "test/e2e/kwokctl/dryrun/testdata/" + clusterRuntime + "/create_cluster_with_verbosity.txt" | ||
kubeAuditPath := path.Join(rootDir, "test/kwokctl/audit-policy.yaml") | ||
schedulerConfigPath := path.Join(rootDir, "test/kwokctl/scheduler-config.yaml") | ||
args := []string{ | ||
"create", "cluster", "--dry-run", "--name", clusterName, "--timeout=30m", "--wait=30m", | ||
"--quiet-pull", "--disable-qps-limits", "--runtime", clusterRuntime, | ||
"--prometheus-port=9090", "--jaeger-port=16686", "--dashboard-port=8000", | ||
"--enable-metrics-server", "--kube-audit-policy", kubeAuditPath, | ||
"--kube-scheduler-config", schedulerConfigPath, | ||
} | ||
diff, err := executeCommand(args, absPath, clusterName, kwokctlPath, rootDir, updateTestdata) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff != "" { | ||
t.Fatalf("Expected vs got:\n%s", diff) | ||
} | ||
return ctx | ||
}) | ||
return f | ||
} |
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,38 @@ | ||
/* | ||
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 dryrun_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"sigs.k8s.io/kwok/test/e2e" | ||
) | ||
|
||
func TestBinaryDryRun(t *testing.T) { | ||
f0 := e2e.CaseDryrun(clusterName, kwokctlPath, rootDir, "binary", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} | ||
|
||
func TestBinaryDryRunWithExtra(t *testing.T) { | ||
f0 := e2e.CaseDryrunWithExtra(clusterName, kwokctlPath, rootDir, "binary", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} | ||
|
||
func TestBinaryDryRunWithVerbosity(t *testing.T) { | ||
f0 := e2e.CaseDryrunWithVerbosity(clusterName, kwokctlPath, rootDir, "binary", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} |
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,38 @@ | ||
/* | ||
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 dryrun_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"sigs.k8s.io/kwok/test/e2e" | ||
) | ||
|
||
func TestDockerDryRun(t *testing.T) { | ||
f0 := e2e.CaseDryrun(clusterName, kwokctlPath, rootDir, "docker", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} | ||
|
||
func TestDockerDryRunWithExtra(t *testing.T) { | ||
f0 := e2e.CaseDryrunWithExtra(clusterName, kwokctlPath, rootDir, "docker", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} | ||
|
||
func TestDockerDryRunWithVerbosity(t *testing.T) { | ||
f0 := e2e.CaseDryrunWithVerbosity(clusterName, kwokctlPath, rootDir, "docker", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} |
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,38 @@ | ||
/* | ||
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 dryrun_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"sigs.k8s.io/kwok/test/e2e" | ||
) | ||
|
||
func TestKindPodmanDryRun(t *testing.T) { | ||
f0 := e2e.CaseDryrun(clusterName, kwokctlPath, rootDir, "kind-podman", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} | ||
|
||
func TestKindPodmanDryRunWithExtra(t *testing.T) { | ||
f0 := e2e.CaseDryrunWithExtra(clusterName, kwokctlPath, rootDir, "kind-podman", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} | ||
|
||
func TestKindPodmanDryRunWithVerbosity(t *testing.T) { | ||
f0 := e2e.CaseDryrunWithVerbosity(clusterName, kwokctlPath, rootDir, "kind-podman", updateTestdata).Feature() | ||
testEnv.Test(t, f0) | ||
} |
Oops, something went wrong.