-
Couldn't load subscription status.
- Fork 96
feat: add workload test case for external tests #700
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //go:build e2e | ||
|
|
||
| package workload | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "log" | ||
| "os" | ||
| "os/signal" | ||
| "testing" | ||
|
|
||
| "sigs.k8s.io/e2e-framework/pkg/env" | ||
| "sigs.k8s.io/e2e-framework/pkg/envconf" | ||
| ) | ||
|
|
||
| var ( | ||
| testenv env.Environment | ||
| workloadTestCommand *string | ||
| workloadTestImage *string | ||
| workloadTestName *string | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| workloadTestCommand = flag.String("workloadTestCommand", "", "command for workload test") | ||
| workloadTestImage = flag.String("workloadTestImage", "", "image for workload test") | ||
| workloadTestName = flag.String("workloadTestName", "workload-test", "name for workload test") | ||
| cfg, err := envconf.NewFromFlags() | ||
| if err != nil { | ||
| log.Fatalf("failed to initialize test environment: %v", err) | ||
| } | ||
| testenv = env.NewWithConfig(cfg) | ||
| ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) | ||
| defer cancel() | ||
| testenv = testenv.WithContext(ctx) | ||
|
|
||
| testenv.Setup(func(ctx context.Context, config *envconf.Config) (context.Context, error) { | ||
| log.Println("Starting workload test suite...") | ||
| return ctx, nil | ||
| }) | ||
|
|
||
| os.Exit(testenv.Run(m)) | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this template is actually so minimal i feel like its worth just using the go type for? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| kind: Job | ||
| apiVersion: batch/v1 | ||
| metadata: | ||
| name: {{.WorkloadTestName}} | ||
| labels: | ||
| app: {{.WorkloadTestName}} | ||
| spec: | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: {{.WorkloadTestName}} | ||
| spec: | ||
| containers: | ||
| - name: {{.WorkloadTestName}} | ||
| image: {{.WorkloadTestImage}} | ||
| command: ["/bin/bash", "-c"] | ||
| args: ["{{.WorkloadTestCommand}}"] | ||
| imagePullPolicy: Always | ||
| restartPolicy: Never | ||
| backoffLimit: 4 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,95 @@ | ||||||||||||||||||||||||||||||||||||||
| //go:build e2e | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| package workload | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||
| _ "embed" | ||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| fwext "github.com/aws/aws-k8s-tester/internal/e2e" | ||||||||||||||||||||||||||||||||||||||
| batchv1 "k8s.io/api/batch/v1" | ||||||||||||||||||||||||||||||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||||||||||||||||||||||||||
| "sigs.k8s.io/e2e-framework/klient/wait" | ||||||||||||||||||||||||||||||||||||||
| "sigs.k8s.io/e2e-framework/pkg/envconf" | ||||||||||||||||||||||||||||||||||||||
| "sigs.k8s.io/e2e-framework/pkg/features" | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| var ( | ||||||||||||||||||||||||||||||||||||||
| //go:embed manifests/single-node-test-workload.yaml | ||||||||||||||||||||||||||||||||||||||
| workloadSingleNodeManifest []byte | ||||||||||||||||||||||||||||||||||||||
| renderedWorkloadSingleNodeManifest []byte | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| type workloadSingleNodeManifestTplVars struct { | ||||||||||||||||||||||||||||||||||||||
| WorkloadTestCommand string | ||||||||||||||||||||||||||||||||||||||
| WorkloadTestImage string | ||||||||||||||||||||||||||||||||||||||
| WorkloadTestName string | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func TestWorkload(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||
| singleNode := features.New("single-node"). | ||||||||||||||||||||||||||||||||||||||
| WithLabel("suite", "workload"). | ||||||||||||||||||||||||||||||||||||||
| Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||||||||||||||||||||||||||||||||||||||
| if *workloadTestCommand == "" { | ||||||||||||||||||||||||||||||||||||||
| t.Fatal(fmt.Errorf("workloadTestCommand must be set to run workload test")) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if *workloadTestImage == "" { | ||||||||||||||||||||||||||||||||||||||
| t.Fatal(fmt.Errorf("workloadTestImage must be set to run workload test")) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if *workloadTestName == "" { | ||||||||||||||||||||||||||||||||||||||
| t.Fatal(fmt.Errorf("workloadTestName must be set to run workload test")) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: just shortening
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| var err error | ||||||||||||||||||||||||||||||||||||||
| renderedWorkloadSingleNodeManifest, err = fwext.RenderManifests(workloadSingleNodeManifest, workloadSingleNodeManifestTplVars{ | ||||||||||||||||||||||||||||||||||||||
| WorkloadTestCommand: *workloadTestCommand, | ||||||||||||||||||||||||||||||||||||||
| WorkloadTestImage: *workloadTestImage, | ||||||||||||||||||||||||||||||||||||||
| WorkloadTestName: *workloadTestName, | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| t.Log("Applying single node manifest") | ||||||||||||||||||||||||||||||||||||||
| err = fwext.ApplyManifests(cfg.Client().RESTConfig(), renderedWorkloadSingleNodeManifest) | ||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| t.Log("Manifest applied successfully") | ||||||||||||||||||||||||||||||||||||||
| return ctx | ||||||||||||||||||||||||||||||||||||||
| }). | ||||||||||||||||||||||||||||||||||||||
| Assess("Single node test Job succeeds", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||||||||||||||||||||||||||||||||||||||
| job := &batchv1.Job{ | ||||||||||||||||||||||||||||||||||||||
| ObjectMeta: metav1.ObjectMeta{Name: *workloadTestName, Namespace: "default"}, | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is there a default namespace enum in |
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| t.Log("Waiting for single node job to complete") | ||||||||||||||||||||||||||||||||||||||
| err := wait.For(fwext.NewConditionExtension(cfg.Client().Resources()).JobSucceeded(job), | ||||||||||||||||||||||||||||||||||||||
| wait.WithContext(ctx), | ||||||||||||||||||||||||||||||||||||||
| wait.WithTimeout(time.Minute*20), | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return ctx | ||||||||||||||||||||||||||||||||||||||
| }). | ||||||||||||||||||||||||||||||||||||||
| Teardown(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||||||||||||||||||||||||||||||||||||||
| log, err := fwext.GetJobLogs(cfg.Client().RESTConfig(), &batchv1.Job{ | ||||||||||||||||||||||||||||||||||||||
| ObjectMeta: metav1.ObjectMeta{Name: *workloadTestName, Namespace: "default"}, | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||
| t.Error(err) | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| t.Log(fmt.Sprintf("Test log for %s:", *workloadTestName)) | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| t.Log(log) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| err = fwext.DeleteManifests(cfg.Client().RESTConfig(), renderedWorkloadSingleNodeManifest) | ||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||
| t.Error(err) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return ctx | ||||||||||||||||||||||||||||||||||||||
| }). | ||||||||||||||||||||||||||||||||||||||
| Feature() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| testenv.Test(t, singleNode) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just want to nit the naming, "workload" is pretty broad, could we pick a clear name with a theme like "jobTemplate"? I'm really open to suggestions but i want to make sure this is sane/immediately readable