|
| 1 | +//go:build e2e |
| 2 | + |
| 3 | +package efa |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + _ "embed" |
| 8 | + "flag" |
| 9 | + "fmt" |
| 10 | + "log" |
| 11 | + "os" |
| 12 | + "os/signal" |
| 13 | + "testing" |
| 14 | + "time" |
| 15 | + |
| 16 | + "github.com/aws/aws-k8s-tester/internal/e2e" |
| 17 | + "github.com/aws/aws-k8s-tester/test/manifests" |
| 18 | + appsv1 "k8s.io/api/apps/v1" |
| 19 | + corev1 "k8s.io/api/core/v1" |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + "sigs.k8s.io/e2e-framework/klient/wait" |
| 22 | + "sigs.k8s.io/e2e-framework/pkg/env" |
| 23 | + "sigs.k8s.io/e2e-framework/pkg/envconf" |
| 24 | +) |
| 25 | + |
| 26 | +func getTestNamespace() *corev1.Namespace { |
| 27 | + return &corev1.Namespace{ |
| 28 | + ObjectMeta: metav1.ObjectMeta{ |
| 29 | + Name: TEST_NAMESPACE_NAME, |
| 30 | + }, |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +func deployTestNamespace(ctx context.Context, config *envconf.Config) (context.Context, error) { |
| 35 | + |
| 36 | + return ctx, nil |
| 37 | +} |
| 38 | + |
| 39 | +func deployEFAPlugin(ctx context.Context, config *envconf.Config) (context.Context, error) { |
| 40 | + err := e2e.ApplyManifests(config.Client().RESTConfig(), manifests.EfaDevicePluginManifest) |
| 41 | + if err != nil { |
| 42 | + return ctx, err |
| 43 | + } |
| 44 | + |
| 45 | + ds := appsv1.DaemonSet{ |
| 46 | + ObjectMeta: metav1.ObjectMeta{Name: "aws-efa-k8s-device-plugin-daemonset", Namespace: "kube-system"}, |
| 47 | + } |
| 48 | + err = wait.For(e2e.NewConditionExtension(config.Client().Resources()).DaemonSetReady(&ds), |
| 49 | + wait.WithContext(ctx)) |
| 50 | + if err != nil { |
| 51 | + return ctx, fmt.Errorf("failed to deploy efa-device-plugin: %v", err) |
| 52 | + } |
| 53 | + |
| 54 | + return ctx, nil |
| 55 | +} |
| 56 | + |
| 57 | +func TestMain(m *testing.M) { |
| 58 | + testImage = flag.String("testImage", "", "container image to use for tests") |
| 59 | + pingPongSize = flag.String("pingPongSize", "all", "sizes to use for ping pong") |
| 60 | + pingPongIters = flag.Int("pingPongIters", 10000, "sizes to use for ping pong") |
| 61 | + pingPongDeadlineSeconds = flag.Int("pingPongDeadlineSeconds", 120, "maximum run time for a ping pong attempt") |
| 62 | + nodeType = flag.String("nodeType", "", "instance type to target for tests") |
| 63 | + expectedEFADeviceCount = flag.Int("expectedEFADeviceCount", 0, "expected number of efa devices for the target nodes") |
| 64 | + verbose = flag.Bool("verbose", true, "use verbose mode for tests") |
| 65 | + |
| 66 | + cfg, err := envconf.NewFromFlags() |
| 67 | + if err != nil { |
| 68 | + log.Fatalf("failed to initialize test environment: %v", err) |
| 69 | + } |
| 70 | + |
| 71 | + if *testImage == "" { |
| 72 | + log.Fatal("--testImage must be set, use https://github.com/aws/aws-k8s-tester/blob/main/test/efa/Dockerfile to build the image") |
| 73 | + } |
| 74 | + |
| 75 | + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) |
| 76 | + timedCtx, _ := context.WithTimeout(ctx, 55*time.Minute) |
| 77 | + defer cancel() |
| 78 | + |
| 79 | + testenv = env.NewWithConfig(cfg) |
| 80 | + testenv = testenv.WithContext(timedCtx) |
| 81 | + |
| 82 | + ec2Client = e2e.NewEC2Client() |
| 83 | + |
| 84 | + testenv.Setup( |
| 85 | + func(ctx context.Context, config *envconf.Config) (context.Context, error) { |
| 86 | + err := e2e.ApplyManifests(config.Client().RESTConfig(), manifests.EfaDevicePluginManifest) |
| 87 | + if err != nil { |
| 88 | + return ctx, err |
| 89 | + } |
| 90 | + efaDS := appsv1.DaemonSet{ |
| 91 | + ObjectMeta: metav1.ObjectMeta{Name: "aws-efa-k8s-device-plugin-daemonset", Namespace: "kube-system"}, |
| 92 | + } |
| 93 | + err = wait.For(e2e.NewConditionExtension(config.Client().Resources()).DaemonSetReady(&efaDS), |
| 94 | + wait.WithContext(ctx), |
| 95 | + wait.WithTimeout(5*time.Minute), |
| 96 | + ) |
| 97 | + if err != nil { |
| 98 | + return ctx, err |
| 99 | + } |
| 100 | + |
| 101 | + select { |
| 102 | + case <-ctx.Done(): |
| 103 | + // Cooldown to let device plugin update node object with resources |
| 104 | + case <-time.After(15 * time.Second): |
| 105 | + } |
| 106 | + |
| 107 | + return ctx, cfg.Client().Resources().Create(ctx, getTestNamespace()) |
| 108 | + }, |
| 109 | + ) |
| 110 | + |
| 111 | + testenv.Finish( |
| 112 | + func(ctx context.Context, config *envconf.Config) (context.Context, error) { |
| 113 | + cfg.Client().Resources().Delete(context.TODO(), getTestNamespace()) |
| 114 | + err := e2e.DeleteManifests(cfg.Client().RESTConfig(), manifests.EfaDevicePluginManifest) |
| 115 | + if err != nil { |
| 116 | + return ctx, err |
| 117 | + } |
| 118 | + return ctx, nil |
| 119 | + }, |
| 120 | + ) |
| 121 | + |
| 122 | + os.Exit(testenv.Run(m)) |
| 123 | +} |
0 commit comments