@@ -10,7 +10,6 @@ import (
10
10
11
11
"github.com/Azure/azure-container-networking/test/internal/datapath"
12
12
"github.com/Azure/azure-container-networking/test/internal/k8sutils"
13
- "github.com/pkg/errors"
14
13
"github.com/stretchr/testify/require"
15
14
apiv1 "k8s.io/api/core/v1"
16
15
)
@@ -46,16 +45,14 @@ Timeout context is controled by the -timeout flag.
46
45
47
46
*/
48
47
49
- func TestDatapathWin (t * testing.T ) {
48
+ func setupWindowsEnvironment (t * testing.T ) {
50
49
ctx := context .Background ()
51
50
52
51
t .Log ("Create Clientset" )
53
52
clientset , err := k8sutils .MustGetClientset ()
54
53
if err != nil {
55
- require . NoError ( t , err )
54
+ t . Fatal ( err )
56
55
}
57
- t .Log ("Get REST config" )
58
- restConfig := k8sutils .MustGetRestConfig (t )
59
56
60
57
t .Log ("Create Label Selectors" )
61
58
podLabelSelector := k8sutils .CreateLabelSelector (podLabelKey , podPrefix )
@@ -64,7 +61,7 @@ func TestDatapathWin(t *testing.T) {
64
61
t .Log ("Get Nodes" )
65
62
nodes , err := k8sutils .GetNodeListByLabelSelector (ctx , clientset , nodeLabelSelector )
66
63
if err != nil {
67
- require . NoError ( t , err )
64
+ t . Fatal ( err )
68
65
}
69
66
70
67
// Create namespace if it doesn't exist
@@ -84,7 +81,7 @@ func TestDatapathWin(t *testing.T) {
84
81
t .Log ("Creating Windows pods through deployment" )
85
82
deployment , err := k8sutils .MustParseDeployment (WindowsDeployYamlPath )
86
83
if err != nil {
87
- require . NoError ( t , err )
84
+ t . Fatal ( err )
88
85
}
89
86
90
87
// Fields for overwritting existing deployment yaml.
@@ -98,23 +95,23 @@ func TestDatapathWin(t *testing.T) {
98
95
deploymentsClient := clientset .AppsV1 ().Deployments (* podNamespace )
99
96
err = k8sutils .MustCreateDeployment (ctx , deploymentsClient , deployment )
100
97
if err != nil {
101
- require . NoError ( t , err )
98
+ t . Fatal ( err )
102
99
}
103
100
104
101
t .Log ("Waiting for pods to be running state" )
105
- err : = k8sutils .WaitForPodsRunning (ctx , clientset , * podNamespace , podLabelSelector )
102
+ err = k8sutils .WaitForPodsRunning (ctx , clientset , * podNamespace , podLabelSelector )
106
103
if err != nil {
107
- require . NoError ( t , err )
104
+ t . Fatal ( err )
108
105
}
109
106
t .Log ("Successfully created customer windows pods" )
110
107
} else {
111
108
// Checks namespace already exists from previous attempt
112
109
t .Log ("Namespace already exists" )
113
110
114
111
t .Log ("Checking for pods to be running state" )
115
- err : = k8sutils .WaitForPodsRunning (ctx , clientset , * podNamespace , podLabelSelector )
112
+ err = k8sutils .WaitForPodsRunning (ctx , clientset , * podNamespace , podLabelSelector )
116
113
if err != nil {
117
- require . NoError ( t , err )
114
+ t . Fatal ( err )
118
115
}
119
116
}
120
117
@@ -123,14 +120,36 @@ func TestDatapathWin(t *testing.T) {
123
120
124
121
pods , err := k8sutils .GetPodsByNode (ctx , clientset , * podNamespace , podLabelSelector , node .Name )
125
122
if err != nil {
126
- require . NoError ( t , err )
123
+ t . Fatal ( err )
127
124
}
128
125
if len (pods .Items ) <= 1 {
129
- require . NoError ( t , errors . New ("Less than 2 pods on node" ) )
126
+ t . Fatalf ("Less than 2 pods on node: %v" , node . Name )
130
127
}
131
128
}
132
129
t .Log ("Windows test environment ready" )
130
+ }
131
+
132
+ func TestDatapathWin (t * testing.T ) {
133
+ ctx := context .Background ()
134
+
135
+ t .Log ("Get REST config" )
136
+ restConfig := k8sutils .MustGetRestConfig (t )
137
+
138
+ t .Log ("Create Clientset" )
139
+ clientset , err := k8sutils .MustGetClientset ()
140
+ if err != nil {
141
+ t .Fatalf ("could not get k8s clientset: %v" , err )
142
+ }
133
143
144
+ setupWindowsEnvironment (t )
145
+ podLabelSelector := k8sutils .CreateLabelSelector (podLabelKey , podPrefix )
146
+ nodeLabelSelector := k8sutils .CreateLabelSelector (nodepoolKey , nodepoolSelector )
147
+
148
+ t .Log ("Get Nodes" )
149
+ nodes , err := k8sutils .GetNodeListByLabelSelector (ctx , clientset , nodeLabelSelector )
150
+ if err != nil {
151
+ t .Fatal (err )
152
+ }
134
153
t .Run ("Windows ping tests pod -> node" , func (t * testing.T ) {
135
154
// Windows ping tests between pods and node
136
155
for _ , node := range nodes .Items {
0 commit comments