Skip to content

Commit

Permalink
dont use step.name as ID
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Jan 8, 2024
1 parent cd0c89c commit 9cce78d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
5 changes: 3 additions & 2 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

const (
EngineName = "kubernetes"
podPrefix = "wp-"
)

var defaultDeleteOptions = newDefaultDeleteOptions()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
)

const (
StepLabel = "step"
StepLabel = "step"
ServiceLabel = "service"
)

func mkPod(namespace, name, image, workDir, goos, serviceAccountName string,
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions pipeline/backend/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/local/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
8 changes: 4 additions & 4 deletions pipeline/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions pipeline/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 9cce78d

Please sign in to comment.