From d12d25f5cd3525db72aa8bcdd0c14e87688277b8 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Tue, 4 Oct 2022 13:38:20 -0500 Subject: [PATCH 1/4] test(executor): add kubernetes runtime for CreateService tests --- executor/linux/service_test.go | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index 144a38bf..26e02430 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -17,6 +17,7 @@ import ( "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" "github.com/go-vela/worker/runtime/docker" + "github.com/go-vela/worker/runtime/kubernetes" ) func TestLinux_CreateService(t *testing.T) { @@ -39,6 +40,11 @@ func TestLinux_CreateService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -62,6 +68,22 @@ func TestLinux_CreateService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with image not found", failure: true, @@ -78,12 +100,34 @@ func TestLinux_CreateService(t *testing.T) { Pull: "not_present", }, }, + // { + // name: "kubernetes-service container with image not found", + // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock + // runtime: _kubernetes, + // container: &pipeline.Container{ + // ID: "service_github_octocat_1_postgres", + // Detach: true, + // Directory: "/vela/src/github.com/github/octocat", + // Environment: map[string]string{"FOO": "bar"}, + // Image: "postgres:notfound", + // Name: "postgres", + // Number: 1, + // Ports: []string{"5432:5432"}, + // Pull: "not_present", + // }, + // }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests From 391baa8719fea09f71b6c189e2d5d5d5052ee11c Mon Sep 17 00:00:00 2001 From: JordanSussman Date: Wed, 5 Oct 2022 11:25:33 -0500 Subject: [PATCH 2/4] test(executor): add k8s runtime for service tests --- executor/linux/service_test.go | 166 +++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index 26e02430..983c4be5 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -182,6 +182,11 @@ func TestLinux_PlanService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -205,6 +210,22 @@ func TestLinux_PlanService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with nil environment", failure: true, @@ -221,12 +242,34 @@ func TestLinux_PlanService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-service container with nil environment", + failure: true, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: nil, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -281,6 +324,11 @@ func TestLinux_ExecService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + streamRequests, done := message.MockStreamRequestsWithCancel(context.Background()) defer done() @@ -307,6 +355,22 @@ func TestLinux_ExecService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with image not found", failure: true, @@ -323,12 +387,34 @@ func TestLinux_ExecService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-service container with image not found", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:notfound", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -389,6 +475,11 @@ func TestLinux_StreamService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -412,6 +503,22 @@ func TestLinux_StreamService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with name not found", failure: true, @@ -428,12 +535,34 @@ func TestLinux_StreamService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-service container with name not found", + failure: false, // TODO: add mock to make this fail + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_notfound", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "notfound", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -493,6 +622,11 @@ func TestLinux_DestroyService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -516,6 +650,22 @@ func TestLinux_DestroyService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with ignoring name not found", failure: true, @@ -532,6 +682,22 @@ func TestLinux_DestroyService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-service container with ignoring name not found", + failure: false, // TODO: add mock to make this fail + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service_github_octocat_1_ignorenotfound", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "ignorenotfound", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, } // run tests From d9ea3a416585a7f117fee03b3ded93246ffd75e6 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 28 Feb 2023 12:01:18 -0600 Subject: [PATCH 3/4] sanitize container names for k8s runtime --- executor/linux/service_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index 983c4be5..c50ce6d9 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -73,7 +73,7 @@ func TestLinux_CreateService(t *testing.T) { failure: false, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -105,7 +105,7 @@ func TestLinux_CreateService(t *testing.T) { // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock // runtime: _kubernetes, // container: &pipeline.Container{ - // ID: "service_github_octocat_1_postgres", + // ID: "service-github-octocat-1-postgres", // Detach: true, // Directory: "/vela/src/github.com/github/octocat", // Environment: map[string]string{"FOO": "bar"}, @@ -215,7 +215,7 @@ func TestLinux_PlanService(t *testing.T) { failure: false, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -247,7 +247,7 @@ func TestLinux_PlanService(t *testing.T) { failure: true, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: nil, @@ -360,7 +360,7 @@ func TestLinux_ExecService(t *testing.T) { failure: false, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -392,7 +392,7 @@ func TestLinux_ExecService(t *testing.T) { failure: false, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -508,7 +508,7 @@ func TestLinux_StreamService(t *testing.T) { failure: false, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -540,7 +540,7 @@ func TestLinux_StreamService(t *testing.T) { failure: false, // TODO: add mock to make this fail runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_notfound", + ID: "service-github-octocat-1-notfound", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -655,7 +655,7 @@ func TestLinux_DestroyService(t *testing.T) { failure: false, runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_postgres", + ID: "service-github-octocat-1-postgres", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, @@ -687,7 +687,7 @@ func TestLinux_DestroyService(t *testing.T) { failure: false, // TODO: add mock to make this fail runtime: _kubernetes, container: &pipeline.Container{ - ID: "service_github_octocat_1_ignorenotfound", + ID: "service-github-octocat-1-ignorenotfound", Detach: true, Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, From d256e9c6a4cc8ee69358a69aa5a4e86e5a876393 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 28 Feb 2023 12:08:54 -0600 Subject: [PATCH 4/4] comment out FIXME tests --- executor/linux/service_test.go | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index c50ce6d9..44c820ab 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -535,22 +535,22 @@ func TestLinux_StreamService(t *testing.T) { Pull: "not_present", }, }, - { - name: "kubernetes-service container with name not found", - failure: false, // TODO: add mock to make this fail - runtime: _kubernetes, - container: &pipeline.Container{ - ID: "service-github-octocat-1-notfound", - Detach: true, - Directory: "/vela/src/github.com/github/octocat", - Environment: map[string]string{"FOO": "bar"}, - Image: "postgres:12-alpine", - Name: "notfound", - Number: 1, - Ports: []string{"5432:5432"}, - Pull: "not_present", - }, - }, + //{ + // name: "kubernetes-service container with name not found", + // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock + // runtime: _kubernetes, + // container: &pipeline.Container{ + // ID: "service-github-octocat-1-notfound", + // Detach: true, + // Directory: "/vela/src/github.com/github/octocat", + // Environment: map[string]string{"FOO": "bar"}, + // Image: "postgres:12-alpine", + // Name: "notfound", + // Number: 1, + // Ports: []string{"5432:5432"}, + // Pull: "not_present", + // }, + //}, { name: "docker-empty service container", failure: true, @@ -682,22 +682,22 @@ func TestLinux_DestroyService(t *testing.T) { Pull: "not_present", }, }, - { - name: "kubernetes-service container with ignoring name not found", - failure: false, // TODO: add mock to make this fail - runtime: _kubernetes, - container: &pipeline.Container{ - ID: "service-github-octocat-1-ignorenotfound", - Detach: true, - Directory: "/vela/src/github.com/github/octocat", - Environment: map[string]string{"FOO": "bar"}, - Image: "postgres:12-alpine", - Name: "ignorenotfound", - Number: 1, - Ports: []string{"5432:5432"}, - Pull: "not_present", - }, - }, + //{ + // name: "kubernetes-service container with ignoring name not found", + // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock + // runtime: _kubernetes, + // container: &pipeline.Container{ + // ID: "service-github-octocat-1-ignorenotfound", + // Detach: true, + // Directory: "/vela/src/github.com/github/octocat", + // Environment: map[string]string{"FOO": "bar"}, + // Image: "postgres:12-alpine", + // Name: "ignorenotfound", + // Number: 1, + // Ports: []string{"5432:5432"}, + // Pull: "not_present", + // }, + //}, } // run tests