mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #89982 from neolit123/1.19-fix-kubeadm-integration-tests
cleanup the kubeadm integration tests and related scripts
This commit is contained in:
commit
1634d9c120
@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2016 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
|
||||
|
||||
KUBE_ROOT=${KUBE_ROOT:-$(dirname "${BASH_SOURCE[0]}")/..}
|
||||
source "${KUBE_ROOT}/cluster/clientbin.sh"
|
||||
|
||||
# If KUBEADM_PATH isn't set, gather up the list of likely places and use ls
|
||||
# to find the latest one.
|
||||
if [[ -z "${KUBEADM_PATH:-}" ]]; then
|
||||
kubeadm=$( get_bin "kubeadm" "cmd/kubeadm" )
|
||||
|
||||
if [[ ! -x "$kubeadm" ]]; then
|
||||
print_error "kubeadm"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ ! -x "${KUBEADM_PATH}" ]]; then
|
||||
{
|
||||
echo "KUBEADM_PATH environment variable set to '${KUBEADM_PATH}', but "
|
||||
echo "this doesn't seem to be a valid executable."
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
kubeadm="${KUBEADM_PATH:-${kubeadm}}"
|
||||
|
||||
"${kubeadm}" "${@+$@}"
|
@ -357,7 +357,10 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
|
||||
// if dry running creates a temporary folder for saving kubeadm generated files
|
||||
dryRunDir := ""
|
||||
if options.dryRun {
|
||||
if dryRunDir, err = kubeadmconstants.CreateTempDirForKubeadm("", "kubeadm-init-dryrun"); err != nil {
|
||||
// the KUBEADM_INIT_DRYRUN_DIR environment variable allows overriding the dry-run temporary
|
||||
// directory from the command line. This makes it possible to run "kubeadm init" integration
|
||||
// tests without root.
|
||||
if dryRunDir, err = kubeadmconstants.CreateTempDirForKubeadm(os.Getenv("KUBEADM_INIT_DRYRUN_DIR"), "kubeadm-init-dryrun"); err != nil {
|
||||
return nil, errors.Wrap(err, "couldn't create a temporary directory")
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ go_test(
|
||||
"token_test.go",
|
||||
"version_test.go",
|
||||
],
|
||||
args = ["--kubeadm-path=$(location //cmd/kubeadm:kubeadm)"],
|
||||
data = ["//cmd/kubeadm"] + glob(["testdata/**"]),
|
||||
embed = [":go_default_library"],
|
||||
tags = [
|
||||
|
@ -20,12 +20,6 @@ import "testing"
|
||||
|
||||
func TestCmdCompletion(t *testing.T) {
|
||||
kubeadmPath := getKubeadmPath()
|
||||
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
name string
|
||||
args string
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package kubeadm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -30,6 +32,10 @@ import (
|
||||
)
|
||||
|
||||
func runKubeadmInit(args ...string) (string, string, int, error) {
|
||||
const dryRunDir = "KUBEADM_INIT_DRYRUN_DIR"
|
||||
if err := os.Setenv(dryRunDir, os.TempDir()); err != nil {
|
||||
panic(fmt.Sprintf("could not set the %s environment variable", dryRunDir))
|
||||
}
|
||||
kubeadmPath := getKubeadmPath()
|
||||
kubeadmArgs := []string{"init", "--dry-run", "--ignore-preflight-errors=all"}
|
||||
kubeadmArgs = append(kubeadmArgs, args...)
|
||||
@ -37,11 +43,6 @@ func runKubeadmInit(args ...string) (string, string, int, error) {
|
||||
}
|
||||
|
||||
func TestCmdInitToken(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
initTest := []struct {
|
||||
name string
|
||||
args string
|
||||
@ -86,11 +87,6 @@ func TestCmdInitToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdInitKubernetesVersion(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
initTest := []struct {
|
||||
name string
|
||||
args string
|
||||
@ -130,11 +126,6 @@ func TestCmdInitKubernetesVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdInitConfig(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
initTest := []struct {
|
||||
name string
|
||||
args string
|
||||
@ -214,11 +205,6 @@ func TestCmdInitConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdInitCertPhaseCSR(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
baseName string
|
||||
@ -279,11 +265,6 @@ func TestCmdInitCertPhaseCSR(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdInitAPIPort(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
initTest := []struct {
|
||||
name string
|
||||
args string
|
||||
@ -339,11 +320,6 @@ func TestCmdInitAPIPort(t *testing.T) {
|
||||
func TestCmdInitFeatureGates(t *testing.T) {
|
||||
const PanicExitcode = 2
|
||||
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
initTest := []struct {
|
||||
name string
|
||||
args string
|
||||
|
@ -26,11 +26,6 @@ func kubeadmReset() error {
|
||||
}
|
||||
|
||||
func TestCmdJoinConfig(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -59,11 +54,6 @@ func TestCmdJoinConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinDiscoveryFile(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -92,11 +82,6 @@ func TestCmdJoinDiscoveryFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinDiscoveryToken(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -125,11 +110,6 @@ func TestCmdJoinDiscoveryToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinNodeName(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -157,11 +137,6 @@ func TestCmdJoinNodeName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinTLSBootstrapToken(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -190,11 +165,6 @@ func TestCmdJoinTLSBootstrapToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinToken(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -223,11 +193,6 @@ func TestCmdJoinToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinBadArgs(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
var initTest = []struct {
|
||||
name string
|
||||
@ -256,11 +221,6 @@ func TestCmdJoinBadArgs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdJoinArgsMixed(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
|
@ -17,10 +17,6 @@ limitations under the License.
|
||||
package kubeadm
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
@ -29,25 +25,8 @@ const (
|
||||
TokenExpectedRegex = "^\\S{6}\\.\\S{16}\n$"
|
||||
)
|
||||
|
||||
var kubeadmPathFlag = flag.String("kubeadm-path", filepath.Join(os.Getenv("KUBE_ROOT"), "cluster/kubeadm.sh"), "Location of kubeadm")
|
||||
|
||||
func getKubeadmPath() string {
|
||||
kubeadmPath := *kubeadmPathFlag // TEST_SRCDIR is provided by Bazel.
|
||||
if srcDir := os.Getenv("TEST_SRCDIR"); srcDir != "" {
|
||||
kubeadmPath = path.Join(srcDir, os.Getenv("TEST_WORKSPACE"), kubeadmPath)
|
||||
}
|
||||
|
||||
return kubeadmPath
|
||||
}
|
||||
|
||||
var kubeadmCmdSkip = flag.Bool("kubeadm-cmd-skip", false, "Skip kubeadm cmd tests")
|
||||
|
||||
func TestCmdTokenGenerate(t *testing.T) {
|
||||
kubeadmPath := getKubeadmPath()
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
stdout, _, _, err := RunCmd(kubeadmPath, "token", "generate")
|
||||
if err != nil {
|
||||
t.Fatalf("'kubeadm token generate' exited uncleanly: %v", err)
|
||||
@ -72,11 +51,6 @@ func TestCmdTokenGenerateTypoError(t *testing.T) {
|
||||
with a non-zero status code after showing the command's usage, so that
|
||||
the usage itself isn't captured as a token without the user noticing.
|
||||
*/
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
_, _, _, err := RunCmd(kubeadmPath, "token", "genorate") // subtle typo
|
||||
if err == nil {
|
||||
@ -84,11 +58,6 @@ func TestCmdTokenGenerateTypoError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestCmdTokenDelete(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
name string
|
||||
args string
|
||||
|
@ -18,6 +18,7 @@ package kubeadm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
@ -79,3 +80,13 @@ func getSubCommand(t *testing.T, subCmds []*cobra.Command, name string) *cobra.C
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getKubeadmPath returns the contents of the environment variable KUBEADM_PATH
|
||||
// or panics if it's empty
|
||||
func getKubeadmPath() string {
|
||||
kubeadmPath := os.Getenv("KUBEADM_PATH")
|
||||
if len(kubeadmPath) == 0 {
|
||||
panic("the environment variable KUBEADM_PATH must point to the kubeadm binary path")
|
||||
}
|
||||
return kubeadmPath
|
||||
}
|
||||
|
@ -34,11 +34,6 @@ var (
|
||||
)
|
||||
|
||||
func TestCmdVersion(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var versionTest = []struct {
|
||||
name string
|
||||
args string
|
||||
@ -78,11 +73,6 @@ func TestCmdVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCmdVersionOutputJsonOrYaml(t *testing.T) {
|
||||
if *kubeadmCmdSkip {
|
||||
t.Log("kubeadm cmd tests being skipped")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var versionTest = []struct {
|
||||
name string
|
||||
args string
|
||||
|
@ -122,7 +122,15 @@ __EOF__
|
||||
WHAT=${WHAT:-}
|
||||
if [[ ${WHAT} == "" || ${WHAT} =~ .*kubeadm.* ]] ; then
|
||||
kube::log::status "Running kubeadm tests"
|
||||
run_kubeadm_tests
|
||||
|
||||
# build kubeadm
|
||||
make all -C "${KUBE_ROOT}" WHAT=cmd/kubeadm
|
||||
# unless the user sets KUBEADM_PATH, assume that "make all..." just built it
|
||||
export KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/_output/local/go/bin/kubeadm}"
|
||||
# invoke the tests
|
||||
make -C "${KUBE_ROOT}" test \
|
||||
WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd
|
||||
|
||||
# if we ONLY want to run kubeadm, then exit here.
|
||||
if [[ ${WHAT} == "kubeadm" ]]; then
|
||||
kube::log::status "TESTS PASSED"
|
||||
|
@ -1,36 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2016 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
|
||||
|
||||
run_kubeadm_tests() {
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/cluster/kubeadm.sh}"
|
||||
|
||||
# If testing a different version of kubeadm than the current build, you can
|
||||
# comment this out to save yourself from needlessly building here.
|
||||
make -C "${KUBE_ROOT}" WHAT=cmd/kubeadm
|
||||
|
||||
make -C "${KUBE_ROOT}" test \
|
||||
WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd \
|
||||
KUBE_TEST_ARGS="--kubeadm-path '${KUBEADM_PATH}'"
|
||||
set +o nounset
|
||||
set +o errexit
|
||||
}
|
@ -41,7 +41,6 @@ source "${KUBE_ROOT}/test/cmd/discovery.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/exec.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/generic-resources.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/get.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/kubeadm.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/kubeconfig.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/node-management.sh"
|
||||
source "${KUBE_ROOT}/test/cmd/plugins.sh"
|
||||
|
Loading…
Reference in New Issue
Block a user