From d6466368c1122d5872e137470a6ac81bf01a206d Mon Sep 17 00:00:00 2001 From: Tianxin Dong Date: Tue, 8 Nov 2022 15:05:27 +0800 Subject: [PATCH] Feat: add scope label in workflow step defs (#4980) Signed-off-by: FogDong Signed-off-by: FogDong --- apis/types/types.go | 2 ++ .../apply-application-in-parallel.yaml | 1 + .../defwithtemplate/apply-application.yaml | 1 + .../templates/defwithtemplate/apply-remaining.yaml | 1 + .../defwithtemplate/deploy-cloud-resource.yaml | 2 ++ .../templates/defwithtemplate/deploy.yaml | 2 ++ .../templates/defwithtemplate/deploy2env.yaml | 1 + .../templates/defwithtemplate/deploy2runtime.yaml | 1 + .../defwithtemplate/share-cloud-resource.yaml | 2 ++ .../apply-application-in-parallel.yaml | 1 + .../defwithtemplate/apply-application.yaml | 1 + .../templates/defwithtemplate/apply-remaining.yaml | 1 + .../defwithtemplate/deploy-cloud-resource.yaml | 2 ++ .../templates/defwithtemplate/deploy.yaml | 2 ++ .../templates/defwithtemplate/deploy2runtime.yaml | 1 + .../defwithtemplate/share-cloud-resource.yaml | 2 ++ pkg/apiserver/domain/service/definition.go | 14 ++++++++++++++ pkg/apiserver/domain/service/definition_test.go | 5 +++++ .../service/testdata/applyapplication-sd.yaml | 2 ++ pkg/apiserver/interfaces/api/definition.go | 2 ++ .../workflowstep/apply-application-in-parallel.cue | 1 + .../internal/workflowstep/apply-application.cue | 1 + .../internal/workflowstep/apply-remaining.cue | 1 + .../workflowstep/deploy-cloud-resource.cue | 4 +++- .../definitions/internal/workflowstep/deploy.cue | 4 +++- .../internal/workflowstep/deploy2env.cue | 1 + .../internal/workflowstep/deploy2runtime.cue | 1 + .../internal/workflowstep/share-cloud-resource.cue | 4 +++- 28 files changed, 60 insertions(+), 3 deletions(-) diff --git a/apis/types/types.go b/apis/types/types.go index 4cd63623e..3882622cc 100644 --- a/apis/types/types.go +++ b/apis/types/types.go @@ -64,6 +64,8 @@ const ( LabelDefinitionDeprecated = "custom.definition.oam.dev/deprecated" // LabelDefinitionHidden is the label which describe whether the capability is hidden by UI LabelDefinitionHidden = "custom.definition.oam.dev/ui-hidden" + // LabelDefinitionScope is the label which describe whether the capability's scope + LabelDefinitionScope = "custom.definition.oam.dev/scope" // LabelNodeRoleGateway gateway role of node LabelNodeRoleGateway = "node-role.kubernetes.io/gateway" // LabelNodeRoleWorker worker role of node diff --git a/charts/vela-core/templates/defwithtemplate/apply-application-in-parallel.yaml b/charts/vela-core/templates/defwithtemplate/apply-application-in-parallel.yaml index 9b95d3ab2..e95251784 100644 --- a/charts/vela-core/templates/defwithtemplate/apply-application-in-parallel.yaml +++ b/charts/vela-core/templates/defwithtemplate/apply-application-in-parallel.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Apply components of an application in parallel for your workflow steps labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: apply-application-in-parallel namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-core/templates/defwithtemplate/apply-application.yaml b/charts/vela-core/templates/defwithtemplate/apply-application.yaml index a61817188..7c3e56904 100644 --- a/charts/vela-core/templates/defwithtemplate/apply-application.yaml +++ b/charts/vela-core/templates/defwithtemplate/apply-application.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Apply application for your workflow steps, it has no arguments, should be used for custom steps before or after application applied. labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: apply-application namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml b/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml index a4bb82cec..aac014cd9 100644 --- a/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml +++ b/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Apply remaining components and traits labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: apply-remaining namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-core/templates/defwithtemplate/deploy-cloud-resource.yaml b/charts/vela-core/templates/defwithtemplate/deploy-cloud-resource.yaml index c47dc2132..cddb48d28 100644 --- a/charts/vela-core/templates/defwithtemplate/deploy-cloud-resource.yaml +++ b/charts/vela-core/templates/defwithtemplate/deploy-cloud-resource.yaml @@ -5,6 +5,8 @@ kind: WorkflowStepDefinition metadata: annotations: definition.oam.dev/description: Deploy cloud resource and deliver secret to multi clusters. + labels: + custom.definition.oam.dev/scope: Application name: deploy-cloud-resource namespace: {{ include "systemDefinitionNamespace" . }} spec: diff --git a/charts/vela-core/templates/defwithtemplate/deploy.yaml b/charts/vela-core/templates/defwithtemplate/deploy.yaml index e7120759f..1da9cc32b 100644 --- a/charts/vela-core/templates/defwithtemplate/deploy.yaml +++ b/charts/vela-core/templates/defwithtemplate/deploy.yaml @@ -5,6 +5,8 @@ kind: WorkflowStepDefinition metadata: annotations: definition.oam.dev/description: A powerful and unified deploy step for components multi-cluster delivery with policies. + labels: + custom.definition.oam.dev/scope: Application name: deploy namespace: {{ include "systemDefinitionNamespace" . }} spec: diff --git a/charts/vela-core/templates/defwithtemplate/deploy2env.yaml b/charts/vela-core/templates/defwithtemplate/deploy2env.yaml index 928b866b0..19e3842fa 100644 --- a/charts/vela-core/templates/defwithtemplate/deploy2env.yaml +++ b/charts/vela-core/templates/defwithtemplate/deploy2env.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Deploy env binding component to target env labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: deploy2env namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-core/templates/defwithtemplate/deploy2runtime.yaml b/charts/vela-core/templates/defwithtemplate/deploy2runtime.yaml index 01b895e07..31ba57af3 100644 --- a/charts/vela-core/templates/defwithtemplate/deploy2runtime.yaml +++ b/charts/vela-core/templates/defwithtemplate/deploy2runtime.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Deploy application to runtime clusters labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: deploy2runtime namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-core/templates/defwithtemplate/share-cloud-resource.yaml b/charts/vela-core/templates/defwithtemplate/share-cloud-resource.yaml index aac98dc9f..88c5d98ae 100644 --- a/charts/vela-core/templates/defwithtemplate/share-cloud-resource.yaml +++ b/charts/vela-core/templates/defwithtemplate/share-cloud-resource.yaml @@ -5,6 +5,8 @@ kind: WorkflowStepDefinition metadata: annotations: definition.oam.dev/description: Sync secrets created by terraform component to runtime clusters so that runtime clusters can share the created cloud resource. + labels: + custom.definition.oam.dev/scope: Application name: share-cloud-resource namespace: {{ include "systemDefinitionNamespace" . }} spec: diff --git a/charts/vela-minimal/templates/defwithtemplate/apply-application-in-parallel.yaml b/charts/vela-minimal/templates/defwithtemplate/apply-application-in-parallel.yaml index 9b95d3ab2..e95251784 100644 --- a/charts/vela-minimal/templates/defwithtemplate/apply-application-in-parallel.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/apply-application-in-parallel.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Apply components of an application in parallel for your workflow steps labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: apply-application-in-parallel namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-minimal/templates/defwithtemplate/apply-application.yaml b/charts/vela-minimal/templates/defwithtemplate/apply-application.yaml index a61817188..7c3e56904 100644 --- a/charts/vela-minimal/templates/defwithtemplate/apply-application.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/apply-application.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Apply application for your workflow steps, it has no arguments, should be used for custom steps before or after application applied. labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: apply-application namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-minimal/templates/defwithtemplate/apply-remaining.yaml b/charts/vela-minimal/templates/defwithtemplate/apply-remaining.yaml index a4bb82cec..aac014cd9 100644 --- a/charts/vela-minimal/templates/defwithtemplate/apply-remaining.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/apply-remaining.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Apply remaining components and traits labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: apply-remaining namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-minimal/templates/defwithtemplate/deploy-cloud-resource.yaml b/charts/vela-minimal/templates/defwithtemplate/deploy-cloud-resource.yaml index c47dc2132..cddb48d28 100644 --- a/charts/vela-minimal/templates/defwithtemplate/deploy-cloud-resource.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/deploy-cloud-resource.yaml @@ -5,6 +5,8 @@ kind: WorkflowStepDefinition metadata: annotations: definition.oam.dev/description: Deploy cloud resource and deliver secret to multi clusters. + labels: + custom.definition.oam.dev/scope: Application name: deploy-cloud-resource namespace: {{ include "systemDefinitionNamespace" . }} spec: diff --git a/charts/vela-minimal/templates/defwithtemplate/deploy.yaml b/charts/vela-minimal/templates/defwithtemplate/deploy.yaml index e7120759f..1da9cc32b 100644 --- a/charts/vela-minimal/templates/defwithtemplate/deploy.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/deploy.yaml @@ -5,6 +5,8 @@ kind: WorkflowStepDefinition metadata: annotations: definition.oam.dev/description: A powerful and unified deploy step for components multi-cluster delivery with policies. + labels: + custom.definition.oam.dev/scope: Application name: deploy namespace: {{ include "systemDefinitionNamespace" . }} spec: diff --git a/charts/vela-minimal/templates/defwithtemplate/deploy2runtime.yaml b/charts/vela-minimal/templates/defwithtemplate/deploy2runtime.yaml index 01b895e07..31ba57af3 100644 --- a/charts/vela-minimal/templates/defwithtemplate/deploy2runtime.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/deploy2runtime.yaml @@ -7,6 +7,7 @@ metadata: definition.oam.dev/description: Deploy application to runtime clusters labels: custom.definition.oam.dev/deprecated: "true" + custom.definition.oam.dev/scope: Application custom.definition.oam.dev/ui-hidden: "true" name: deploy2runtime namespace: {{ include "systemDefinitionNamespace" . }} diff --git a/charts/vela-minimal/templates/defwithtemplate/share-cloud-resource.yaml b/charts/vela-minimal/templates/defwithtemplate/share-cloud-resource.yaml index aac98dc9f..88c5d98ae 100644 --- a/charts/vela-minimal/templates/defwithtemplate/share-cloud-resource.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/share-cloud-resource.yaml @@ -5,6 +5,8 @@ kind: WorkflowStepDefinition metadata: annotations: definition.oam.dev/description: Sync secrets created by terraform component to runtime clusters so that runtime clusters can share the created cloud resource. + labels: + custom.definition.oam.dev/scope: Application name: share-cloud-resource namespace: {{ include "systemDefinitionNamespace" . }} spec: diff --git a/pkg/apiserver/domain/service/definition.go b/pkg/apiserver/domain/service/definition.go index 28eaa7821..1d72dda95 100644 --- a/pkg/apiserver/domain/service/definition.go +++ b/pkg/apiserver/domain/service/definition.go @@ -69,6 +69,7 @@ type DefinitionQueryOption struct { AppliedWorkloads string `json:"appliedWorkloads"` OwnerAddon string `json:"sourceAddon"` QueryAll bool `json:"queryAll"` + Scope string `json:"scope"` } // String return cache key string @@ -109,6 +110,19 @@ func (d *definitionServiceImpl) listDefinitions(ctx context.Context, list *unstr }, }, } + if ops.Scope != "" { + var filterScope string + if ops.Scope == "Application" { + filterScope = "WorkflowRun" + } else { + filterScope = "Application" + } + matchLabels.MatchExpressions = append(matchLabels.MatchExpressions, metav1.LabelSelectorRequirement{ + Key: types.LabelDefinitionScope, + Operator: metav1.LabelSelectorOpNotIn, + Values: []string{filterScope}, + }) + } if !ops.QueryAll { matchLabels.MatchExpressions = append(matchLabels.MatchExpressions, metav1.LabelSelectorRequirement{ Key: types.LabelDefinitionHidden, diff --git a/pkg/apiserver/domain/service/definition_test.go b/pkg/apiserver/domain/service/definition_test.go index 79cef40aa..34b4ad37e 100644 --- a/pkg/apiserver/domain/service/definition_test.go +++ b/pkg/apiserver/domain/service/definition_test.go @@ -112,6 +112,11 @@ var _ = Describe("Test namespace service functions", func() { Expect(wfstep[0].WorkflowStep.Schematic).ShouldNot(BeNil()) Expect(wfstep[0].Alias).Should(Equal("test-alias")) + wfstep, err = definitionService.ListDefinitions(context.TODO(), DefinitionQueryOption{Type: "workflowstep", Scope: "WorkflowRun"}) + Expect(err).Should(BeNil()) + // the definition should be filtered + Expect(cmp.Diff(len(wfstep), 1)).Should(BeEmpty()) + step, err = ioutil.ReadFile("./testdata/apply-application-hide.yaml") Expect(err).Should(Succeed()) var sd2 v1beta1.WorkflowStepDefinition diff --git a/pkg/apiserver/domain/service/testdata/applyapplication-sd.yaml b/pkg/apiserver/domain/service/testdata/applyapplication-sd.yaml index c1c141be4..98397e6c3 100644 --- a/pkg/apiserver/domain/service/testdata/applyapplication-sd.yaml +++ b/pkg/apiserver/domain/service/testdata/applyapplication-sd.yaml @@ -8,6 +8,8 @@ metadata: definition.oam.dev/alias: test-alias name: apply-application namespace: vela-system + labels: + custom.definition.oam.dev/scope: Application spec: schematic: cue: diff --git a/pkg/apiserver/interfaces/api/definition.go b/pkg/apiserver/interfaces/api/definition.go index b3b2954f8..a8afdd942 100644 --- a/pkg/apiserver/interfaces/api/definition.go +++ b/pkg/apiserver/interfaces/api/definition.go @@ -51,6 +51,7 @@ func (d *definitionAPIInterface) GetWebServiceRoute() *restful.WebService { Param(ws.QueryParameter("queryAll", "query all definitions include hidden in UI").DataType("boolean").DefaultValue("false")). Param(ws.QueryParameter("appliedWorkload", "if specified, query the trait definition applied to the workload").DataType("string")). Param(ws.QueryParameter("ownerAddon", "query by which addon created the definition").DataType("string")). + Param(ws.QueryParameter("scope", "query by the specified scope like WorkflowRun or Application").DataType("string")). Returns(200, "OK", apis.ListDefinitionResponse{}). Writes(apis.ListDefinitionResponse{}).Do(returns200, returns500)) @@ -97,6 +98,7 @@ func (d *definitionAPIInterface) listDefinitions(req *restful.Request, res *rest Type: req.QueryParameter("type"), AppliedWorkloads: req.QueryParameter("appliedWorkload"), OwnerAddon: req.QueryParameter("ownerAddon"), + Scope: req.QueryParameter("scope"), QueryAll: queryAll, }) if err != nil { diff --git a/vela-templates/definitions/internal/workflowstep/apply-application-in-parallel.cue b/vela-templates/definitions/internal/workflowstep/apply-application-in-parallel.cue index cee280959..14a454b18 100644 --- a/vela-templates/definitions/internal/workflowstep/apply-application-in-parallel.cue +++ b/vela-templates/definitions/internal/workflowstep/apply-application-in-parallel.cue @@ -8,6 +8,7 @@ import ( labels: { "ui-hidden": "true" "deprecated": "true" + "scope": "Application" } description: "Apply components of an application in parallel for your workflow steps" } diff --git a/vela-templates/definitions/internal/workflowstep/apply-application.cue b/vela-templates/definitions/internal/workflowstep/apply-application.cue index 1136784f2..d35d516f3 100644 --- a/vela-templates/definitions/internal/workflowstep/apply-application.cue +++ b/vela-templates/definitions/internal/workflowstep/apply-application.cue @@ -8,6 +8,7 @@ import ( labels: { "ui-hidden": "true" "deprecated": "true" + "scope": "Application" } description: "Apply application for your workflow steps, it has no arguments, should be used for custom steps before or after application applied." } diff --git a/vela-templates/definitions/internal/workflowstep/apply-remaining.cue b/vela-templates/definitions/internal/workflowstep/apply-remaining.cue index 5b0e86080..b8249a8fe 100644 --- a/vela-templates/definitions/internal/workflowstep/apply-remaining.cue +++ b/vela-templates/definitions/internal/workflowstep/apply-remaining.cue @@ -8,6 +8,7 @@ import ( labels: { "ui-hidden": "true" "deprecated": "true" + "scope": "Application" } description: "Apply remaining components and traits" } diff --git a/vela-templates/definitions/internal/workflowstep/deploy-cloud-resource.cue b/vela-templates/definitions/internal/workflowstep/deploy-cloud-resource.cue index 0adaa7e35..ec93d84ea 100644 --- a/vela-templates/definitions/internal/workflowstep/deploy-cloud-resource.cue +++ b/vela-templates/definitions/internal/workflowstep/deploy-cloud-resource.cue @@ -5,7 +5,9 @@ import ( "deploy-cloud-resource": { type: "workflow-step" annotations: {} - labels: {} + labels: { + "scope": "Application" + } description: "Deploy cloud resource and deliver secret to multi clusters." } template: { diff --git a/vela-templates/definitions/internal/workflowstep/deploy.cue b/vela-templates/definitions/internal/workflowstep/deploy.cue index 949b36e45..48ebaeec3 100644 --- a/vela-templates/definitions/internal/workflowstep/deploy.cue +++ b/vela-templates/definitions/internal/workflowstep/deploy.cue @@ -5,7 +5,9 @@ import ( "deploy": { type: "workflow-step" annotations: {} - labels: {} + labels: { + "scope": "Application" + } description: "A powerful and unified deploy step for components multi-cluster delivery with policies." } template: { diff --git a/vela-templates/definitions/internal/workflowstep/deploy2env.cue b/vela-templates/definitions/internal/workflowstep/deploy2env.cue index 41e0227f3..b29b097f5 100644 --- a/vela-templates/definitions/internal/workflowstep/deploy2env.cue +++ b/vela-templates/definitions/internal/workflowstep/deploy2env.cue @@ -8,6 +8,7 @@ import ( labels: { "ui-hidden": "true" "deprecated": "true" + "scope": "Application" } description: "Deploy env binding component to target env" } diff --git a/vela-templates/definitions/internal/workflowstep/deploy2runtime.cue b/vela-templates/definitions/internal/workflowstep/deploy2runtime.cue index de21db1f0..6965a4cf1 100644 --- a/vela-templates/definitions/internal/workflowstep/deploy2runtime.cue +++ b/vela-templates/definitions/internal/workflowstep/deploy2runtime.cue @@ -8,6 +8,7 @@ import ( labels: { "ui-hidden": "true" "deprecated": "true" + "scope": "Application" } description: "Deploy application to runtime clusters" } diff --git a/vela-templates/definitions/internal/workflowstep/share-cloud-resource.cue b/vela-templates/definitions/internal/workflowstep/share-cloud-resource.cue index 1d6246381..ef542df4c 100644 --- a/vela-templates/definitions/internal/workflowstep/share-cloud-resource.cue +++ b/vela-templates/definitions/internal/workflowstep/share-cloud-resource.cue @@ -5,7 +5,9 @@ import ( "share-cloud-resource": { type: "workflow-step" annotations: {} - labels: {} + labels: { + "scope": "Application" + } description: "Sync secrets created by terraform component to runtime clusters so that runtime clusters can share the created cloud resource." } template: {