Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: making installation of CNS daemonset shared #2227

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions test/integration/datapath/datapath_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

k8s "github.com/Azure/azure-container-networking/test/integration"
"github.com/Azure/azure-container-networking/test/integration/goldpinger"
k8sutils "github.com/Azure/azure-container-networking/test/internal/k8sutils"
"github.com/Azure/azure-container-networking/test/internal/kubernetes"
"github.com/Azure/azure-container-networking/test/internal/retry"
"github.com/pkg/errors"

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

t.Log("Create Clientset")
clientset, err := k8sutils.MustGetClientset()
clientset, err := kubernetes.MustGetClientset()
if err != nil {
t.Fatalf("could not get k8s clientset: %v", err)
}

t.Log("Create Label Selectors")
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
nodeLabelSelector := k8sutils.CreateLabelSelector(nodepoolKey, nodepoolSelector)
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
nodeLabelSelector := kubernetes.CreateLabelSelector(nodepoolKey, nodepoolSelector)

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

if *isDualStack {
deployment, err = k8sutils.MustParseDeployment(LinuxDeployIPv6)
deployment, err = kubernetes.MustParseDeployment(LinuxDeployIPv6)
if err != nil {
t.Fatal(err)
}

daemonset, err = k8sutils.MustParseDaemonSet(gpDaemonsetIPv6)
daemonset, err = kubernetes.MustParseDaemonSet(gpDaemonsetIPv6)
if err != nil {
t.Fatal(err)
}
} else {
deployment, err = k8sutils.MustParseDeployment(LinuxDeployIPV4)
deployment, err = kubernetes.MustParseDeployment(LinuxDeployIPV4)
if err != nil {
t.Fatal(err)
}

daemonset, err = k8sutils.MustParseDaemonSet(gpDaemonset)
daemonset, err = kubernetes.MustParseDaemonSet(gpDaemonset)
if err != nil {
t.Fatal(err)
}
}

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

deploymentsClient := clientset.AppsV1().Deployments(*podNamespace)
err = k8sutils.MustCreateDeployment(ctx, deploymentsClient, deployment)
err = kubernetes.MustCreateDeployment(ctx, deploymentsClient, deployment)
if err != nil {
t.Fatal(err)
}

daemonsetClient := clientset.AppsV1().DaemonSets(daemonset.Namespace)
err = k8sutils.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
err = kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
if err != nil {
t.Fatal(err)
}
Expand All @@ -159,7 +159,7 @@ func setupLinuxEnvironment(t *testing.T) {
})

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

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

t.Log("Get REST config")
restConfig := k8sutils.MustGetRestConfig(t)
restConfig := kubernetes.MustGetRestConfig(t)

t.Log("Create Clientset")
clientset, err := k8sutils.MustGetClientset()
clientset, err := kubernetes.MustGetClientset()
if err != nil {
t.Fatalf("could not get k8s clientset: %v", err)
}
setupLinuxEnvironment(t)
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)

