mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-08-16 10:33:57 +00:00
Use step type to detect services in Kubernetes backend (#3141)
and use the correct name for tail log --------- Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
549d095ff3
commit
31614d0e38
@ -173,8 +173,8 @@ func (e *kube) SetupWorkflow(ctx context.Context, conf *types.Config, taskUUID s
|
|||||||
|
|
||||||
extraHosts := []types.HostAlias{}
|
extraHosts := []types.HostAlias{}
|
||||||
for _, stage := range conf.Stages {
|
for _, stage := range conf.Stages {
|
||||||
if stage.Alias == "services" {
|
|
||||||
for _, step := range stage.Steps {
|
for _, step := range stage.Steps {
|
||||||
|
if step.Type == types.StepTypeService {
|
||||||
svc, err := startService(ctx, e, step)
|
svc, err := startService(ctx, e, step)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -196,6 +196,11 @@ func (e *kube) SetupWorkflow(ctx context.Context, conf *types.Config, taskUUID s
|
|||||||
|
|
||||||
// Start the pipeline step.
|
// Start the pipeline step.
|
||||||
func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string) error {
|
func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string) error {
|
||||||
|
if step.Type == types.StepTypeService {
|
||||||
|
// a service should be started by SetupWorkflow so we can ignore it
|
||||||
|
log.Trace().Msgf("StartStep got service '%s', ignoring it.", step.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
log.Trace().Str("taskUUID", taskUUID).Msgf("Starting step: %s", step.Name)
|
log.Trace().Str("taskUUID", taskUUID).Msgf("Starting step: %s", step.Name)
|
||||||
_, err := startPod(ctx, e, step)
|
_, err := startPod(ctx, e, step)
|
||||||
return err
|
return err
|
||||||
@ -204,7 +209,7 @@ func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string)
|
|||||||
// Wait for the pipeline step to complete and returns
|
// Wait for the pipeline step to complete and returns
|
||||||
// the completion results.
|
// the completion results.
|
||||||
func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) (*types.State, error) {
|
func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) (*types.State, error) {
|
||||||
podName, err := dnsName(step.Name)
|
podName, err := stepToPodName(step)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -264,7 +269,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)
|
|||||||
|
|
||||||
// Tail the pipeline step logs.
|
// Tail the pipeline step logs.
|
||||||
func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string) (io.ReadCloser, error) {
|
func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string) (io.ReadCloser, error) {
|
||||||
podName, err := dnsName(step.Name)
|
podName, err := stepToPodName(step)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -327,13 +332,14 @@ func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string)
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return rc, nil
|
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 {
|
func (e *kube) DestroyStep(_ context.Context, step *types.Step, taskUUID string) error {
|
||||||
|
if step.Type == types.StepTypeService {
|
||||||
|
// a service should be stopped by DestroyWorkflow so we can ignore it
|
||||||
|
log.Trace().Msgf("DestroyStep got service '%s', ignoring it.", step.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
log.Trace().Str("taskUUID", taskUUID).Msgf("Stopping step: %s", step.Name)
|
log.Trace().Str("taskUUID", taskUUID).Msgf("Stopping step: %s", step.Name)
|
||||||
err := stopPod(e.ctx, e, step, defaultDeleteOptions)
|
err := stopPod(e.ctx, e, step, defaultDeleteOptions)
|
||||||
return err
|
return err
|
||||||
|
@ -66,6 +66,13 @@ func mkPod(namespace, name, image, workDir, goos, serviceAccountName string,
|
|||||||
return pod, nil
|
return pod, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stepToPodName(step *types.Step) (name string, err error) {
|
||||||
|
if step.Type == types.StepTypeService {
|
||||||
|
return serviceName(step)
|
||||||
|
}
|
||||||
|
return podName(step)
|
||||||
|
}
|
||||||
|
|
||||||
func podName(step *types.Step) (string, error) {
|
func podName(step *types.Step) (string, error) {
|
||||||
return dnsName(step.Name)
|
return dnsName(step.Name)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user