Skip to content
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

Use step type to detect services in Kubernetes backend #3141

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@

extraHosts := []types.HostAlias{}
for _, stage := range conf.Stages {
if stage.Alias == "services" {
for _, step := range stage.Steps {
for _, step := range stage.Steps {
if step.Type == types.StepTypeService {

Check warning on line 177 in pipeline/backend/kubernetes/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/kubernetes.go#L176-L177

Added lines #L176 - L177 were not covered by tests
svc, err := startService(ctx, e, step)
if err != nil {
return err
Expand All @@ -196,6 +196,11 @@

// Start the pipeline step.
func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string) error {
if step.Type == types.StepTypeService {
// this one should be started by SetupWorkflow so we can ignore it
6543 marked this conversation as resolved.
Show resolved Hide resolved
log.Trace().Msgf("StartStep got service '%s', ignoring it.", step.Name)
return nil
}

Check warning on line 203 in pipeline/backend/kubernetes/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/kubernetes.go#L199-L203

Added lines #L199 - L203 were not covered by tests
log.Trace().Str("taskUUID", taskUUID).Msgf("Starting step: %s", step.Name)
_, err := startPod(ctx, e, step)
return err
Expand All @@ -204,7 +209,7 @@
// 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 := stepToPodName(step)

Check warning on line 212 in pipeline/backend/kubernetes/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/kubernetes.go#L212

Added line #L212 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -264,7 +269,7 @@

// 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 := stepToPodName(step)

Check warning on line 272 in pipeline/backend/kubernetes/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/kubernetes.go#L272

Added line #L272 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -327,13 +332,14 @@
}
}()
return rc, nil

// rc := io.NopCloser(bytes.NewReader(e.logs.Bytes()))
// e.logs.Reset()
// return rc, nil
}

func (e *kube) DestroyStep(_ context.Context, step *types.Step, taskUUID string) error {
if step.Type == types.StepTypeService {
// this one should be stopped by DestroyWorkflow so we can ignore it
6543 marked this conversation as resolved.
Show resolved Hide resolved
log.Trace().Msgf("DestroyStep got service '%s', ignoring it.", step.Name)
return nil
}

Check warning on line 342 in pipeline/backend/kubernetes/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/kubernetes.go#L338-L342

Added lines #L338 - L342 were not covered by tests
log.Trace().Str("taskUUID", taskUUID).Msgf("Stopping step: %s", step.Name)
err := stopPod(e.ctx, e, step, defaultDeleteOptions)
return err
Expand Down
7 changes: 7 additions & 0 deletions pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
return pod, nil
}

func stepToPodName(step *types.Step) (name string, err error) {
if step.Type == types.StepTypeService {
return serviceName(step)
}
return podName(step)

Check warning on line 73 in pipeline/backend/kubernetes/pod.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/pod.go#L69-L73

Added lines #L69 - L73 were not covered by tests
}

func podName(step *types.Step) (string, error) {
return dnsName(step.Name)
}
Expand Down