diff --git a/docs/apidoc/swagger.json b/docs/apidoc/swagger.json index 624f824ce..7154398b2 100644 --- a/docs/apidoc/swagger.json +++ b/docs/apidoc/swagger.json @@ -4884,7 +4884,7 @@ "parameters": [ { "type": "string", - "description": "query by specific id", + "description": "query by specific step name", "name": "step", "in": "query" }, @@ -7355,6 +7355,12 @@ "in": "path", "required": true }, + { + "type": "string", + "description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed", + "name": "dryRun", + "in": "query" + }, { "name": "body", "in": "body", @@ -8358,8 +8364,8 @@ }, "config.ClusterTargetStatus": { "required": [ - "namespace", "clusterName", + "namespace", "status", "application", "message" @@ -9444,12 +9450,12 @@ }, "v1.ApplicationDeployResponse": { "required": [ - "status", - "note", - "createTime", "envName", "triggerType", - "version" + "createTime", + "version", + "status", + "note" ], "properties": { "codeInfo": { @@ -10209,13 +10215,13 @@ }, "v1.ConfigTemplateDetail": { "required": [ + "name", "namespace", "description", "scope", "sensitive", "createTime", "alias", - "name", "schema", "uiSchema" ], @@ -11035,10 +11041,10 @@ }, "v1.DetailAddonResponse": { "required": [ - "version", - "description", - "icon", "name", + "version", + "icon", + "description", "invisible", "schema", "uiSchema", @@ -11119,13 +11125,13 @@ }, "v1.DetailApplicationResponse": { "required": [ - "updateTime", + "createTime", + "icon", "name", "alias", "project", "description", - "createTime", - "icon", + "updateTime", "policies", "envBindings", "resourceInfo" @@ -11182,20 +11188,20 @@ }, "v1.DetailClusterResponse": { "required": [ + "createTime", + "description", + "kubeConfig", + "kubeConfigSecret", "updateTime", "name", - "apiServerURL", - "kubeConfigSecret", - "createTime", - "alias", - "provider", - "kubeConfig", - "description", - "icon", - "reason", - "labels", "status", + "reason", + "provider", + "apiServerURL", "dashboardURL", + "icon", + "labels", + "alias", "resourceInfo" ], "properties": { @@ -11253,14 +11259,14 @@ }, "v1.DetailComponentResponse": { "required": [ - "appPrimaryKey", - "main", - "createTime", - "type", - "name", - "alias", - "updateTime", "creator", + "name", + "type", + "main", + "updateTime", + "alias", + "createTime", + "appPrimaryKey", "definition" ], "properties": { @@ -11348,12 +11354,12 @@ }, "v1.DetailDefinitionResponse": { "required": [ - "description", "status", "ownerAddon", - "name", "alias", + "description", "icon", + "name", "labels", "schema", "uiSchema" @@ -11413,13 +11419,13 @@ "required": [ "name", "alias", + "description", + "updateTime", + "type", "creator", "properties", "createTime", - "updateTime", - "envName", - "type", - "description" + "envName" ], "properties": { "alias": { @@ -11461,18 +11467,18 @@ }, "v1.DetailRevisionResponse": { "required": [ + "createTime", + "appPrimaryKey", + "triggerType", + "workflowName", + "envName", "version", "revisionCRName", - "workflowName", - "reason", - "updateTime", - "appPrimaryKey", - "envName", - "createTime", "status", + "reason", "deployUser", - "note", - "triggerType" + "updateTime", + "note" ], "properties": { "appPrimaryKey": { @@ -11529,10 +11535,10 @@ }, "v1.DetailTargetResponse": { "required": [ - "updateTime", - "project", "name", - "createTime" + "createTime", + "updateTime", + "project" ], "properties": { "alias": { @@ -11572,11 +11578,11 @@ }, "v1.DetailUserResponse": { "required": [ - "email", - "disabled", "createTime", "lastLoginTime", "name", + "email", + "disabled", "projects", "roles" ], @@ -11617,12 +11623,12 @@ }, "v1.DetailWorkflowRecordResponse": { "required": [ - "workflowAlias", - "applicationRevision", "status", "name", "namespace", "workflowName", + "workflowAlias", + "applicationRevision", "deployTime", "deployUser", "note", @@ -11674,14 +11680,14 @@ }, "v1.DetailWorkflowResponse": { "required": [ - "alias", "enable", - "envName", - "name", - "description", "default", + "envName", "createTime", - "updateTime" + "updateTime", + "alias", + "description", + "name" ], "properties": { "alias": { @@ -11914,8 +11920,8 @@ "v1.GetPipelineResponse": { "required": [ "project", - "name", "spec", + "name", "info" ], "properties": { @@ -11941,14 +11947,27 @@ }, "v1.GetPipelineRunLogResponse": { "required": [ + "id", + "name", + "type", + "phase", "log" ], "properties": { + "id": { + "type": "string" + }, "log": { - "type": "array", - "items": { - "$ref": "#/definitions/v1.Log" - } + "type": "string" + }, + "name": { + "type": "string" + }, + "phase": { + "type": "string" + }, + "type": { + "type": "string" } } }, @@ -11960,7 +11979,7 @@ "output": { "type": "array", "items": { - "$ref": "#/definitions/v1.Output" + "$ref": "#/definitions/v1.StepOutput" } } } @@ -12526,32 +12545,6 @@ } } }, - "v1.Log": { - "required": [ - "id", - "name", - "type", - "phase", - "log" - ], - "properties": { - "id": { - "type": "string" - }, - "log": { - "type": "string" - }, - "name": { - "type": "string" - }, - "phase": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "v1.LoginRequest": { "properties": { "code": { @@ -12585,11 +12578,11 @@ }, "v1.LoginUserInfoResponse": { "required": [ + "email", + "disabled", "createTime", "lastLoginTime", "name", - "email", - "disabled", "projects", "platformPermissions", "projectPermissions" @@ -12729,35 +12722,6 @@ } } }, - "v1.Output": { - "required": [ - "id", - "name", - "type", - "phase", - "vars" - ], - "properties": { - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "phase": { - "type": "string" - }, - "type": { - "type": "string" - }, - "vars": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, "v1.PermissionBase": { "required": [ "name", @@ -12802,8 +12766,8 @@ }, "v1.PipelineBase": { "required": [ - "project", "name", + "project", "spec" ], "properties": { @@ -12891,8 +12855,8 @@ }, "v1.PipelineMetaResponse": { "required": [ - "name", - "project" + "project", + "name" ], "properties": { "alias": { @@ -12911,9 +12875,9 @@ }, "v1.PipelineRunBase": { "required": [ + "pipelineName", "project", "pipelineRunName", - "pipelineName", "record", "contextName", "spec" @@ -13331,6 +13295,52 @@ } } }, + "v1.StepOutput": { + "required": [ + "outputs", + "subStepOutputs" + ], + "properties": { + "outputs": { + "$ref": "#/definitions/v1.StepOutputBase" + }, + "subStepOutputs": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.StepOutputBase" + } + } + } + }, + "v1.StepOutputBase": { + "required": [ + "id", + "name", + "type", + "phase", + "vars" + ], + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "phase": { + "type": "string" + }, + "type": { + "type": "string" + }, + "vars": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, "v1.SystemInfo": { "required": [ "platformID", @@ -13390,9 +13400,9 @@ }, "v1.SystemInfoResponse": { "required": [ - "loginType", "platformID", "enableCollection", + "loginType", "systemVersion" ], "properties": { @@ -14022,6 +14032,9 @@ }, "v1alpha1.WorkflowRunSpec": { "properties": { + "context": { + "type": "string" + }, "mode": { "$ref": "#/definitions/v1alpha1.WorkflowExecuteMode" }, diff --git a/pkg/addon/addon.go b/pkg/addon/addon.go index 0dbdc6dec..e422546ed 100644 --- a/pkg/addon/addon.go +++ b/pkg/addon/addon.go @@ -612,7 +612,7 @@ func unmarshalToContent(content []byte) (fileContent *github.RepositoryContent, } func genAddonAPISchema(addonRes *UIData) error { - cueScript := script.CUE([]byte(addonRes.Parameters)) + cueScript := script.CUE(addonRes.Parameters) schema, err := cueScript.ParsePropertiesToSchema() if err != nil { return err diff --git a/pkg/apiserver/domain/service/pipeline.go b/pkg/apiserver/domain/service/pipeline.go index fa9af38c6..25fd3db29 100644 --- a/pkg/apiserver/domain/service/pipeline.go +++ b/pkg/apiserver/domain/service/pipeline.go @@ -93,11 +93,13 @@ type pipelineRunServiceImpl struct { // ContextService is the interface for context service type ContextService interface { + InitContext(ctx context.Context, projectName, pipelineName string) error GetContext(ctx context.Context, projectName, pipelineName string, name string) (*apis.Context, error) CreateContext(ctx context.Context, projectName, pipelineName string, context apis.Context) (*model.PipelineContext, error) UpdateContext(ctx context.Context, projectName, pipelineName string, context apis.Context) (*model.PipelineContext, error) ListContexts(ctx context.Context, projectName, pipelineName string) (*apis.ListContextValueResponse, error) DeleteContext(ctx context.Context, projectName, pipelineName, name string) error + DeleteAllContexts(ctx context.Context, projectName, pipelineName string) error } type contextServiceImpl struct { @@ -158,6 +160,7 @@ func (p pipelineServiceImpl) ListPipelines(ctx context.Context, req apis.ListPip item := apis.PipelineListItem{ PipelineMeta: workflow2PipelineBase(wf).PipelineMeta, // todo info + Info: apis.PipelineInfo{}, } res.Pipelines = append(res.Pipelines, item) } @@ -444,6 +447,19 @@ func (p pipelineRunServiceImpl) DeletePipelineRun(ctx context.Context, meta apis return p.KubeClient.Delete(ctx, &run) } +// InitContext will init pipeline context record +func (c contextServiceImpl) InitContext(ctx context.Context, projectName, pipelineName string) error { + modelCtx := model.PipelineContext{ + ProjectName: projectName, + PipelineName: pipelineName, + } + if err := c.Store.Get(ctx, &modelCtx); err == nil { + return errors.New("pipeline contexts record already exists") + } + modelCtx.Contexts = make(map[string][]model.Value) + return c.Store.Add(ctx, &modelCtx) +} + // GetContext will get a context func (c contextServiceImpl) GetContext(ctx context.Context, projectName, pipelineName, name string) (*apis.Context, error) { modelCtx := model.PipelineContext{ @@ -521,10 +537,16 @@ func (c contextServiceImpl) DeleteContext(ctx context.Context, projectName, pipe return err } delete(modelCtx.Contexts, name) - if err := c.Store.Put(ctx, &modelCtx); err != nil { - return err + return c.Store.Put(ctx, &modelCtx) +} + +// DeleteAllContexts will delete all contexts of a pipeline +func (c contextServiceImpl) DeleteAllContexts(ctx context.Context, projectName, pipelineName string) error { + modelCtx := model.PipelineContext{ + ProjectName: projectName, + PipelineName: pipelineName, } - return nil + return c.Store.Delete(ctx, &modelCtx) } func nsForProj(proj string) string { @@ -559,7 +581,7 @@ func fuzzyMatch(wf v1alpha1.Workflow, q string) bool { } func workflow2PipelineBase(wf v1alpha1.Workflow) *apis.PipelineBase { - project := strings.TrimRight(wf.Namespace, "-project") + project := strings.TrimPrefix(wf.Namespace, "project-") return &apis.PipelineBase{ PipelineMeta: apis.PipelineMeta{ Name: wf.Name, diff --git a/pkg/apiserver/infrastructure/clients/kubeclient.go b/pkg/apiserver/infrastructure/clients/kubeclient.go index 436773a31..9fd402546 100644 --- a/pkg/apiserver/infrastructure/clients/kubeclient.go +++ b/pkg/apiserver/infrastructure/clients/kubeclient.go @@ -20,15 +20,17 @@ import ( "fmt" pkgmulticluster "github.com/kubevela/pkg/multicluster" + "github.com/kubevela/workflow/pkg/cue/packages" + "github.com/pkg/errors" "k8s.io/client-go/discovery" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" - "github.com/kubevela/workflow/pkg/cue/packages" - + "github.com/kubevela/workflow/api/v1alpha1" apiConfig "github.com/oam-dev/kubevela/pkg/apiserver/config" "github.com/oam-dev/kubevela/pkg/auth" + "github.com/oam-dev/kubevela/pkg/multicluster" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" "github.com/oam-dev/kubevela/pkg/utils/common" ) @@ -77,7 +79,23 @@ func GetKubeClient() (client.Client, error) { kubeClient, err = pkgmulticluster.NewClient(kubeConfig, pkgmulticluster.ClientOptions{ Options: client.Options{Scheme: common.Scheme}, }) - return kubeClient, err + err = v1alpha1.AddToScheme(common.Scheme) + if err != nil { + return nil, err + } + kubeClient, err = multicluster.Initialize(kubeConfig, false) + if err == nil { + return kubeClient, nil + } + if !errors.Is(err, multicluster.ErrDetectClusterGateway) { + return nil, err + } + // create single cluster client + kubeClient, err = client.New(kubeConfig, client.Options{Scheme: common.Scheme}) + if err != nil { + return nil, err + } + return kubeClient, nil } // GetKubeConfig create/get kube runtime config diff --git a/pkg/apiserver/interfaces/api/pipeline.go b/pkg/apiserver/interfaces/api/pipeline.go index c4078496a..d1f735f01 100644 --- a/pkg/apiserver/interfaces/api/pipeline.go +++ b/pkg/apiserver/interfaces/api/pipeline.go @@ -247,6 +247,13 @@ func (p *pipelineAPIInterface) createPipeline(req *restful.Request, res *restful bcode.ReturnError(req, res, err) return } + err = p.ContextService.InitContext(req.Request.Context(), pipelineBase.Project, pipelineBase.Name) + if err != nil { + log.Logger.Errorf("init pipeline context failure: %s", err.Error()) + bcode.ReturnError(req, res, err) + return + } + if err := res.WriteEntity(pipelineBase); err != nil { bcode.ReturnError(req, res, err) return @@ -284,7 +291,13 @@ func (p *pipelineAPIInterface) deletePipeline(req *restful.Request, res *restful bcode.ReturnError(req, res, err) return } + if err := p.ContextService.DeleteAllContexts(req.Request.Context(), pipeline.Project, pipeline.Name); err != nil { + log.Logger.Errorf("delete pipeline all context failure %s", err.Error()) + bcode.ReturnError(req, res, err) + return + } if err := res.WriteEntity(pipeline.PipelineMeta); err != nil { + log.Logger.Errorf("delete pipeline failure %s", err.Error()) bcode.ReturnError(req, res, err) return } @@ -293,7 +306,7 @@ func (p *pipelineAPIInterface) deletePipeline(req *restful.Request, res *restful func (p *pipelineAPIInterface) runPipeline(req *restful.Request, res *restful.Response) { var runReq apis.RunPipelineRequest pipeline := req.Request.Context().Value(&apis.CtxKeyPipeline).(apis.PipelineBase) - if err := req.ReadEntity(runReq); err != nil { + if err := req.ReadEntity(&runReq); err != nil { bcode.ReturnError(req, res, err) return } @@ -400,7 +413,7 @@ func (p *pipelineAPIInterface) listContextValues(req *restful.Request, res *rest pipeline := req.Request.Context().Value(&apis.CtxKeyPipeline).(apis.PipelineBase) contextValues, err := p.ContextService.ListContexts(req.Request.Context(), pipeline.Project, pipeline.Name) if err != nil { - log.Logger.Errorf("list context values failure %s", err.Error()) + log.Logger.Errorf("list context values failure: %s", err.Error()) bcode.ReturnError(req, res, err) return }