-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidateKubernetes.Pester.tests.ps1
136 lines (130 loc) · 5.24 KB
/
ValidateKubernetes.Pester.tests.ps1
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
<#
.DESCRIPTION
This script validates basic connectivity for Windows nodes in a Kubernetes cluster.
Assumes the cluster has no other services/pods deployed besides kube-system
#>
import-module "$PSScriptRoot\ValidateKubernetesHelper.psm1"
Describe 'Kubernetes Prerequisites' {
# Context 'Checking Docker images' {
# It "should have windowservercore image" {
# docker images mcr.microsoft.com/windows/servercore:1809 -q | Should Not BeNullOrEmpty
# }
# }
Context 'Checking Kubernetes Binaries are running' {
It 'kubelet.exe is running' {
get-process -Name 'kubelet' | Should be $true
}
It 'kube-proxy.exe is running' {
get-process -Name 'kube-proxy'| Should be $true
}
It 'flanneld.exe is running' {
get-process -Name 'flanneld' | Should be $true
}
}
}
Describe 'Basic Connectivity Tests' {
Context 'Windows Connectivity' {
BeforeAll {
$Name = "win-webserver"
kubectl apply -f https://raw.githubusercontent.com/anuddeeph1/windows-k8s/main/webserver.yaml
kubectl scale deployment $Name --replicas=4
WaitForDeploymentCompletion -DeploymentName $Name
$workloadContainers = GetContainers -DeploymentName $Name
$localContainers = GetContainers -PodLocation Local -DeploymentName $Name
$remoteContainers = GetContainers -PodLocation Remote -DeploymentName $Name
$serviceVIP = (kubectl get services -o json | ConvertFrom-Json).items[1].spec.clusterIP
$nodePort = (kubectl get services -o json | ConvertFrom-Json).items[1].spec.ports.nodePort
}
AfterAll {
kubectl delete -f https://raw.githubusercontent.com/anuddeeph1/windows-k8s/main/webserver.yaml
}
It 'should have more than 1 local container' {
$localContainers.count | Should BeGreaterThan 1
}
It 'should have at least 1 remote container' {
$remoteContainers.count | Should BeGreaterThan 0
}
It 'Pods should have correct IP' {
foreach ($container in $workloadContainers)
{
Write-Host "Checking $($container.Name) has IP address $($container.IPAddress)"
$container.IPAddress -eq (GetContainerIPv4Address -containerName $container.Name) | Should be $true
}
}
It 'Pods should have Internet connectivity' {
foreach ($container in $workloadContainers)
{
Write-Host "Testing from $($container.Name) $($container.IPAddress)"
TestConnectivity -containerName $container.Name
}
}
It 'Pods should be able to resolve Service Name' {
foreach ($container in $workloadContainers)
{
Write-Host "Testing service $Name from ${container.Name} $($container.IPAddress)"
TestConnectivity -containerName $container.Name -remoteHost $Name
}
}
It 'Host should be able to reach Service Ip' {
foreach ($container in $workloadContainers)
{
Write-Host "Testing service VIP ${serviceVIP} from host"
TestConnectivity -fromHost -remoteHost $ServiceVip
}
}
It 'Pods should be able to reach localhost' {
$managementIP = WaitForManagementIP
foreach ($container in $localContainers)
{
PingTest -containerName $container.Name -destination $managementIP
}
}
It 'Localhost should be able to reach local pod' {
foreach ($container in $localContainers)
{
PingTest -destination $container.IPAddress -fromHost
}
}
It 'Pod should be able to ping a local pod' {
foreach ($container1 in $localContainers)
{
foreach ($container2 in $localContainers)
{
if ($container1.Name -ne $container2.Name) {
PingTest -containerName $container1.Name -destination $container2.IPAddress
}
}
}
}
It 'Pod should be able to ping a remote pod' {
foreach ($container1 in $localContainers)
{
foreach ($container2 in $remoteContainers)
{
PingTest -containerName $container1.Name -destination $container2.IPAddress
}
}
}
It 'Remote host Should be able to access Node port' {
foreach ($container1 in $localContainers)
{
foreach ($container2 in $remoteContainers)
{
TestConnectivity -remoteHost $container2.HostIP -port $nodePort -fromHost
}
}
}
'''
# LocalRoutedVip
It "Localhost Should be able to access Node port" {
foreach ($container1 in $localContainers)
{
foreach ($container2 in $remoteContainers)
{
TestConnectivity -remoteHost $container2.HostIP -port $nodePort -fromHost
}
}
}
'''
}
}