Skip to content

Commit c2c59db

Browse files
authored
chore: making installation of CNS daemonset shared (#2227)
1 parent bad286b commit c2c59db

File tree

15 files changed

+635
-597
lines changed

15 files changed

+635
-597
lines changed

test/integration/datapath/datapath_linux_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
k8s "github.com/Azure/azure-container-networking/test/integration"
1414
"github.com/Azure/azure-container-networking/test/integration/goldpinger"
15-
k8sutils "github.com/Azure/azure-container-networking/test/internal/k8sutils"
15+
"github.com/Azure/azure-container-networking/test/internal/kubernetes"
1616
"github.com/Azure/azure-container-networking/test/internal/retry"
1717
"github.com/pkg/errors"
1818

@@ -74,17 +74,17 @@ func setupLinuxEnvironment(t *testing.T) {
7474
ctx := context.Background()
7575

7676
t.Log("Create Clientset")
77-
clientset, err := k8sutils.MustGetClientset()
77+
clientset, err := kubernetes.MustGetClientset()
7878
if err != nil {
7979
t.Fatalf("could not get k8s clientset: %v", err)
8080
}
8181

8282
t.Log("Create Label Selectors")
83-
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
84-
nodeLabelSelector := k8sutils.CreateLabelSelector(nodepoolKey, nodepoolSelector)
83+
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
84+
nodeLabelSelector := kubernetes.CreateLabelSelector(nodepoolKey, nodepoolSelector)
8585

8686
t.Log("Get Nodes")
87-
nodes, err := k8sutils.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
87+
nodes, err := kubernetes.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
8888
if err != nil {
8989
t.Fatalf("could not get k8s node list: %v", err)
9090
}
@@ -96,29 +96,29 @@ func setupLinuxEnvironment(t *testing.T) {
9696
var deployment appsv1.Deployment
9797

9898
if *isDualStack {
99-
deployment, err = k8sutils.MustParseDeployment(LinuxDeployIPv6)
99+
deployment, err = kubernetes.MustParseDeployment(LinuxDeployIPv6)
100100
if err != nil {
101101
t.Fatal(err)
102102
}
103103

104-
daemonset, err = k8sutils.MustParseDaemonSet(gpDaemonsetIPv6)
104+
daemonset, err = kubernetes.MustParseDaemonSet(gpDaemonsetIPv6)
105105
if err != nil {
106106
t.Fatal(err)
107107
}
108108
} else {
109-
deployment, err = k8sutils.MustParseDeployment(LinuxDeployIPV4)
109+
deployment, err = kubernetes.MustParseDeployment(LinuxDeployIPV4)
110110
if err != nil {
111111
t.Fatal(err)
112112
}
113113

114-
daemonset, err = k8sutils.MustParseDaemonSet(gpDaemonset)
114+
daemonset, err = kubernetes.MustParseDaemonSet(gpDaemonset)
115115
if err != nil {
116116
t.Fatal(err)
117117
}
118118
}
119119

120120
// setup common RBAC, ClusteerRole, ClusterRoleBinding, ServiceAccount
121-
rbacSetupFn, err := k8sutils.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
121+
rbacSetupFn, err := kubernetes.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
122122
if err != nil {
123123
t.Log(os.Getwd())
124124
t.Fatal(err)
@@ -134,13 +134,13 @@ func setupLinuxEnvironment(t *testing.T) {
134134
daemonset.Namespace = *podNamespace
135135

136136
deploymentsClient := clientset.AppsV1().Deployments(*podNamespace)
137-
err = k8sutils.MustCreateDeployment(ctx, deploymentsClient, deployment)
137+
err = kubernetes.MustCreateDeployment(ctx, deploymentsClient, deployment)
138138
if err != nil {
139139
t.Fatal(err)
140140
}
141141

142142
daemonsetClient := clientset.AppsV1().DaemonSets(daemonset.Namespace)
143-
err = k8sutils.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
143+
err = kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
144144
if err != nil {
145145
t.Fatal(err)
146146
}
@@ -159,7 +159,7 @@ func setupLinuxEnvironment(t *testing.T) {
159159
})
160160

161161
t.Log("Waiting for pods to be running state")
162-
err = k8sutils.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
162+
err = kubernetes.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
163163
if err != nil {
164164
t.Fatalf("Pods are not in running state due to %+v", err)
165165
}
@@ -172,7 +172,7 @@ func setupLinuxEnvironment(t *testing.T) {
172172

173173
t.Log("Checking Linux test environment")
174174
for _, node := range nodes.Items {
175-
pods, err := k8sutils.GetPodsByNode(ctx, clientset, *podNamespace, podLabelSelector, node.Name)
175+
pods, err := kubernetes.GetPodsByNode(ctx, clientset, *podNamespace, podLabelSelector, node.Name)
176176
if err != nil {
177177
t.Fatalf("could not get k8s clientset: %v", err)
178178
}
@@ -188,20 +188,20 @@ func TestDatapathLinux(t *testing.T) {
188188
ctx := context.Background()
189189

190190
t.Log("Get REST config")
191-
restConfig := k8sutils.MustGetRestConfig(t)
191+
restConfig := kubernetes.MustGetRestConfig(t)
192192

193193
t.Log("Create Clientset")
194-
clientset, err := k8sutils.MustGetClientset()
194+
clientset, err := kubernetes.MustGetClientset()
195195
if err != nil {
196196
t.Fatalf("could not get k8s clientset: %v", err)
197197
}
198198
setupLinuxEnvironment(t)
199-
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
199+
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
200200

201201
t.Run("Linux ping tests", func(t *testing.T) {
202202
// Check goldpinger health
203203
t.Run("all pods have IPs assigned", func(t *testing.T) {
204-
err := k8sutils.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
204+
err := kubernetes.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
205205
if err != nil {
206206
t.Fatalf("Pods are not in running state due to %+v", err)
207207
}

test/integration/datapath/datapath_windows_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/Azure/azure-container-networking/test/internal/datapath"
12-
"github.com/Azure/azure-container-networking/test/internal/k8sutils"
12+
"github.com/Azure/azure-container-networking/test/internal/kubernetes"
1313
"github.com/stretchr/testify/require"
1414
apiv1 "k8s.io/api/core/v1"
1515
)
@@ -49,37 +49,37 @@ func setupWindowsEnvironment(t *testing.T) {
4949
ctx := context.Background()
5050

5151
t.Log("Create Clientset")
52-
clientset, err := k8sutils.MustGetClientset()
52+
clientset, err := kubernetes.MustGetClientset()
5353
if err != nil {
5454
t.Fatal(err)
5555
}
5656

5757
t.Log("Create Label Selectors")
58-
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
59-
nodeLabelSelector := k8sutils.CreateLabelSelector(nodepoolKey, nodepoolSelector)
58+
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
59+
nodeLabelSelector := kubernetes.CreateLabelSelector(nodepoolKey, nodepoolSelector)
6060

6161
t.Log("Get Nodes")
62-
nodes, err := k8sutils.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
62+
nodes, err := kubernetes.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
6363
if err != nil {
6464
t.Fatal(err)
6565
}
6666

6767
// Create namespace if it doesn't exist
68-
namespaceExists, err := k8sutils.NamespaceExists(ctx, clientset, *podNamespace)
68+
namespaceExists, err := kubernetes.NamespaceExists(ctx, clientset, *podNamespace)
6969
if err != nil {
7070
t.Fatalf("failed to check if namespace %s exists due to: %v", *podNamespace, err)
7171
}
7272

7373
if !namespaceExists {
7474
// Test Namespace
7575
t.Log("Create Namespace")
76-
err := k8sutils.MustCreateNamespace(ctx, clientset, *podNamespace)
76+
err := kubernetes.MustCreateNamespace(ctx, clientset, *podNamespace)
7777
if err != nil {
7878
t.Fatalf("failed to create pod namespace %s due to: %v", *podNamespace, err)
7979
}
8080

8181
t.Log("Creating Windows pods through deployment")
82-
deployment, err := k8sutils.MustParseDeployment(WindowsDeployYamlPath)
82+
deployment, err := kubernetes.MustParseDeployment(WindowsDeployYamlPath)
8383
if err != nil {
8484
t.Fatal(err)
8585
}
@@ -93,13 +93,13 @@ func setupWindowsEnvironment(t *testing.T) {
9393
deployment.Namespace = *podNamespace
9494

9595
deploymentsClient := clientset.AppsV1().Deployments(*podNamespace)
96-
err = k8sutils.MustCreateDeployment(ctx, deploymentsClient, deployment)
96+
err = kubernetes.MustCreateDeployment(ctx, deploymentsClient, deployment)
9797
if err != nil {
9898
t.Fatal(err)
9999
}
100100

101101
t.Log("Waiting for pods to be running state")
102-
err = k8sutils.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
102+
err = kubernetes.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
103103
if err != nil {
104104
t.Fatal(err)
105105
}
@@ -109,7 +109,7 @@ func setupWindowsEnvironment(t *testing.T) {
109109
t.Log("Namespace already exists")
110110

111111
t.Log("Checking for pods to be running state")
112-
err = k8sutils.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
112+
err = kubernetes.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
113113
if err != nil {
114114
t.Fatal(err)
115115
}
@@ -118,7 +118,7 @@ func setupWindowsEnvironment(t *testing.T) {
118118
t.Log("Checking Windows test environment")
119119
for _, node := range nodes.Items {
120120

121-
pods, err := k8sutils.GetPodsByNode(ctx, clientset, *podNamespace, podLabelSelector, node.Name)
121+
pods, err := kubernetes.GetPodsByNode(ctx, clientset, *podNamespace, podLabelSelector, node.Name)
122122
if err != nil {
123123
t.Fatal(err)
124124
}
@@ -133,20 +133,20 @@ func TestDatapathWin(t *testing.T) {
133133
ctx := context.Background()
134134

135135
t.Log("Get REST config")
136-
restConfig := k8sutils.MustGetRestConfig(t)
136+
restConfig := kubernetes.MustGetRestConfig(t)
137137

138138
t.Log("Create Clientset")
139-
clientset, err := k8sutils.MustGetClientset()
139+
clientset, err := kubernetes.MustGetClientset()
140140
if err != nil {
141141
t.Fatalf("could not get k8s clientset: %v", err)
142142
}
143143

144144
setupWindowsEnvironment(t)
145-
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
146-
nodeLabelSelector := k8sutils.CreateLabelSelector(nodepoolKey, nodepoolSelector)
145+
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
146+
nodeLabelSelector := kubernetes.CreateLabelSelector(nodepoolKey, nodepoolSelector)
147147

148148
t.Log("Get Nodes")
149-
nodes, err := k8sutils.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
149+
nodes, err := kubernetes.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
150150
if err != nil {
151151
t.Fatal(err)
152152
}

test/integration/k8s_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/Azure/azure-container-networking/test/integration/goldpinger"
16-
k8sutils "github.com/Azure/azure-container-networking/test/internal/k8sutils"
16+
"github.com/Azure/azure-container-networking/test/internal/kubernetes"
1717
"github.com/Azure/azure-container-networking/test/internal/retry"
1818
v1 "k8s.io/client-go/kubernetes/typed/apps/v1"
1919

@@ -81,44 +81,44 @@ todo:
8181
*/
8282

8383
func TestPodScaling(t *testing.T) {
84-
clientset, err := k8sutils.MustGetClientset()
84+
clientset, err := kubernetes.MustGetClientset()
8585
if err != nil {
8686
t.Fatal(err)
8787
}
8888

89-
restConfig := k8sutils.MustGetRestConfig(t)
90-
deployment, err := k8sutils.MustParseDeployment(gpDeployment)
89+
restConfig := kubernetes.MustGetRestConfig(t)
90+
deployment, err := kubernetes.MustParseDeployment(gpDeployment)
9191
if err != nil {
9292
t.Fatal(err)
9393
}
9494

95-
daemonset, err := k8sutils.MustParseDaemonSet(gpDaemonset)
95+
daemonset, err := kubernetes.MustParseDaemonSet(gpDaemonset)
9696
if err != nil {
9797
t.Fatal(err)
9898
}
9999

100100
ctx := context.Background()
101101

102102
if shouldLabelNodes() {
103-
k8sutils.MustLabelSwiftNodes(ctx, t, clientset, *delegatedSubnetID, *delegatedSubnetName)
103+
kubernetes.MustLabelSwiftNodes(ctx, t, clientset, *delegatedSubnetID, *delegatedSubnetName)
104104
} else {
105105
t.Log("swift node labels not passed or set. skipping labeling")
106106
}
107107

108-
rbacCleanUpFn, err := k8sutils.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
108+
rbacCleanUpFn, err := kubernetes.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
109109
if err != nil {
110110
t.Log(os.Getwd())
111111
t.Fatal(err)
112112
}
113113

114114
deploymentsClient := clientset.AppsV1().Deployments(deployment.Namespace)
115-
err = k8sutils.MustCreateDeployment(ctx, deploymentsClient, deployment)
115+
err = kubernetes.MustCreateDeployment(ctx, deploymentsClient, deployment)
116116
if err != nil {
117117
t.Fatal(err)
118118
}
119119

120120
daemonsetClient := clientset.AppsV1().DaemonSets(daemonset.Namespace)
121-
err = k8sutils.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
121+
err = kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
122122
if err != nil {
123123
t.Fatal(err)
124124
}
@@ -254,7 +254,7 @@ func updateReplicaCount(t *testing.T, ctx context.Context, deployments v1.Deploy
254254
}
255255

256256
t.Logf("setting deployment %s to %d replicas", name, replicas)
257-
res.Spec.Replicas = k8sutils.Int32ToPtr(int32(replicas))
257+
res.Spec.Replicas = kubernetes.Int32ToPtr(int32(replicas))
258258
_, err = deployments.Update(ctx, res, metav1.UpdateOptions{})
259259
return err
260260
})

0 commit comments

Comments
 (0)