Skip to content

Commit

Permalink
chore: must* functions should panic (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjohnst5 authored Oct 3, 2023
1 parent 35a6f89 commit ad3329a
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 369 deletions.
52 changes: 11 additions & 41 deletions test/integration/datapath/datapath_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"flag"
"net"
"os"
"testing"
"time"

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

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

t.Log("Create Label Selectors")
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
Expand All @@ -96,33 +92,15 @@ func setupLinuxEnvironment(t *testing.T) {
var deployment appsv1.Deployment

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

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

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

// setup common RBAC, ClusteerRole, ClusterRoleBinding, ServiceAccount
rbacSetupFn, err := kubernetes.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)
if err != nil {
t.Log(os.Getwd())
t.Fatal(err)
}
rbacSetupFn := kubernetes.MustSetUpClusterRBAC(ctx, clientset, gpClusterRolePath, gpClusterRoleBindingPath, gpServiceAccountPath)

// Fields for overwritting existing deployment yaml.
// Defaults from flags will not change anything
Expand All @@ -134,16 +112,10 @@ func setupLinuxEnvironment(t *testing.T) {
daemonset.Namespace = *podNamespace

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

daemonsetClient := clientset.AppsV1().DaemonSets(daemonset.Namespace)
err = kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
if err != nil {
t.Fatal(err)
}
kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)

t.Cleanup(func() {
t.Log("cleaning up resources")
Expand Down Expand Up @@ -188,13 +160,11 @@ func TestDatapathLinux(t *testing.T) {
ctx := context.Background()

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

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

setupLinuxEnvironment(t)
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)

Expand Down
29 changes: 7 additions & 22 deletions test/integration/datapath/datapath_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ func setupWindowsEnvironment(t *testing.T) {
ctx := context.Background()

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

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

if *restartKubeproxy {
validator, err := validate.CreateValidator(ctx, clientset, restConfig, *podNamespace, "cniv2", false, "windows")
Expand Down Expand Up @@ -85,16 +82,10 @@ func setupWindowsEnvironment(t *testing.T) {
if !namespaceExists {
// Test Namespace
t.Log("Create Namespace")
err := kubernetes.MustCreateNamespace(ctx, clientset, *podNamespace)
if err != nil {
t.Fatalf("failed to create pod namespace %s due to: %v", *podNamespace, err)
}
kubernetes.MustCreateNamespace(ctx, clientset, *podNamespace)

t.Log("Creating Windows pods through deployment")
deployment, err := kubernetes.MustParseDeployment(WindowsDeployYamlPath)
if err != nil {
t.Fatal(err)
}
deployment := kubernetes.MustParseDeployment(WindowsDeployYamlPath)

// Fields for overwritting existing deployment yaml.
// Defaults from flags will not change anything
Expand All @@ -105,10 +96,7 @@ func setupWindowsEnvironment(t *testing.T) {
deployment.Namespace = *podNamespace

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

t.Log("Waiting for pods to be running state")
err = kubernetes.WaitForPodsRunning(ctx, clientset, *podNamespace, podLabelSelector)
Expand Down Expand Up @@ -145,13 +133,10 @@ func TestDatapathWin(t *testing.T) {
ctx := context.Background()

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

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

setupWindowsEnvironment(t)
podLabelSelector := kubernetes.CreateLabelSelector(podLabelKey, podPrefix)
Expand Down
37 changes: 8 additions & 29 deletions test/integration/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,47 +81,26 @@ todo:
*/

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

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

daemonset, err := kubernetes.MustParseDaemonSet(gpDaemonset)
if err != nil {
t.Fatal(err)
}
clientset := kubernetes.MustGetClientset()
restConfig := kubernetes.MustGetRestConfig()
deployment := kubernetes.MustParseDeployment(gpDeployment)
daemonset := kubernetes.MustParseDaemonSet(gpDaemonset)

ctx := context.Background()

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

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

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

daemonsetClient := clientset.AppsV1().DaemonSets(daemonset.Namespace)
err = kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)
if err != nil {
t.Fatal(err)
}
kubernetes.MustCreateDaemonset(ctx, daemonsetClient, daemonset)

t.Cleanup(func() {
t.Log("cleaning up resources")
Expand Down
Loading

0 comments on commit ad3329a

Please sign in to comment.