@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/Azure/azure-container-networking/test/internal/datapath"
1212 "github.com/Azure/azure-container-networking/test/internal/k8sutils"
13- "github.com/pkg/errors"
1413 "github.com/stretchr/testify/require"
1514 apiv1 "k8s.io/api/core/v1"
1615)
@@ -46,16 +45,14 @@ Timeout context is controled by the -timeout flag.
4645
4746*/
4847
49- func TestDatapathWin (t * testing.T ) {
48+ func setupWindowsEnvironment (t * testing.T ) {
5049 ctx := context .Background ()
5150
5251 t .Log ("Create Clientset" )
5352 clientset , err := k8sutils .MustGetClientset ()
5453 if err != nil {
55- require . NoError ( t , err )
54+ t . Fatal ( err )
5655 }
57- t .Log ("Get REST config" )
58- restConfig := k8sutils .MustGetRestConfig (t )
5956
6057 t .Log ("Create Label Selectors" )
6158 podLabelSelector := k8sutils .CreateLabelSelector (podLabelKey , podPrefix )
@@ -64,7 +61,7 @@ func TestDatapathWin(t *testing.T) {
6461 t .Log ("Get Nodes" )
6562 nodes , err := k8sutils .GetNodeListByLabelSelector (ctx , clientset , nodeLabelSelector )
6663 if err != nil {
67- require . NoError ( t , err )
64+ t . Fatal ( err )
6865 }
6966
7067 // Create namespace if it doesn't exist
@@ -84,7 +81,7 @@ func TestDatapathWin(t *testing.T) {
8481 t .Log ("Creating Windows pods through deployment" )
8582 deployment , err := k8sutils .MustParseDeployment (WindowsDeployYamlPath )
8683 if err != nil {
87- require . NoError ( t , err )
84+ t . Fatal ( err )
8885 }
8986
9087 // Fields for overwritting existing deployment yaml.
@@ -98,23 +95,23 @@ func TestDatapathWin(t *testing.T) {
9895 deploymentsClient := clientset .AppsV1 ().Deployments (* podNamespace )
9996 err = k8sutils .MustCreateDeployment (ctx , deploymentsClient , deployment )
10097 if err != nil {
101- require . NoError ( t , err )
98+ t . Fatal ( err )
10299 }
103100
104101 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 )
106103 if err != nil {
107- require . NoError ( t , err )
104+ t . Fatal ( err )
108105 }
109106 t .Log ("Successfully created customer windows pods" )
110107 } else {
111108 // Checks namespace already exists from previous attempt
112109 t .Log ("Namespace already exists" )
113110
114111 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 )
116113 if err != nil {
117- require . NoError ( t , err )
114+ t . Fatal ( err )
118115 }
119116 }
120117
@@ -123,14 +120,36 @@ func TestDatapathWin(t *testing.T) {
123120
124121 pods , err := k8sutils .GetPodsByNode (ctx , clientset , * podNamespace , podLabelSelector , node .Name )
125122 if err != nil {
126- require . NoError ( t , err )
123+ t . Fatal ( err )
127124 }
128125 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 )
130127 }
131128 }
132129 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+ }
133143
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+ }
134153 t .Run ("Windows ping tests pod -> node" , func (t * testing.T ) {
135154 // Windows ping tests between pods and node
136155 for _ , node := range nodes .Items {
0 commit comments