From 9cce78d3059490f26bd9ce0f7a1283b95c17a12b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 8 Jan 2024 21:00:30 +0100 Subject: [PATCH 1/6] dont use step.name as ID --- pipeline/backend/kubernetes/kubernetes.go | 5 +++-- pipeline/backend/kubernetes/pod.go | 5 +++-- pipeline/backend/kubernetes/service.go | 6 +----- pipeline/backend/local/clone.go | 2 +- pipeline/backend/local/local.go | 8 ++++---- pipeline/error.go | 8 ++++---- pipeline/pipeline.go | 4 ++-- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pipeline/backend/kubernetes/kubernetes.go b/pipeline/backend/kubernetes/kubernetes.go index 4620dcfd20..22ee9ae14d 100644 --- a/pipeline/backend/kubernetes/kubernetes.go +++ b/pipeline/backend/kubernetes/kubernetes.go @@ -42,6 +42,7 @@ import ( const ( EngineName = "kubernetes" + podPrefix = "wp-" ) var defaultDeleteOptions = newDefaultDeleteOptions() @@ -204,7 +205,7 @@ func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string) // Wait for the pipeline step to complete and returns // the completion results. func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) (*types.State, error) { - podName, err := dnsName(step.Name) + podName, err := podName(step) if err != nil { return nil, err } @@ -264,7 +265,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) // Tail the pipeline step logs. func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string) (io.ReadCloser, error) { - podName, err := dnsName(step.Name) + podName, err := podName(step) if err != nil { return nil, err } diff --git a/pipeline/backend/kubernetes/pod.go b/pipeline/backend/kubernetes/pod.go index eb85f9f46e..cb21e7d239 100644 --- a/pipeline/backend/kubernetes/pod.go +++ b/pipeline/backend/kubernetes/pod.go @@ -31,7 +31,8 @@ import ( ) const ( - StepLabel = "step" + StepLabel = "step" + ServiceLabel = "service" ) func mkPod(namespace, name, image, workDir, goos, serviceAccountName string, @@ -67,7 +68,7 @@ func mkPod(namespace, name, image, workDir, goos, serviceAccountName string, } func podName(step *types.Step) (string, error) { - return dnsName(step.Name) + return dnsName(podPrefix + step.UUID) } func podMeta(name, namespace string, labels, annotations map[string]string) metav1.ObjectMeta { diff --git a/pipeline/backend/kubernetes/service.go b/pipeline/backend/kubernetes/service.go index 2fa66a462b..554f2405d0 100644 --- a/pipeline/backend/kubernetes/service.go +++ b/pipeline/backend/kubernetes/service.go @@ -51,12 +51,8 @@ func mkService(namespace, name string, ports []uint16, selector map[string]strin }, nil } -func serviceName(step *types.Step) (string, error) { - return dnsName(step.Name) -} - func startService(ctx context.Context, engine *kube, step *types.Step) (*v1.Service, error) { - name, err := serviceName(step) + name, err := dnsName(step.Name) if err != nil { return nil, err } diff --git a/pipeline/backend/local/clone.go b/pipeline/backend/local/clone.go index 083c018207..8dd2bc8169 100644 --- a/pipeline/backend/local/clone.go +++ b/pipeline/backend/local/clone.go @@ -107,7 +107,7 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow e.output, _ = cmd.StdoutPipe() cmd.Stderr = cmd.Stdout - state.stepCMDs[step.Name] = cmd + state.stepCMDs[step.UUID] = cmd return cmd.Start() } diff --git a/pipeline/backend/local/local.go b/pipeline/backend/local/local.go index 8b3cd52312..eaf103da4e 100644 --- a/pipeline/backend/local/local.go +++ b/pipeline/backend/local/local.go @@ -166,7 +166,7 @@ func (e *local) execCommands(ctx context.Context, step *types.Step, state *workf e.output = io.NopCloser(transform.NewReader(e.output, unicode.UTF8.NewDecoder().Transformer)) } - state.stepCMDs[step.Name] = cmd + state.stepCMDs[step.UUID] = cmd return cmd.Start() } @@ -186,7 +186,7 @@ func (e *local) execPlugin(ctx context.Context, step *types.Step, state *workflo e.output, _ = cmd.StdoutPipe() cmd.Stderr = cmd.Stdout - state.stepCMDs[step.Name] = cmd + state.stepCMDs[step.UUID] = cmd return cmd.Start() } @@ -201,9 +201,9 @@ func (e *local) WaitStep(_ context.Context, step *types.Step, taskUUID string) ( return nil, err } - cmd, ok := state.stepCMDs[step.Name] + cmd, ok := state.stepCMDs[step.UUID] if !ok { - return nil, fmt.Errorf("step cmd %s not found", step.Name) + return nil, fmt.Errorf("step cmd %s not found", step.UUID) } err = cmd.Wait() diff --git a/pipeline/error.go b/pipeline/error.go index 161e7db1f7..5e90904f33 100644 --- a/pipeline/error.go +++ b/pipeline/error.go @@ -31,22 +31,22 @@ var ( // An ExitError reports an unsuccessful exit. type ExitError struct { - Name string + UUID string Code int } // Error returns the error message in string format. func (e *ExitError) Error() string { - return fmt.Sprintf("%s : exit code %d", e.Name, e.Code) + return fmt.Sprintf("%s : exit code %d", e.UUID, e.Code) } // An OomError reports the process received an OOMKill from the kernel. type OomError struct { - Name string + UUID string Code int } // Error returns the error message in string format. func (e *OomError) Error() string { - return fmt.Sprintf("%s : received oom kill", e.Name) + return fmt.Sprintf("%s : received oom kill", e.UUID) } diff --git a/pipeline/pipeline.go b/pipeline/pipeline.go index 9d620eb380..2d560c8799 100644 --- a/pipeline/pipeline.go +++ b/pipeline/pipeline.go @@ -280,12 +280,12 @@ func (r *Runtime) exec(step *backend.Step) (*backend.State, error) { if waitState.OOMKilled { return waitState, &OomError{ - Name: step.Name, + UUID: step.UUID, Code: waitState.ExitCode, } } else if waitState.ExitCode != 0 { return waitState, &ExitError{ - Name: step.Name, + UUID: step.UUID, Code: waitState.ExitCode, } } From 449575a51ba2604d442b0475a62e4e57d8853cac Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 8 Jan 2024 22:03:00 +0100 Subject: [PATCH 2/6] rm unrelated --- pipeline/backend/kubernetes/kubernetes.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pipeline/backend/kubernetes/kubernetes.go b/pipeline/backend/kubernetes/kubernetes.go index 22ee9ae14d..4620dcfd20 100644 --- a/pipeline/backend/kubernetes/kubernetes.go +++ b/pipeline/backend/kubernetes/kubernetes.go @@ -42,7 +42,6 @@ import ( const ( EngineName = "kubernetes" - podPrefix = "wp-" ) var defaultDeleteOptions = newDefaultDeleteOptions() @@ -205,7 +204,7 @@ func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string) // Wait for the pipeline step to complete and returns // the completion results. func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) (*types.State, error) { - podName, err := podName(step) + podName, err := dnsName(step.Name) if err != nil { return nil, err } @@ -265,7 +264,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) // Tail the pipeline step logs. func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string) (io.ReadCloser, error) { - podName, err := podName(step) + podName, err := dnsName(step.Name) if err != nil { return nil, err } From ce8737807ce944c73c3504d0ba107ca9cb1aab6d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 8 Jan 2024 22:03:31 +0100 Subject: [PATCH 3/6] rm unrelated --- pipeline/backend/kubernetes/pod.go | 5 ++--- pipeline/backend/kubernetes/service.go | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pipeline/backend/kubernetes/pod.go b/pipeline/backend/kubernetes/pod.go index cb21e7d239..eb85f9f46e 100644 --- a/pipeline/backend/kubernetes/pod.go +++ b/pipeline/backend/kubernetes/pod.go @@ -31,8 +31,7 @@ import ( ) const ( - StepLabel = "step" - ServiceLabel = "service" + StepLabel = "step" ) func mkPod(namespace, name, image, workDir, goos, serviceAccountName string, @@ -68,7 +67,7 @@ func mkPod(namespace, name, image, workDir, goos, serviceAccountName string, } func podName(step *types.Step) (string, error) { - return dnsName(podPrefix + step.UUID) + return dnsName(step.Name) } func podMeta(name, namespace string, labels, annotations map[string]string) metav1.ObjectMeta { diff --git a/pipeline/backend/kubernetes/service.go b/pipeline/backend/kubernetes/service.go index 554f2405d0..2fa66a462b 100644 --- a/pipeline/backend/kubernetes/service.go +++ b/pipeline/backend/kubernetes/service.go @@ -51,8 +51,12 @@ func mkService(namespace, name string, ports []uint16, selector map[string]strin }, nil } +func serviceName(step *types.Step) (string, error) { + return dnsName(step.Name) +} + func startService(ctx context.Context, engine *kube, step *types.Step) (*v1.Service, error) { - name, err := dnsName(step.Name) + name, err := serviceName(step) if err != nil { return nil, err } From e80f661661929c7168351b3bfdca99e7b7c8bacc Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 8 Jan 2024 22:37:11 +0100 Subject: [PATCH 4/6] fix test --- pipeline/error_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipeline/error_test.go b/pipeline/error_test.go index 99c8ddb786..b2db70e6b3 100644 --- a/pipeline/error_test.go +++ b/pipeline/error_test.go @@ -20,7 +20,7 @@ import ( func TestExitError(t *testing.T) { err := ExitError{ - Name: "build", + UUID: "14534321", Code: 255, } got, want := err.Error(), "build : exit code 255" @@ -31,7 +31,7 @@ func TestExitError(t *testing.T) { func TestOomError(t *testing.T) { err := OomError{ - Name: "build", + UUID: "14534321", } got, want := err.Error(), "build : received oom kill" if got != want { From 7d57204c130a887bdac4e181615b36aadb6061ba Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 9 Jan 2024 00:46:20 +0100 Subject: [PATCH 5/6] fix tests and add uuid keyword --- pipeline/error.go | 4 ++-- pipeline/error_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pipeline/error.go b/pipeline/error.go index 5e90904f33..d2b39c3358 100644 --- a/pipeline/error.go +++ b/pipeline/error.go @@ -37,7 +37,7 @@ type ExitError struct { // Error returns the error message in string format. func (e *ExitError) Error() string { - return fmt.Sprintf("%s : exit code %d", e.UUID, e.Code) + return fmt.Sprintf("uuid=%s: exit code %d", e.UUID, e.Code) } // An OomError reports the process received an OOMKill from the kernel. @@ -48,5 +48,5 @@ type OomError struct { // Error returns the error message in string format. func (e *OomError) Error() string { - return fmt.Sprintf("%s : received oom kill", e.UUID) + return fmt.Sprintf("uuid=%s: received oom kill", e.UUID) } diff --git a/pipeline/error_test.go b/pipeline/error_test.go index b2db70e6b3..536895e8dd 100644 --- a/pipeline/error_test.go +++ b/pipeline/error_test.go @@ -23,7 +23,7 @@ func TestExitError(t *testing.T) { UUID: "14534321", Code: 255, } - got, want := err.Error(), "build : exit code 255" + got, want := err.Error(), "uuid=14534321: exit code 255" if got != want { t.Errorf("Want error message %q, got %q", want, got) } @@ -33,7 +33,7 @@ func TestOomError(t *testing.T) { err := OomError{ UUID: "14534321", } - got, want := err.Error(), "build : received oom kill" + got, want := err.Error(), "uuid=14534321: received oom kill" if got != want { t.Errorf("Want error message %q, got %q", want, got) } From b5510932b5da4c6cc0adeb4c44af453a7c986236 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 9 Jan 2024 05:39:32 +0100 Subject: [PATCH 6/6] Update pipeline/backend/local/local.go Co-authored-by: Anbraten --- pipeline/backend/local/local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/backend/local/local.go b/pipeline/backend/local/local.go index eaf103da4e..5eafe224e4 100644 --- a/pipeline/backend/local/local.go +++ b/pipeline/backend/local/local.go @@ -203,7 +203,7 @@ func (e *local) WaitStep(_ context.Context, step *types.Step, taskUUID string) ( cmd, ok := state.stepCMDs[step.UUID] if !ok { - return nil, fmt.Errorf("step cmd %s not found", step.UUID) + return nil, fmt.Errorf("step cmd for %s not found", step.UUID) } err = cmd.Wait()