Skip to content

Commit 323340c

Browse files
committed
Add node label integration test
1 parent 5999b69 commit 323340c

6 files changed

+70
-11
lines changed

integration/add_worker.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import (
99
. "github.com/onsi/ginkgo"
1010
)
1111

12-
func addWorkerToCluster(newWorker NodeDeets, sshKey string) error {
12+
func addWorkerToCluster(newWorker NodeDeets, sshKey string, labels []string) error {
1313
By("Adding new worker")
1414
cmd := exec.Command("./kismatic", "install", "add-worker", "-f", "kismatic-testing.yaml", newWorker.Hostname, newWorker.PublicIP, newWorker.PrivateIP)
15+
if len(labels) > 0 {
16+
cmd.Args = append(cmd.Args, "--labels", strings.Join(labels, ","))
17+
}
1518
cmd.Stdout = os.Stdout
1619
cmd.Stderr = os.Stderr
1720
if err := cmd.Run(); err != nil {

integration/hosts_file_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var _ = Describe("hosts file modification feature", func() {
5151
FailIfError(err)
5252

5353
By("Adding a worker with a bogus hostname that is added to hosts files")
54-
err = addWorkerToCluster(nodes.worker[3], sshKey)
54+
err = addWorkerToCluster(nodes.worker[3], sshKey, []string{})
5555
FailIfError(err)
5656
})
5757
})

integration/install_test.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ var _ = Describe("kismatic", func() {
234234

235235
sub.It("should allow adding a worker node", func() error {
236236
newWorker := allWorkers[len(allWorkers)-1]
237-
return addWorkerToCluster(newWorker, sshKey)
237+
return addWorkerToCluster(newWorker, sshKey, []string{"com.integrationtest/worker=true"})
238238
})
239239

240240
sub.It("should be able to deploy a workload with ingress", func() error {
@@ -257,6 +257,10 @@ var _ = Describe("kismatic", func() {
257257
sub.It("should have tiller running", func() error {
258258
return verifyTiller(nodes.master[0], sshKey)
259259
})
260+
261+
sub.It("nodes should contain expected labels", func() error {
262+
return containsLabels(nodes, sshKey)
263+
})
260264
})
261265
})
262266
})
@@ -284,7 +288,7 @@ var _ = Describe("kismatic", func() {
284288

285289
sub.It("should allow adding a worker node", func() error {
286290
newWorker := allWorkers[len(allWorkers)-1]
287-
return addWorkerToCluster(newWorker, sshKey)
291+
return addWorkerToCluster(newWorker, sshKey, []string{"com.integrationtest/worker=true"})
288292
})
289293

290294
sub.It("should be able to deploy a workload with ingress", func() error {
@@ -307,6 +311,10 @@ var _ = Describe("kismatic", func() {
307311
sub.It("should have tiller running", func() error {
308312
return verifyTiller(nodes.master[0], sshKey)
309313
})
314+
315+
sub.It("nodes should contain expected labels", func() error {
316+
return containsLabels(nodes, sshKey)
317+
})
310318
})
311319
})
312320
})
@@ -334,7 +342,7 @@ var _ = Describe("kismatic", func() {
334342

335343
// sub.It("should allow adding a worker node", func() error {
336344
// newWorker := allWorkers[len(allWorkers)-1]
337-
// return addWorkerToCluster(newWorker, sshKey)
345+
// return addWorkerToCluster(newWorker, sshKey, []string{})
338346
// })
339347

340348
// // This test is flaky with contiv

integration/labels.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package integration
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func containsLabels(nodes provisionedNodes, sshKey string) error {
9+
// labels were hardcoded in th plan pattern
10+
tests := []struct {
11+
nodes []NodeDeets
12+
label string
13+
}{
14+
{
15+
nodes: nodes.master,
16+
label: "com.integrationtest/master:true",
17+
},
18+
{
19+
nodes: nodes.worker,
20+
label: "com.integrationtest/worker:true",
21+
},
22+
{
23+
nodes: nodes.ingress,
24+
label: "com.integrationtest/ingress:true",
25+
},
26+
{
27+
nodes: nodes.storage,
28+
label: "com.integrationtest/storage:true",
29+
},
30+
}
31+
for _, role := range tests {
32+
for _, n := range role.nodes {
33+
if err := runViaSSH([]string{fmt.Sprintf("sudo kubectl get nodes %s -o jsonpath='{.metadata.labels}' | grep %q", n.Hostname, role.label)}, []NodeDeets{nodes.master[0]}, sshKey, 1*time.Minute); err != nil {
34+
return fmt.Errorf("error validating node %q label: %v", n.Hostname, err)
35+
}
36+
}
37+
}
38+
39+
return nil
40+
}

integration/plan_patterns.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,35 @@ master:
108108
nodes:{{range .Master}}
109109
- host: {{.Hostname}}
110110
ip: {{.PublicIP}}
111-
internalip: {{.PrivateIP}}{{end}}
111+
internalip: {{.PrivateIP}}
112+
labels:
113+
com.integrationtest/master: true{{end}}
112114
load_balanced_fqdn: {{.MasterNodeFQDN}}
113115
load_balanced_short_name: {{.MasterNodeShortName}}
114116
worker:
115117
expected_count: {{len .Worker}}
116118
nodes:{{range .Worker}}
117119
- host: {{.Hostname}}
118120
ip: {{.PublicIP}}
119-
internalip: {{.PrivateIP}}{{end}}
121+
internalip: {{.PrivateIP}}
122+
labels:
123+
com.integrationtest/worker: true{{end}}
120124
ingress:
121125
expected_count: {{len .Ingress}}
122126
nodes:{{range .Ingress}}
123127
- host: {{.Hostname}}
124128
ip: {{.PublicIP}}
125-
internalip: {{.PrivateIP}}{{end}}
129+
internalip: {{.PrivateIP}}
130+
labels:
131+
com.integrationtest/ingress: true{{end}}
126132
storage:
127133
expected_count: {{len .Storage}}
128134
nodes:{{range .Storage}}
129135
- host: {{.Hostname}}
130136
ip: {{.PublicIP}}
131-
internalip: {{.PrivateIP}}{{end}}
137+
internalip: {{.PrivateIP}}
138+
labels:
139+
com.integrationtest/storage: true{{end}}
132140
nfs:
133141
nfs_volume:{{range .NFSVolume}}
134142
- nfs_host: {{.Host}}

integration/upgrade_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var _ = Describe("Upgrade", func() {
6464

6565
sub.It("should allow adding a worker node", func() error {
6666
newWorker := allWorkers[len(allWorkers)-1]
67-
return addWorkerToCluster(newWorker, sshKey)
67+
return addWorkerToCluster(newWorker, sshKey, []string{})
6868
})
6969

7070
sub.It("should be able to deploy a workload with ingress", func() error {
@@ -248,7 +248,7 @@ var _ = Describe("Upgrade", func() {
248248

249249
sub.It("should allow adding a worker node", func() error {
250250
newWorker := allWorkers[len(allWorkers)-1]
251-
return addWorkerToCluster(newWorker, sshKey)
251+
return addWorkerToCluster(newWorker, sshKey, []string{})
252252
})
253253

254254
sub.It("should be able to deploy a workload with ingress", func() error {

0 commit comments

Comments
 (0)