Skip to content

Commit 1634d9c

Browse files
authored
Merge pull request kubernetes#89982 from neolit123/1.19-fix-kubeadm-integration-tests
cleanup the kubeadm integration tests and related scripts
2 parents 7b20442 + a185026 commit 1634d9c

File tree

12 files changed

+30
-199
lines changed

12 files changed

+30
-199
lines changed

cluster/kubeadm.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

cmd/kubeadm/app/cmd/init.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,10 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
357357
// if dry running creates a temporary folder for saving kubeadm generated files
358358
dryRunDir := ""
359359
if options.dryRun {
360-
if dryRunDir, err = kubeadmconstants.CreateTempDirForKubeadm("", "kubeadm-init-dryrun"); err != nil {
360+
// the KUBEADM_INIT_DRYRUN_DIR environment variable allows overriding the dry-run temporary
361+
// directory from the command line. This makes it possible to run "kubeadm init" integration
362+
// tests without root.
363+
if dryRunDir, err = kubeadmconstants.CreateTempDirForKubeadm(os.Getenv("KUBEADM_INIT_DRYRUN_DIR"), "kubeadm-init-dryrun"); err != nil {
361364
return nil, errors.Wrap(err, "couldn't create a temporary directory")
362365
}
363366
}

cmd/kubeadm/test/cmd/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ go_test(
2525
"token_test.go",
2626
"version_test.go",
2727
],
28-
args = ["--kubeadm-path=$(location //cmd/kubeadm:kubeadm)"],
2928
data = ["//cmd/kubeadm"] + glob(["testdata/**"]),
3029
embed = [":go_default_library"],
3130
tags = [

cmd/kubeadm/test/cmd/completion_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ import "testing"
2020

2121
func TestCmdCompletion(t *testing.T) {
2222
kubeadmPath := getKubeadmPath()
23-
24-
if *kubeadmCmdSkip {
25-
t.Log("kubeadm cmd tests being skipped")
26-
t.Skip()
27-
}
28-
2923
var tests = []struct {
3024
name string
3125
args string

cmd/kubeadm/test/cmd/init_test.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package kubeadm
1818

1919
import (
20+
"fmt"
21+
"os"
2022
"os/exec"
2123
"strings"
2224
"testing"
@@ -30,18 +32,17 @@ import (
3032
)
3133

3234
func runKubeadmInit(args ...string) (string, string, int, error) {
35+
const dryRunDir = "KUBEADM_INIT_DRYRUN_DIR"
36+
if err := os.Setenv(dryRunDir, os.TempDir()); err != nil {
37+
panic(fmt.Sprintf("could not set the %s environment variable", dryRunDir))
38+
}
3339
kubeadmPath := getKubeadmPath()
3440
kubeadmArgs := []string{"init", "--dry-run", "--ignore-preflight-errors=all"}
3541
kubeadmArgs = append(kubeadmArgs, args...)
3642
return RunCmd(kubeadmPath, kubeadmArgs...)
3743
}
3844

3945
func TestCmdInitToken(t *testing.T) {
40-
if *kubeadmCmdSkip {
41-
t.Log("kubeadm cmd tests being skipped")
42-
t.Skip()
43-
}
44-
4546
initTest := []struct {
4647
name string
4748
args string
@@ -86,11 +87,6 @@ func TestCmdInitToken(t *testing.T) {
8687
}
8788

8889
func TestCmdInitKubernetesVersion(t *testing.T) {
89-
if *kubeadmCmdSkip {
90-
t.Log("kubeadm cmd tests being skipped")
91-
t.Skip()
92-
}
93-
9490
initTest := []struct {
9591
name string
9692
args string
@@ -130,11 +126,6 @@ func TestCmdInitKubernetesVersion(t *testing.T) {
130126
}
131127

132128
func TestCmdInitConfig(t *testing.T) {
133-
if *kubeadmCmdSkip {
134-
t.Log("kubeadm cmd tests being skipped")
135-
t.Skip()
136-
}
137-
138129
initTest := []struct {
139130
name string
140131
args string
@@ -214,11 +205,6 @@ func TestCmdInitConfig(t *testing.T) {
214205
}
215206

216207
func TestCmdInitCertPhaseCSR(t *testing.T) {
217-
if *kubeadmCmdSkip {
218-
t.Log("kubeadm cmd tests being skipped")
219-
t.Skip()
220-
}
221-
222208
tests := []struct {
223209
name string
224210
baseName string
@@ -279,11 +265,6 @@ func TestCmdInitCertPhaseCSR(t *testing.T) {
279265
}
280266

281267
func TestCmdInitAPIPort(t *testing.T) {
282-
if *kubeadmCmdSkip {
283-
t.Log("kubeadm cmd tests being skipped")
284-
t.Skip()
285-
}
286-
287268
initTest := []struct {
288269
name string
289270
args string
@@ -339,11 +320,6 @@ func TestCmdInitAPIPort(t *testing.T) {
339320
func TestCmdInitFeatureGates(t *testing.T) {
340321
const PanicExitcode = 2
341322

342-
if *kubeadmCmdSkip {
343-
t.Log("kubeadm cmd tests being skipped")
344-
t.Skip()
345-
}
346-
347323
initTest := []struct {
348324
name string
349325
args string

cmd/kubeadm/test/cmd/join_test.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ func kubeadmReset() error {
2626
}
2727

2828
func TestCmdJoinConfig(t *testing.T) {
29-
if *kubeadmCmdSkip {
30-
t.Log("kubeadm cmd tests being skipped")
31-
t.Skip()
32-
}
33-
3429
var initTest = []struct {
3530
name string
3631
args string
@@ -59,11 +54,6 @@ func TestCmdJoinConfig(t *testing.T) {
5954
}
6055

6156
func TestCmdJoinDiscoveryFile(t *testing.T) {
62-
if *kubeadmCmdSkip {
63-
t.Log("kubeadm cmd tests being skipped")
64-
t.Skip()
65-
}
66-
6757
var initTest = []struct {
6858
name string
6959
args string
@@ -92,11 +82,6 @@ func TestCmdJoinDiscoveryFile(t *testing.T) {
9282
}
9383

9484
func TestCmdJoinDiscoveryToken(t *testing.T) {
95-
if *kubeadmCmdSkip {
96-
t.Log("kubeadm cmd tests being skipped")
97-
t.Skip()
98-
}
99-
10085
var initTest = []struct {
10186
name string
10287
args string
@@ -125,11 +110,6 @@ func TestCmdJoinDiscoveryToken(t *testing.T) {
125110
}
126111

127112
func TestCmdJoinNodeName(t *testing.T) {
128-
if *kubeadmCmdSkip {
129-
t.Log("kubeadm cmd tests being skipped")
130-
t.Skip()
131-
}
132-
133113
var initTest = []struct {
134114
name string
135115
args string
@@ -157,11 +137,6 @@ func TestCmdJoinNodeName(t *testing.T) {
157137
}
158138

159139
func TestCmdJoinTLSBootstrapToken(t *testing.T) {
160-
if *kubeadmCmdSkip {
161-
t.Log("kubeadm cmd tests being skipped")
162-
t.Skip()
163-
}
164-
165140
var initTest = []struct {
166141
name string
167142
args string
@@ -190,11 +165,6 @@ func TestCmdJoinTLSBootstrapToken(t *testing.T) {
190165
}
191166

192167
func TestCmdJoinToken(t *testing.T) {
193-
if *kubeadmCmdSkip {
194-
t.Log("kubeadm cmd tests being skipped")
195-
t.Skip()
196-
}
197-
198168
var initTest = []struct {
199169
name string
200170
args string
@@ -223,11 +193,6 @@ func TestCmdJoinToken(t *testing.T) {
223193
}
224194

225195
func TestCmdJoinBadArgs(t *testing.T) {
226-
if *kubeadmCmdSkip {
227-
t.Log("kubeadm cmd tests being skipped")
228-
t.Skip()
229-
}
230-
231196
kubeadmPath := getKubeadmPath()
232197
var initTest = []struct {
233198
name string
@@ -256,11 +221,6 @@ func TestCmdJoinBadArgs(t *testing.T) {
256221
}
257222

258223
func TestCmdJoinArgsMixed(t *testing.T) {
259-
if *kubeadmCmdSkip {
260-
t.Log("kubeadm cmd tests being skipped")
261-
t.Skip()
262-
}
263-
264224
var initTest = []struct {
265225
name string
266226
args string

cmd/kubeadm/test/cmd/token_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ limitations under the License.
1717
package kubeadm
1818

1919
import (
20-
"flag"
21-
"os"
22-
"path"
23-
"path/filepath"
2420
"regexp"
2521
"testing"
2622
)
@@ -29,25 +25,8 @@ const (
2925
TokenExpectedRegex = "^\\S{6}\\.\\S{16}\n$"
3026
)
3127

32-
var kubeadmPathFlag = flag.String("kubeadm-path", filepath.Join(os.Getenv("KUBE_ROOT"), "cluster/kubeadm.sh"), "Location of kubeadm")
33-
34-
func getKubeadmPath() string {
35-
kubeadmPath := *kubeadmPathFlag // TEST_SRCDIR is provided by Bazel.
36-
if srcDir := os.Getenv("TEST_SRCDIR"); srcDir != "" {
37-
kubeadmPath = path.Join(srcDir, os.Getenv("TEST_WORKSPACE"), kubeadmPath)
38-
}
39-
40-
return kubeadmPath
41-
}
42-
43-
var kubeadmCmdSkip = flag.Bool("kubeadm-cmd-skip", false, "Skip kubeadm cmd tests")
44-
4528
func TestCmdTokenGenerate(t *testing.T) {
4629
kubeadmPath := getKubeadmPath()
47-
if *kubeadmCmdSkip {
48-
t.Log("kubeadm cmd tests being skipped")
49-
t.Skip()
50-
}
5130
stdout, _, _, err := RunCmd(kubeadmPath, "token", "generate")
5231
if err != nil {
5332
t.Fatalf("'kubeadm token generate' exited uncleanly: %v", err)
@@ -72,23 +51,13 @@ func TestCmdTokenGenerateTypoError(t *testing.T) {
7251
with a non-zero status code after showing the command's usage, so that
7352
the usage itself isn't captured as a token without the user noticing.
7453
*/
75-
if *kubeadmCmdSkip {
76-
t.Log("kubeadm cmd tests being skipped")
77-
t.Skip()
78-
}
79-
8054
kubeadmPath := getKubeadmPath()
8155
_, _, _, err := RunCmd(kubeadmPath, "token", "genorate") // subtle typo
8256
if err == nil {
8357
t.Error("'kubeadm token genorate' (a deliberate typo) exited without an error when we expected non-zero exit status")
8458
}
8559
}
8660
func TestCmdTokenDelete(t *testing.T) {
87-
if *kubeadmCmdSkip {
88-
t.Log("kubeadm cmd tests being skipped")
89-
t.Skip()
90-
}
91-
9261
var tests = []struct {
9362
name string
9463
args string

cmd/kubeadm/test/cmd/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package kubeadm
1818

1919
import (
2020
"bytes"
21+
"os"
2122
"os/exec"
2223
"testing"
2324

@@ -79,3 +80,13 @@ func getSubCommand(t *testing.T, subCmds []*cobra.Command, name string) *cobra.C
7980

8081
return nil
8182
}
83+
84+
// getKubeadmPath returns the contents of the environment variable KUBEADM_PATH
85+
// or panics if it's empty
86+
func getKubeadmPath() string {
87+
kubeadmPath := os.Getenv("KUBEADM_PATH")
88+
if len(kubeadmPath) == 0 {
89+
panic("the environment variable KUBEADM_PATH must point to the kubeadm binary path")
90+
}
91+
return kubeadmPath
92+
}

cmd/kubeadm/test/cmd/version_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ var (
3434
)
3535

3636
func TestCmdVersion(t *testing.T) {
37-
if *kubeadmCmdSkip {
38-
t.Log("kubeadm cmd tests being skipped")
39-
t.Skip()
40-
}
41-
4237
var versionTest = []struct {
4338
name string
4439
args string
@@ -78,11 +73,6 @@ func TestCmdVersion(t *testing.T) {
7873
}
7974

8075
func TestCmdVersionOutputJsonOrYaml(t *testing.T) {
81-
if *kubeadmCmdSkip {
82-
t.Log("kubeadm cmd tests being skipped")
83-
t.Skip()
84-
}
85-
8676
var versionTest = []struct {
8777
name string
8878
args string

hack/make-rules/test-cmd.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,15 @@ __EOF__
122122
WHAT=${WHAT:-}
123123
if [[ ${WHAT} == "" || ${WHAT} =~ .*kubeadm.* ]] ; then
124124
kube::log::status "Running kubeadm tests"
125-
run_kubeadm_tests
125+
126+
# build kubeadm
127+
make all -C "${KUBE_ROOT}" WHAT=cmd/kubeadm
128+
# unless the user sets KUBEADM_PATH, assume that "make all..." just built it
129+
export KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/_output/local/go/bin/kubeadm}"
130+
# invoke the tests
131+
make -C "${KUBE_ROOT}" test \
132+
WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd
133+
126134
# if we ONLY want to run kubeadm, then exit here.
127135
if [[ ${WHAT} == "kubeadm" ]]; then
128136
kube::log::status "TESTS PASSED"

0 commit comments

Comments
 (0)