t.Run("Linux ping tests", func(t *testing.T) {
// Check goldpinger health
t.Run("all pods have IPs assigned", func(t *testing.T) {
err := k8sutils.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
err := kubernetes.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
if err != nil {
t.Fatalf("Pods are not in running state due to %+v", err)
}
Expand Down
34 changes: 17 additions & 17 deletions test/integration/datapath/datapath_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

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

t.Log("Create Clientset")
clientset, err := k8sutils.MustGetClientset()
clientset, err := kubernetes.MustGetClientset()
if err != nil {
t.Fatal(err)
}

t.Log("Create Label Selectors")
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
nodeLabelSelector := k8sutils.CreateLabelSelector(nodepoolKey, nodepoolSelector)
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
nodeLabelSelector := kubernetes.CreateLabelSelector(nodepoolKey, nodepoolSelector)

t.Log("Get Nodes")
nodes, err := k8sutils.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
nodes, err := kubernetes.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
if err != nil {
t.Fatal(err)
}

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

if !namespaceExists {
// Test Namespace
t.Log("Create Namespace")
err := k8sutils.MustCreateNamespace(ctx, clientset, *podNamespace)
err := kubernetes.MustCreateNamespace(ctx, clientset, *podNamespace)
if err != nil {
t.Fatalf("failed to create pod namespace %s due to: %v", *podNamespace, err)
}

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

deploymentsClient := clientset.AppsV1().Deployments(*podNamespace)
err = k8sutils.MustCreateDeployment(ctx, deploymentsClient, deployment)
err = kubernetes.MustCreateDeployment(ctx, deploymentsClient, deployment)
if err != nil {
t.Fatal(err)
}

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

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

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

t.Log("Get REST config")
restConfig := k8sutils.MustGetRestConfig(t)
restConfig := kubernetes.MustGetRestConfig(t)

t.Log("Create Clientset")
clientset, err := k8sutils.MustGetClientset()
clientset, err := kubernetes.MustGetClientset()
if err != nil {
t.Fatalf("could not get k8s clientset: %v", err)
}

setupWindowsEnvironment(t)
podLabelSelector := k8sutils.CreateLabelSelector(podLabelKey, podPrefix)
nodeLabelSelector := k8sutils.CreateLabelSelector(nodepoolKey, nodepoolSelector)
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
nodeLabelSelector := kubernetes.CreateLabelSelector(nodepoolKey, nodepoolSelector)

t.Log("Get Nodes")
nodes, err := k8sutils.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
nodes, err := kubernetes.GetNodeListByLabelSelector(ctx, clientset, nodeLabelSelector)
if err != nil {
t.Fatal(err)
}
Expand Down
20 changes: 10 additions & 10 deletions test/integration/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

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

Expand Down Expand Up @@ -81,44 +81,44 @@ todo:
*/

func TestPodScaling(t *testing.T) {
clientset, err := k8sutils.MustGetClientset()
clientset, err := kubernetes.MustGetClientset()
if err != nil {
t.Fatal(err)
}

restConfig := k8sutils.MustGetRestConfig(t)
deployment, err := k8sutils.MustParseDeployment(gpDeployment)
restConfig := kubernetes.MustGetRestConfig(t)
deployment, err := kubernetes.MustParseDeployment(gpDeployment)
if err != nil {
t.Fatal(err)
}

daemonset, err := k8sutils.MustParseDaemonSet(gpDaemonset)
daemonset, err := kubernetes.MustParseDaemonSet(gpDaemonset)
if err != nil {
t.Fatal(err)
}

ctx := context.Background()

if shouldLabelNodes() {
k8sutils.MustLabelSwiftNodes(ctx, t, clientset, *delegatedSubnetID, *delegatedSubnetName)
kubernetes.MustLabelSwiftNodes(ctx, t, clientset, *delegatedSubnetID, *delegatedSubnetName)
} else {
t.Log("swift node labels not passed or set. skipping labeling")
}

rbacCleanUpFn, err := k8sutils.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
rbacCleanUpFn, err := kubernetes.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
if err != nil {
t.Log(os.Getwd())
t.Fatal(err)
}

deploymentsClient := clientset.AppsV1().Deployments(deployment.Namespace)
err = k8sutils.MustCreateDeployment(ctx, deploymentsClient, deployment)
err = kubernetes.MustCreateDeployment(ctx, deploymentsClient, deployment)
if err != nil {
t.Fatal(err)
}

daemonsetClient := clientset.AppsV1().DaemonSets(daemonset.Namespace)
err = k8sutils.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
err = kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func updateReplicaCount(t *testing.T, ctx context.Context, deployments v1.Deploy
}

t.Logf("setting deployment %s to %d replicas", name, replicas)
res.Spec.Replicas = k8sutils.Int32ToPtr(int32(replicas))
res.Spec.Replicas = kubernetes.Int32ToPtr(int32(replicas))
_, err = deployments.Update(ctx, res, metav1.UpdateOptions{})
return err
})
Expand Down
Loading