This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
/
kubernetes_test.go
2134 lines (1980 loc) · 101 KB
/
kubernetes_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//+build test
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package kubernetes
import (
"bufio"
"fmt"
"io"
"log"
"math/rand"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
"time"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/aks-engine/pkg/api"
"github.com/Azure/aks-engine/pkg/api/common"
"github.com/Azure/aks-engine/test/e2e/config"
"github.com/Azure/aks-engine/test/e2e/engine"
"github.com/Azure/aks-engine/test/e2e/kubernetes/deployment"
"github.com/Azure/aks-engine/test/e2e/kubernetes/event"
"github.com/Azure/aks-engine/test/e2e/kubernetes/hpa"
"github.com/Azure/aks-engine/test/e2e/kubernetes/job"
"github.com/Azure/aks-engine/test/e2e/kubernetes/namespace"
"github.com/Azure/aks-engine/test/e2e/kubernetes/networkpolicy"
"github.com/Azure/aks-engine/test/e2e/kubernetes/node"
"github.com/Azure/aks-engine/test/e2e/kubernetes/persistentvolume"
"github.com/Azure/aks-engine/test/e2e/kubernetes/persistentvolumeclaims"
"github.com/Azure/aks-engine/test/e2e/kubernetes/pod"
"github.com/Azure/aks-engine/test/e2e/kubernetes/service"
"github.com/Azure/aks-engine/test/e2e/kubernetes/storageclass"
"github.com/Azure/aks-engine/test/e2e/kubernetes/util"
"github.com/Azure/aks-engine/test/e2e/remote"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const (
WorkloadDir = "workloads"
PolicyDir = "workloads/policies"
retryCommandsTimeout = 5 * time.Minute
kubeSystemPodsReadinessChecks = 6
sleepBetweenRetriesWhenWaitingForPodReady = 1 * time.Second
sleepBetweenRetriesRemoteSSHCommand = 3 * time.Second
timeoutWhenWaitingForPodOutboundAccess = 1 * time.Minute
stabilityCommandTimeout = 3 * time.Second
singleCommandTimeout = 1 * time.Minute
validateNetworkPolicyTimeout = 3 * time.Minute
validateDNSTimeout = 2 * time.Minute
firstMasterRegexStr = "^k8s-master-"
podLookupRetries = 5
)
var (
cfg config.Config
eng engine.Engine
masterSSHPort string
masterSSHPrivateKeyFilepath string
longRunningApacheDeploymentName string
sshConn *remote.Connection
kubeConfig *Config
firstMasterRegexp *regexp.Regexp
masterNodes []node.Node
clusterAutoscalerEngaged bool
clusterAutoscalerAddon api.KubernetesAddon
deploymentReplicasCount int
dnsAddonName string
)
var _ = BeforeSuite(func() {
cwd, _ := os.Getwd()
rootPath := filepath.Join(cwd, "../../..") // The current working dir of these tests is down a few levels from the root of the project. We should traverse up that path so we can find the _output dir
c, err := config.ParseConfig()
c.CurrentWorkingDir = rootPath
Expect(err).NotTo(HaveOccurred())
cfg = *c // We have to do this because golang anon functions and scoping and stuff
engCfg, err := engine.ParseConfig(c.CurrentWorkingDir, c.ClusterDefinition, c.Name)
Expect(err).NotTo(HaveOccurred())
csInput, err := engine.ParseInput(engCfg.ClusterDefinitionTemplate)
Expect(err).NotTo(HaveOccurred())
isUpdate := cfg.Name != ""
validate := false
csGenerated, err := engine.ParseOutput(engCfg.GeneratedDefinitionPath+"/apimodel.json", validate, isUpdate)
Expect(err).NotTo(HaveOccurred())
eng = engine.Engine{
Config: engCfg,
ClusterDefinition: csInput,
ExpandedDefinition: csGenerated,
}
longRunningApacheDeploymentName = "php-apache-long-running"
for _, profile := range eng.ExpandedDefinition.Properties.AgentPoolProfiles {
deploymentReplicasCount += profile.Count
}
if !cfg.BlockSSHPort {
var err error
masterNodes, err = node.GetByRegexWithRetry("^k8s-master-", 3*time.Minute, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
masterName := masterNodes[0].Metadata.Name
if strings.Contains(masterName, "vmss") {
masterSSHPort = "50001"
} else {
masterSSHPort = "22"
}
masterSSHPrivateKeyFilepath = cfg.GetSSHKeyPath()
kubeConfig, err = GetConfigWithRetry(3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
sshConn, err = remote.NewConnectionWithRetry(kubeConfig.GetServerName(), masterSSHPort, eng.ExpandedDefinition.Properties.LinuxProfile.AdminUsername, masterSSHPrivateKeyFilepath, 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
success := false
for i := 0; i < 3; i++ {
sshAddErr := util.AddToSSHKeyChain(masterSSHPrivateKeyFilepath)
if sshAddErr == nil {
success = true
break
}
if i > 1 {
log.Printf("Error while setting up ssh key forwarding:%s\n", sshAddErr)
}
time.Sleep(10 * time.Second)
}
Expect(success).To(BeTrue())
firstMasterRegexp, err = regexp.Compile(firstMasterRegexStr)
Expect(err).NotTo(HaveOccurred())
if hasAddon, addon := eng.HasAddon("cluster-autoscaler"); hasAddon {
clusterAutoscalerAddon = addon
if len(addon.Pools) > 0 {
for _, pool := range addon.Pools {
p := eng.ExpandedDefinition.Properties.GetAgentPoolIndexByName(pool.Name)
maxNodes, _ := strconv.Atoi(pool.Config["max-nodes"])
minNodes, _ := strconv.Atoi(pool.Config["min-nodes"])
if maxNodes > eng.ExpandedDefinition.Properties.AgentPoolProfiles[p].Count &&
minNodes <= eng.ExpandedDefinition.Properties.AgentPoolProfiles[p].Count {
clusterAutoscalerEngaged = true
break
}
}
}
}
}
if hasAddon, _ := eng.HasAddon(common.KubeDNSAddonName); hasAddon {
dnsAddonName = common.KubeDNSAddonName
}
if hasAddon, _ := eng.HasAddon("coredns"); hasAddon {
dnsAddonName = common.CoreDNSAddonName
}
Expect(dnsAddonName).NotTo(Equal(""))
})
var _ = AfterSuite(func() {
if cfg.DebugAfterSuite {
cmd := exec.Command("k", "get", "deployments,pods,svc,daemonsets,configmaps,endpoints,jobs,clusterroles,clusterrolebindings,roles,rolebindings,storageclasses", "--all-namespaces", "-o", "wide")
out, err := cmd.CombinedOutput()
log.Printf("%s\n", out)
if err != nil {
log.Printf("Error: Unable to print all cluster resources\n")
}
pod.PrintPodsLogs("kube-addon-manager", "kube-system", 5*time.Second, 1*time.Minute)
pod.PrintPodsLogs("kube-proxy", "kube-system", 5*time.Second, 1*time.Minute)
pod.PrintPodsLogs("kube-scheduler", "kube-system", 5*time.Second, 1*time.Minute)
pod.PrintPodsLogs(common.APIServerComponentName, "kube-system", 5*time.Second, 1*time.Minute)
pod.PrintPodsLogs("kube-controller-manager", "kube-system", 5*time.Second, 1*time.Minute)
}
})
var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", func() {
Describe("regardless of agent pool type", func() {
It("should check for cluster-init pod", func() {
if cfg.ClusterInitPodName != "" {
By(fmt.Sprintf("Ensuring that cluster-init Pod \"%s\" is Running", cfg.ClusterInitPodName))
running, err := pod.WaitOnSuccesses(cfg.ClusterInitPodName, "default", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
}
if cfg.ClusterInitJobName != "" {
ready, err := job.WaitOnSucceeded(cfg.ClusterInitJobName, "default", 30*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(ready).To(Equal(true))
}
})
It("should validate host OS DNS", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else {
var nodes []node.Node
var err error
if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
nodes, err = node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
} else {
nodes = masterNodes
}
Expect(err).NotTo(HaveOccurred())
hostOSDNSValidateScript := "host-os-dns-validate.sh"
err = sshConn.CopyTo(hostOSDNSValidateScript)
Expect(err).NotTo(HaveOccurred())
envString := "NODE_HOSTNAMES='"
for _, n := range nodes {
envString += fmt.Sprintf("%s ", n.Metadata.Name)
}
lookupRetries := 3
envString += fmt.Sprintf("' LOOKUP_RETRIES=%d", lookupRetries)
hostOSDNSValidationCommand := fmt.Sprintf("%s /tmp/%s", envString, hostOSDNSValidateScript)
var success bool
// Retry for up to 5 minutes host vm DNS validation
for i := 0; i < 30; i++ {
err := sshConn.Execute(hostOSDNSValidationCommand, true)
if err == nil {
success = true
break
} else {
time.Sleep(10 * time.Second)
}
}
Expect(success).To(BeTrue())
hostOSDNSValidationCommand = fmt.Sprintf("\"%s /tmp/%s\"", envString, hostOSDNSValidateScript)
for _, n := range nodes {
if n.IsLinux() && !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+hostOSDNSValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, hostOSDNSValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
}
})
It("should validate cloudprovider config", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
var cloudproviderEnabledPrefixes []string
if eng.ExpandedDefinition.Properties.MasterProfile != nil {
cloudproviderEnabledPrefixes = append(cloudproviderEnabledPrefixes, "k8s-master-")
}
for _, profile := range eng.ExpandedDefinition.Properties.AgentPoolProfiles {
if profile.RequiresCloudproviderConfig() {
cloudproviderEnabledPrefixes = append(cloudproviderEnabledPrefixes, "k8s-"+profile.Name)
}
}
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
cloudproviderConfigValidateScript := "cloudprovider-config-validate.sh"
err = sshConn.CopyTo(cloudproviderConfigValidateScript)
Expect(err).NotTo(HaveOccurred())
envString := fmt.Sprintf("BACKOFF_MODE=%s", eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.CloudProviderBackoffMode)
// TODO test remaining cloudprovider config
cloudproviderConfigValidationCommand := fmt.Sprintf("%s /tmp/%s", envString, cloudproviderConfigValidateScript)
err = sshConn.Execute(cloudproviderConfigValidationCommand, false)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if n.IsUbuntu() && !firstMasterRegexp.MatchString(n.Metadata.Name) && n.HasSubstring(cloudproviderEnabledPrefixes) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+cloudproviderConfigValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, cloudproviderConfigValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should have the expected k8s version", func() {
if eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.CustomHyperkubeImage == "" &&
eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.CustomWindowsPackageURL == "" {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
err := n.Describe()
if err != nil {
log.Printf("Unable to describe node %s: %s", n.Metadata.Name, err)
}
Expect("v" + eng.ExpandedDefinition.Properties.OrchestratorProfile.OrchestratorVersion).To(Equal(n.Version()))
}
} else {
Skip("This is a cluster built from source")
}
})
It("should display the installed Ubuntu version on the master node", func() {
if !eng.ExpandedDefinition.Properties.MasterProfile.IsUbuntu() {
Skip("This is not an ubuntu master")
} else if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else {
lsbReleaseCmd := fmt.Sprintf("lsb_release -a && uname -r")
err := sshConn.Execute(lsbReleaseCmd, true)
Expect(err).NotTo(HaveOccurred())
kernelVerCmd := fmt.Sprintf("cat /proc/version")
err = sshConn.Execute(kernelVerCmd, true)
Expect(err).NotTo(HaveOccurred())
}
})
It("should display the installed docker runtime on all nodes", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.RequiresDocker() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
dockerVersionCmd := fmt.Sprintf("\"docker version\"")
for _, n := range nodes {
if n.IsWindows() {
if eng.ExpandedDefinition.Properties.WindowsProfile != nil && !eng.ExpandedDefinition.Properties.WindowsProfile.SSHEnabled {
log.Printf("Can't ssh into Windows node %s because there is no SSH listener", n.Metadata.Name)
continue
}
}
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, dockerVersionCmd, true, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
} else {
Skip("Skip docker validations on non-docker-backed clusters")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate that every linux node has a root password", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.IsVHDDistroForAllNodes() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
rootPasswdCmd := fmt.Sprintf("\"sudo grep '^root:[!*]:' /etc/shadow\" && exit 1 || exit 0")
for _, n := range nodes {
if n.IsUbuntu() {
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, rootPasswdCmd, true, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("This config is only available on VHD")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate aks-engine-provided sysctl configuration", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
for key, val := range eng.ExpandedDefinition.Properties.MasterProfile.SysctlDConfig {
for _, n := range nodes {
if n.HasSubstring([]string{"k8s-master"}) && n.IsUbuntu() {
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, fmt.Sprintf("sysctl %s | grep '= %s'", key, val), false, sleepBetweenRetriesRemoteSSHCommand, singleCommandTimeout)
Expect(err).NotTo(HaveOccurred())
}
}
}
for _, pool := range eng.ExpandedDefinition.Properties.AgentPoolProfiles {
for key, val := range pool.SysctlDConfig {
for _, n := range nodes {
if n.HasSubstring([]string{pool.Name}) && n.IsUbuntu() {
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, fmt.Sprintf("sysctl %s | grep '= %s'", key, val), false, sleepBetweenRetriesRemoteSSHCommand, singleCommandTimeout)
Expect(err).NotTo(HaveOccurred())
}
}
}
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate Ubuntu host OS network configuration on all nodes", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.IsVHDDistroForAllNodes() {
var largeSKUPrefixes []string
if eng.ExpandedDefinition.Properties.MasterProfile != nil {
if util.IsLargeVMSKU(eng.ExpandedDefinition.Properties.MasterProfile.VMSize) {
largeSKUPrefixes = append(largeSKUPrefixes, "k8s-master-")
}
}
for _, profile := range eng.ExpandedDefinition.Properties.AgentPoolProfiles {
if util.IsLargeVMSKU(profile.VMSize) {
largeSKUPrefixes = append(largeSKUPrefixes, "k8s-"+profile.Name)
}
}
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
netConfigValidateScript := "net-config-validate.sh"
err = sshConn.CopyTo(netConfigValidateScript)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
var gt8CoreSKU string
if n.HasSubstring(largeSKUPrefixes) && n.IsUbuntu() {
gt8CoreSKU = "true"
}
netConfigValidationCommand := fmt.Sprintf("\"GT_8_CORE_SKU=%s /tmp/%s\"", gt8CoreSKU, netConfigValidateScript)
if n.IsUbuntu() && !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+netConfigValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, netConfigValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("This config is only available on VHD")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate all CIS VHD-paved files", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.IsVHDDistroForAllNodes() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
CISFilesValidateScript := "CIS-files-validate.sh"
err = sshConn.CopyTo(CISFilesValidateScript)
Expect(err).NotTo(HaveOccurred())
CISValidationCommand := fmt.Sprintf("\"/tmp/%s\"", CISFilesValidateScript)
err = sshConn.Execute(CISValidationCommand, false)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+CISFilesValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, CISValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
fmt.Println(err)
}
}
} else {
Skip("This config is only available on VHD")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate kernel module configuration", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.IsVHDDistroForAllNodes() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
modprobeConfigValidateScript := "modprobe-config-validate.sh"
err = sshConn.CopyTo(modprobeConfigValidateScript)
Expect(err).NotTo(HaveOccurred())
netConfigValidationCommand := fmt.Sprintf("\"/tmp/%s\"", modprobeConfigValidateScript)
err = sshConn.Execute(netConfigValidationCommand, false)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if n.IsUbuntu() && !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+modprobeConfigValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, netConfigValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("This config is only available on VHD")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate installed software packages", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
installedPackagesValidateScript := "ubuntu-installed-packages-validate.sh"
err = sshConn.CopyTo(installedPackagesValidateScript)
Expect(err).NotTo(HaveOccurred())
installedPackagesValidationCommand := fmt.Sprintf("\"/tmp/%s\"", installedPackagesValidateScript)
err = sshConn.Execute(installedPackagesValidationCommand, false)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if n.IsUbuntu() && !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+installedPackagesValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, installedPackagesValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate that every linux node has the right sshd config", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.IsVHDDistroForAllNodes() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
sshdConfigValidateScript := "sshd-config-validate.sh"
err = sshConn.CopyTo(sshdConfigValidateScript)
Expect(err).NotTo(HaveOccurred())
sshdConfigValidationCommand := fmt.Sprintf("\"/tmp/%s\"", sshdConfigValidateScript)
err = sshConn.Execute(sshdConfigValidationCommand, false)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if n.IsUbuntu() && !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+sshdConfigValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, sshdConfigValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("This config is only available on VHD")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate password enforcement configuration", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() {
if eng.ExpandedDefinition.Properties.IsVHDDistroForAllNodes() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
pwQualityValidateScript := "pwquality-validate.sh"
err = sshConn.CopyTo(pwQualityValidateScript)
Expect(err).NotTo(HaveOccurred())
pwQualityValidationCommand := fmt.Sprintf("\"/tmp/%s\"", pwQualityValidateScript)
err = sshConn.Execute(pwQualityValidationCommand, false)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if n.IsUbuntu() && !firstMasterRegexp.MatchString(n.Metadata.Name) {
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+pwQualityValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, pwQualityValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
Skip("This config is only available on VHD")
}
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should validate auditd configuration", func() {
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
} else {
var auditDNodePrefixes []string
var nonRegularPriVMSSPrefixes []string
if eng.ExpandedDefinition.Properties.MasterProfile != nil {
if to.Bool(eng.ExpandedDefinition.Properties.MasterProfile.AuditDEnabled) {
auditDNodePrefixes = append(auditDNodePrefixes, "k8s-master-")
}
}
for _, profile := range eng.ExpandedDefinition.Properties.AgentPoolProfiles {
if profile.IsLowPriorityScaleSet() || profile.IsSpotScaleSet() {
nonRegularPriVMSSPrefixes = append(nonRegularPriVMSSPrefixes, "k8s-"+profile.Name)
} else if to.Bool(profile.AuditDEnabled) {
auditDNodePrefixes = append(auditDNodePrefixes, profile.Name)
}
}
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
auditdValidateScript := "auditd-validate.sh"
err = sshConn.CopyTo(auditdValidateScript)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if !n.HasSubstring(nonRegularPriVMSSPrefixes) && n.IsUbuntu() {
var enabled bool
if n.HasSubstring(auditDNodePrefixes) {
enabled = true
}
err := sshConn.CopyToRemoteWithRetry(n.Metadata.Name, "/tmp/"+auditdValidateScript, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
auditdValidationCommand := fmt.Sprintf("\"ENABLED=%t /tmp/%s\"", enabled, auditdValidateScript)
err = sshConn.ExecuteRemoteWithRetry(n.Metadata.Name, auditdValidationCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
}
}
}
})
It("should report all nodes in a Ready state", func() {
var expectedReadyNodes int
if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() &&
!clusterAutoscalerEngaged &&
cfg.AddNodePoolInput == "" {
expectedReadyNodes = eng.NodeCount()
log.Printf("Checking for %d Ready nodes\n", expectedReadyNodes)
} else {
expectedReadyNodes = -1
}
ready := node.WaitOnReady(expectedReadyNodes, 10*time.Second, cfg.Timeout)
cmd := exec.Command("k", "get", "nodes", "-o", "wide")
out, _ := cmd.CombinedOutput()
log.Printf("%s\n", out)
Expect(ready).To(Equal(true))
})
It("should have node labels and annotations added by E2E test runner", func() {
if !eng.ExpandedDefinition.Properties.HasNonRegularPriorityScaleset() &&
cfg.AddNodePoolInput == "" {
totalNodeCount := eng.NodeCount()
nodes := totalNodeCount - len(masterNodes)
nodeList, err := node.GetByLabel("foo")
Expect(err).NotTo(HaveOccurred())
Expect(len(nodeList)).To(Equal(nodes))
nodeList, err = node.GetByAnnotations("foo", "bar")
Expect(err).NotTo(HaveOccurred())
Expect(len(nodeList)).To(Equal(nodes))
} else {
Skip("Skip per-node tests in low-priority VMSS cluster configuration scenario")
}
})
It("should have core kube-system componentry running", func() {
coreComponents := []string{
common.AddonManagerComponentName,
common.APIServerComponentName,
common.ControllerManagerComponentName,
common.KubeProxyAddonName,
common.SchedulerComponentName,
}
if to.Bool(eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager) {
coreComponents = append(coreComponents, common.CloudControllerManagerComponentName)
}
if hasAddon, _ := eng.HasAddon(common.AzureDiskCSIDriverAddonName); hasAddon {
coreComponents = append(coreComponents, "csi-azuredisk-controller", "csi-azuredisk-node")
}
if hasAddon, _ := eng.HasAddon(common.AzureFileCSIDriverAddonName); hasAddon {
coreComponents = append(coreComponents, "csi-azurefile-controller", "csi-azurefile-node")
}
if hasAddon, _ := eng.HasAddon(common.CloudNodeManagerAddonName); hasAddon {
coreComponents = append(coreComponents, common.CloudNodeManagerAddonName)
}
for _, componentName := range coreComponents {
By(fmt.Sprintf("Ensuring that %s is Running", componentName))
running, err := pod.WaitOnSuccesses(componentName, "kube-system", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
}
})
It("Should not have any unready or crashing pods right after deployment", func() {
if eng.Config.DebugCrashingPods {
By("Checking ready status of each pod in kube-system")
pods, err := pod.GetAll("kube-system")
Expect(err).NotTo(HaveOccurred())
Expect(len(pods.Pods)).ToNot(BeZero())
for _, currentPod := range pods.Pods {
log.Printf("Checking %s - ready: %t, restarts: %d", currentPod.Metadata.Name, currentPod.Status.ContainerStatuses[0].Ready, currentPod.Status.ContainerStatuses[0].RestartCount)
Expect(currentPod.Status.ContainerStatuses[0].Ready).To(BeTrue())
tooManyRestarts := 5
if strings.Contains(currentPod.Metadata.Name, "cluster-autoscaler") {
log.Print("need to investigate cluster-autoscaler restarts!")
tooManyRestarts = 10
}
Expect(currentPod.Status.ContainerStatuses[0].RestartCount).To(BeNumerically("<", tooManyRestarts))
}
} else {
Skip("Skipping this DEBUG test")
}
})
It("should print cluster resources", func() {
cmd := exec.Command("k", "get", "deployments,pods,svc,daemonsets,configmaps,endpoints,jobs,clusterroles,clusterrolebindings,roles,rolebindings,storageclasses", "--all-namespaces", "-o", "wide")
out, err := cmd.CombinedOutput()
log.Printf("%s\n", out)
if err != nil {
log.Printf("Error: Unable to print all cluster resources\n")
}
})
It("should have DNS pod running", func() {
By(fmt.Sprintf("Ensuring that %s is running", dnsAddonName))
running, err := pod.WaitOnSuccesses(dnsAddonName, "kube-system", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
pod.PrintPodsLogs(dnsAddonName, "kube-system", 5*time.Second, 1*time.Minute)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
})
It("should have functional container networking DNS", func() {
By("Ensuring that we have functional DNS resolution from a linux container")
validateDNSLinuxName := "validate-dns-linux"
validateDNSLinuxNamespace := "default"
j, err := job.CreateJobFromFileDeleteIfExists(filepath.Join(WorkloadDir, fmt.Sprintf("%s.yaml", validateDNSLinuxName)), validateDNSLinuxName, validateDNSLinuxNamespace, 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
ready, err := j.WaitOnSucceeded(sleepBetweenRetriesWhenWaitingForPodReady, validateDNSTimeout)
if err != nil {
pod.PrintPodsLogs(validateDNSLinuxName, validateDNSLinuxNamespace, 5*time.Second, 1*time.Minute)
pods, err := pod.GetAllByPrefixWithRetry(validateDNSLinuxName, validateDNSLinuxNamespace, 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
for _, p := range pods {
out, err := p.Exec("--", "cat", "/etc/resolv.conf")
log.Printf("%s\n", string(out))
Expect(err).NotTo(HaveOccurred())
out, err = p.Exec("--", "ifconfig")
log.Printf("%s\n", string(out))
Expect(err).NotTo(HaveOccurred())
out, err = p.Exec("--", "nc", "-vz", eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.DNSServiceIP, "53")
log.Printf("%s\n", string(out))
Expect(err).NotTo(HaveOccurred())
}
}
Expect(err).NotTo(HaveOccurred())
Expect(ready).To(Equal(true))
if eng.HasWindowsAgents() {
By("Ensuring that we have functional DNS resolution from a windows container")
windowsImages, imgErr := eng.GetWindowsTestImages()
Expect(imgErr).NotTo(HaveOccurred())
j, err = job.CreateWindowsJobFromTemplateDeleteIfExists(filepath.Join(WorkloadDir, "validate-dns-windows.yaml"), "validate-dns-windows", "default", windowsImages, 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
ready, err = j.WaitOnSucceeded(sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
if err != nil {
pod.PrintPodsLogs("validate-dns-windows", "default", 5*time.Second, 1*time.Minute)
}
Expect(err).NotTo(HaveOccurred())
Expect(ready).To(Equal(true))
}
By("Ensuring that we have stable external DNS resolution as we recycle a bunch of pods")
name := fmt.Sprintf("alpine-%s", cfg.Name)
command := fmt.Sprintf("nc -vz bbc.co.uk 80 || nc -vz google.com 443 || nc -vz microsoft.com 80")
deploymentCommand := fmt.Sprintf("%s && while true; do sleep 1; done || echo unable to make external connections or resolve dns", command)
// Ensure across all nodes
successes, err := deployment.RunDeploymentMultipleTimes(deployment.RunLinuxDeploy, "alpine", name, deploymentCommand, deploymentReplicasCount, cfg.StabilityIterations, 1*time.Second, timeoutWhenWaitingForPodOutboundAccess, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
successes, err = pod.RunCommandMultipleTimes(pod.RunLinuxPod, "alpine", name, command, cfg.StabilityIterations, 1*time.Second, stabilityCommandTimeout, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
})
It("should be able to launch a long-running container networking DNS liveness pod", func() {
p, err := pod.CreatePodFromFileIfNotExist(filepath.Join(WorkloadDir, "dns-liveness.yaml"), "dns-liveness", "default", 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
running, err := p.WaitOnReady(sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
})
It("should be able to launch a long running HTTP listener and svc endpoint", func() {
By("Creating a php-apache deployment")
phpApacheDeploy, err := deployment.CreateLinuxDeployIfNotExist("deis/hpa-example", longRunningApacheDeploymentName, "default", "", "")
Expect(err).NotTo(HaveOccurred())
By("Ensuring that php-apache pod is running")
running, err := pod.WaitOnSuccesses(longRunningApacheDeploymentName, "default", 4, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
By("Ensuring that the php-apache pod has outbound internet access")
pods, err := phpApacheDeploy.PodsRunning()
Expect(err).NotTo(HaveOccurred())
for _, p := range pods {
pass, outboundErr := p.CheckLinuxOutboundConnection(5*time.Second, cfg.Timeout)
Expect(outboundErr).NotTo(HaveOccurred())
Expect(pass).To(BeTrue())
}
By("Exposing TCP 80 internally on the php-apache deployment")
err = phpApacheDeploy.ExposeIfNotExist("ClusterIP", 80, 80)
Expect(err).NotTo(HaveOccurred())
})
It("should be able to schedule a pod to a master node", func() {
By("Creating a Job with master nodeSelector")
j, err := job.CreateJobFromFileDeleteIfExists(filepath.Join(WorkloadDir, "busybox-master.yaml"), "busybox-master", "default", 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
ready, err := j.WaitOnSucceeded(30*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(ready).To(Equal(true))
})
It("should be able to schedule a pod to an agent node", func() {
if eng.AnyAgentIsLinux() {
By("Creating a Job with agent nodeSelector")
j, err := job.CreateJobFromFileDeleteIfExists(filepath.Join(WorkloadDir, "busybox-agent.yaml"), "busybox-agent", "default", 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
ready, err := j.WaitOnSucceeded(30*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(ready).To(Equal(true))
} else {
Skip("agent nodeSelector test Job is currently Linux-only")
}
})
It("should have stable external container networking as we recycle a bunch of pods", func() {
// Test for basic UDP networking
name := fmt.Sprintf("alpine-%s", cfg.Name)
command := fmt.Sprintf("nc -vz 8.8.8.8 53 || nc -vz 8.8.4.4 53")
deploymentCommand := fmt.Sprintf("%s && while true; do sleep 1; done || echo unable to connect externally against known listeners", command)
// Ensure across all nodes
successes, err := deployment.RunDeploymentMultipleTimes(deployment.RunLinuxDeploy, "alpine", name, deploymentCommand, deploymentReplicasCount, cfg.StabilityIterations, 1*time.Second, timeoutWhenWaitingForPodOutboundAccess, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
// Ensure responsiveness
successes, err = pod.RunCommandMultipleTimes(pod.RunLinuxPod, "alpine", name, command, cfg.StabilityIterations, 1*time.Second, stabilityCommandTimeout, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
// Use curl to test responsive DNS lookup + TCP 443 connectivity
name = fmt.Sprintf("alpine-%s", cfg.Name)
command = fmt.Sprintf("curl --head https://www.bing.com 1> /dev/null || curl --head https://google.com 1> /dev/null || curl --head https://microsoft.com 1> /dev/null")
deploymentCommand = fmt.Sprintf("%s && while true; do sleep 1; done || echo unable to curl externally against known endpoints", command)
// Ensure across all nodes
successes, err = deployment.RunDeploymentMultipleTimes(deployment.RunLinuxDeploy, "byrnedo/alpine-curl", name, deploymentCommand, deploymentReplicasCount, cfg.StabilityIterations, 1*time.Second, timeoutWhenWaitingForPodOutboundAccess, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
// Ensure responsiveness
successes, err = pod.RunCommandMultipleTimes(pod.RunLinuxPod, "byrnedo/alpine-curl", name, command, cfg.StabilityIterations, 1*time.Second, stabilityCommandTimeout, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
})
It("should have stable internal container networking as we recycle a bunch of pods", func() {
name := fmt.Sprintf("alpine-%s", cfg.Name)
command := fmt.Sprintf("nc -vz kubernetes 443 && nc -vz kubernetes.default.svc 443 && nc -vz kubernetes.default.svc.cluster.local 443")
deploymentCommand := fmt.Sprintf("%s && while true; do sleep 1; done || echo unable to reach internal kubernetes endpoints", command)
// Ensure across all nodes
successes, err := deployment.RunDeploymentMultipleTimes(deployment.RunLinuxDeploy, "alpine", name, deploymentCommand, deploymentReplicasCount, cfg.StabilityIterations, 1*time.Second, timeoutWhenWaitingForPodOutboundAccess, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
// Ensure responsiveness
successes, err = pod.RunCommandMultipleTimes(pod.RunLinuxPod, "alpine", name, command, cfg.StabilityIterations, 1*time.Second, stabilityCommandTimeout, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
})
It("should have stable pod-to-pod networking", func() {
if eng.AnyAgentIsLinux() {
By("Creating a php-apache deployment")
phpApacheDeploy, err := deployment.CreateLinuxDeployIfNotExist("deis/hpa-example", longRunningApacheDeploymentName, "default", "", "")
Expect(err).NotTo(HaveOccurred())
By("Ensuring that php-apache pod is running")
running, err := pod.WaitOnSuccesses(longRunningApacheDeploymentName, "default", 4, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
By("Ensuring that the php-apache pod has outbound internet access")
pods, err := phpApacheDeploy.PodsRunning()
Expect(err).NotTo(HaveOccurred())
for _, p := range pods {
pass, outboundErr := p.CheckLinuxOutboundConnection(5*time.Second, cfg.Timeout)
Expect(outboundErr).NotTo(HaveOccurred())
Expect(pass).To(BeTrue())
}
By("Exposing TCP 80 internally on the php-apache deployment")
err = phpApacheDeploy.ExposeIfNotExist("ClusterIP", 80, 80)
Expect(err).NotTo(HaveOccurred())
By("Creating another pod that will connect to the php-apache pod")
r := rand.New(rand.NewSource(time.Now().UnixNano()))
commandString := fmt.Sprintf("nc -vz %s.default.svc.cluster.local 80", longRunningApacheDeploymentName)
consumerPodName := fmt.Sprintf("consumer-pod-%s-%v", cfg.Name, r.Intn(99999))
deploymentCommand := fmt.Sprintf("%s && while true; do sleep 1; done || echo unable to connect to in-cluster web listener", commandString)
// Ensure across all nodes
successes, err := deployment.RunDeploymentMultipleTimes(deployment.RunLinuxDeploy, "busybox", consumerPodName, deploymentCommand, deploymentReplicasCount, cfg.StabilityIterations, 1*time.Second, timeoutWhenWaitingForPodOutboundAccess, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
// Ensure responsiveness
successes, err = pod.RunCommandMultipleTimes(pod.RunLinuxPod, "busybox", consumerPodName, commandString, cfg.StabilityIterations, 1*time.Second, stabilityCommandTimeout, retryCommandsTimeout)
Expect(err).NotTo(HaveOccurred())
Expect(successes).To(Equal(cfg.StabilityIterations))
} else {
Skip("Pod-to-pod network tests only valid on Linux clusters")
}
})
It("should have addons running", func() {
for _, addonName := range []string{"tiller", "aci-connector", "cluster-autoscaler", "blobfuse-flexvolume", "smb-flexvolume", "keyvault-flexvolume", "kubernetes-dashboard", "rescheduler", "metrics-server", "nvidia-device-plugin", "container-monitoring", "azure-cni-networkmonitor", "azure-npm-daemonset", "ip-masq-agent", "azure-policy", "node-problem-detector"} {
var addonPods = []string{addonName}
var addonNamespace = "kube-system"
switch addonName {
case "blobfuse-flexvolume":
addonPods = []string{"blobfuse-flexvol-installer"}
case "smb-flexvolume":
addonPods = []string{"smb-flexvol-installer"}
case "container-monitoring":
addonPods = []string{"omsagent"}
case "azure-npm-daemonset":
addonPods = []string{"azure-npm"}
}
if hasAddon, addon := eng.HasAddon(addonName); hasAddon {
for _, addonPod := range addonPods {
By(fmt.Sprintf("Ensuring that the %s addon is Running", addonName))
running, err := pod.WaitOnSuccesses(addonPod, addonNamespace, kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
By(fmt.Sprintf("Ensuring that the correct resources have been applied for %s", addonPod))
pods, err := pod.GetAllRunningByPrefixWithRetry(addonPod, addonNamespace, 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
for i, c := range addon.Containers {
pod := pods[0]
container := pod.Spec.Containers[i]
err := container.ValidateResources(c)
Expect(err).NotTo(HaveOccurred())
}
}
} else {
fmt.Printf("%s disabled for this cluster, will not test\n", addonName)
}
}
})
It("should have a working node-problem-detector configuration", func() {
if hasNpd, _ := eng.HasAddon("node-problem-detector"); hasNpd {
running, err := pod.WaitOnSuccesses("node-problem-detector", "kube-system", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
pods, err := pod.GetAllRunningByPrefixWithRetry("node-problem-detector", "kube-system", 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(pods).NotTo(BeEmpty())
nodeName := pods[0].Spec.NodeName
// Create a fake kernel message on a node running node-problem-detector
r := rand.New(rand.NewSource(time.Now().UnixNano()))
msgId := r.Intn(999999999999)
msg := fmt.Sprintf("kernel: BUG: unable to handle kernel NULL pointer dereference at TESTING-%d", msgId)
kernelMsgTestCommand := fmt.Sprintf("sudo 'echo %s | sudo tee /dev/kmsg'", msg)
if cfg.BlockSSHPort {
Skip("SSH port is blocked")
}
err = sshConn.ExecuteRemoteWithRetry(nodeName, kernelMsgTestCommand, false, sleepBetweenRetriesRemoteSSHCommand, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
evt, err := event.GetWithRetry(msg, 5*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(evt.Type).To(Equal("Warning"))
Expect(evt.Reason).To(Equal("KernelOops"))
}
})
It("should have the correct tiller configuration", func() {
if hasTiller, tillerAddon := eng.HasAddon("tiller"); hasTiller {
running, err := pod.WaitOnSuccesses("tiller", "kube-system", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
pods, err := pod.GetAllRunningByPrefixWithRetry("tiller-deploy", "kube-system", 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
By("Ensuring that the correct max-history has been applied")
maxHistory := tillerAddon.Config["max-history"]
// There is only one tiller pod and one container in that pod
actualTillerMaxHistory, err := pods[0].Spec.Containers[0].GetEnvironmentVariable("TILLER_HISTORY_MAX")
Expect(err).NotTo(HaveOccurred())
Expect(actualTillerMaxHistory).To(Equal(maxHistory))
} else {
Skip("tiller disabled for this cluster, will not test")
}
})
It("should have the expected omsagent cluster footprint", func() {
if hasContainerMonitoring, _ := eng.HasAddon("container-monitoring"); hasContainerMonitoring {
By("Validating the omsagent replicaset")
running, err := pod.WaitOnSuccesses("omsagent-rs", "kube-system", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
pods, err := pod.GetAllRunningByPrefixWithRetry("omsagent-rs", "kube-system", 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
By("Ensuring that the kubepodinventory plugin is writing data successfully")
pass, err := pods[0].ValidateOmsAgentLogs("kubePodInventoryEmitStreamSuccess", 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(pass).To(BeTrue())
By("Ensuring that the kubenodeinventory plugin is writing data successfully")
pass, err = pods[0].ValidateOmsAgentLogs("kubeNodeInventoryEmitStreamSuccess", 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(pass).To(BeTrue())
By("Validating the omsagent daemonset")
running, err = pod.WaitOnSuccesses("omsagent", "kube-system", kubeSystemPodsReadinessChecks, sleepBetweenRetriesWhenWaitingForPodReady, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
pods, err = pod.GetAllRunningByPrefixWithRetry("omsagent", "kube-system", 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
By("Ensuring that the cadvisor_perf plugin is writing data successfully")
pass, err = pods[0].ValidateOmsAgentLogs("cAdvisorPerfEmitStreamSuccess", 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(pass).To(BeTrue())
By("Ensuring that the containerinventory plugin is writing data successfully")
pass, err = pods[0].ValidateOmsAgentLogs("containerInventoryEmitStreamSuccess", 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(pass).To(BeTrue())
} else {