diff --git a/pkg/apiserver/domain/model/project.go b/pkg/apiserver/domain/model/project.go index 6911b06b8..ff10fae5c 100644 --- a/pkg/apiserver/domain/model/project.go +++ b/pkg/apiserver/domain/model/project.go @@ -29,10 +29,14 @@ type Project struct { Alias string `json:"alias"` Owner string `json:"owner"` Description string `json:"description,omitempty"` + Namespace string `json:"namespace"` } // GetNamespace get the namespace name of this project. func (p *Project) GetNamespace() string { + if p.Namespace != "" { + return p.Namespace + } return fmt.Sprintf("project-%s", p.Name) } diff --git a/pkg/apiserver/domain/service/pipeline.go b/pkg/apiserver/domain/service/pipeline.go index 2350e78a0..554cc3d17 100644 --- a/pkg/apiserver/domain/service/pipeline.go +++ b/pkg/apiserver/domain/service/pipeline.go @@ -68,11 +68,12 @@ type PipelineService interface { } type pipelineServiceImpl struct { - ProjectService ProjectService `inject:""` - ContextService ContextService `inject:""` - KubeClient client.Client `inject:"kubeClient"` - KubeConfig *rest.Config `inject:"kubeConfig"` - Apply apply.Applicator `inject:"apply"` + ProjectService ProjectService `inject:""` + ContextService ContextService `inject:""` + KubeClient client.Client `inject:"kubeClient"` + KubeConfig *rest.Config `inject:"kubeConfig"` + Apply apply.Applicator `inject:"apply"` + PipelineRunService PipelineRunService `inject:""` } // PipelineRunService is the interface for pipelineRun service @@ -458,7 +459,11 @@ func (p pipelineServiceImpl) RunPipeline(ctx context.Context, pipeline apis.Pipe if err := p.KubeClient.Create(ctx, &run); err != nil { return nil, err } - return workflowRun2PipelineRun(run, project) + return p.PipelineRunService.GetPipelineRun(ctx, apis.PipelineRunMeta{ + PipelineName: pipeline.Name, + Project: apis.NameAlias{Name: project.Name}, + PipelineRunName: name, + }) } // GetPipelineRun will get a pipeline run @@ -693,9 +698,7 @@ func workflow2PipelineBase(wf v1alpha1.Workflow, p ProjectService) (*apis.Pipeli } func workflowRun2PipelineRun(run v1alpha1.WorkflowRun, project *model.Project) (*apis.PipelineRun, error) { - mergeSteps(&run) - return &apis.PipelineRun{ PipelineRunBase: apis.PipelineRunBase{ PipelineRunMeta: apis.PipelineRunMeta{ @@ -715,6 +718,9 @@ func workflowRun2PipelineRun(run v1alpha1.WorkflowRun, project *model.Project) ( } func mergeSteps(run *v1alpha1.WorkflowRun) { + if run.Spec.WorkflowSpec == nil { + return + } if run.Status.Steps == nil { run.Status.Steps = make([]v1alpha1.WorkflowStepStatus, 0) } diff --git a/pkg/apiserver/interfaces/api/pipeline.go b/pkg/apiserver/interfaces/api/pipeline.go index 56e07375b..96c9f002d 100644 --- a/pkg/apiserver/interfaces/api/pipeline.go +++ b/pkg/apiserver/interfaces/api/pipeline.go @@ -438,7 +438,7 @@ func (n *projectAPIInterface) deletePipelineRun(req *restful.Request, res *restf } func (n *projectAPIInterface) listContextValues(req *restful.Request, res *restful.Response) { - pipeline := req.Request.Context().Value(&apis.CtxKeyPipeline).(*apis.PipelineBase) + pipeline := req.Request.Context().Value(&apis.CtxKeyPipeline).(apis.PipelineBase) contextValues, err := n.ContextService.ListContexts(req.Request.Context(), pipeline.Project.Name, pipeline.Name) if err != nil { log.Logger.Errorf("list context values failure: %s", err.Error())