From f0357fdc8f2332102665aed624ed2b26f90c9fdd Mon Sep 17 00:00:00 2001 From: JohnJan Date: Tue, 25 Jul 2023 10:31:18 +0800 Subject: [PATCH] Feat: apply-component supports namespace (#6228) * Feat: apply-component supports namespace Signed-off-by: wuzhongjian * Feat: apply-component supports namespace Signed-off-by: wuzhongjian --------- Signed-off-by: wuzhongjian --- .../templates/defwithtemplate/apply-component.yaml | 2 ++ .../core.oam.dev/v1beta1/application/generator.go | 9 +++++++-- pkg/workflow/template/static/builtin-apply-component.cue | 8 +++++--- .../docgen/def-doc/workflowstep/apply-component.eg.md | 3 ++- .../internal/workflowstep/apply-component.cue | 2 ++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/charts/vela-core/templates/defwithtemplate/apply-component.yaml b/charts/vela-core/templates/defwithtemplate/apply-component.yaml index 16b73261d..ae1045fb2 100644 --- a/charts/vela-core/templates/defwithtemplate/apply-component.yaml +++ b/charts/vela-core/templates/defwithtemplate/apply-component.yaml @@ -19,5 +19,7 @@ spec: component: string // +usage=Specify the cluster cluster: *"" | string + // +usage=Specify the namespace + namespace: *"" | string } diff --git a/pkg/controller/core.oam.dev/v1beta1/application/generator.go b/pkg/controller/core.oam.dev/v1beta1/application/generator.go index b57360796..2fe0eb527 100644 --- a/pkg/controller/core.oam.dev/v1beta1/application/generator.go +++ b/pkg/controller/core.oam.dev/v1beta1/application/generator.go @@ -252,6 +252,7 @@ func convertStepProperties(step *workflowv1alpha1.WorkflowStep, app *v1beta1.App o := struct { Component string `json:"component"` Cluster string `json:"cluster"` + Namespace string `json:"namespace"` }{} js, err := common.RawExtensionPointer{RawExtension: step.Properties}.MarshalJSON() if err != nil { @@ -260,6 +261,9 @@ func convertStepProperties(step *workflowv1alpha1.WorkflowStep, app *v1beta1.App if err := json.Unmarshal(js, &o); err != nil { return err } + if len(o.Namespace) == 0 { + o.Namespace = app.Namespace + } var componentNames []string for _, c := range app.Spec.Components { @@ -288,8 +292,9 @@ func convertStepProperties(step *workflowv1alpha1.WorkflowStep, app *v1beta1.App c.Outputs = nil c.DependsOn = nil stepProperties := map[string]interface{}{ - "value": c, - "cluster": o.Cluster, + "value": c, + "cluster": o.Cluster, + "namespace": o.Namespace, } step.Properties = util.Object2RawExtension(stepProperties) return nil diff --git a/pkg/workflow/template/static/builtin-apply-component.cue b/pkg/workflow/template/static/builtin-apply-component.cue index d00140170..e50900efb 100644 --- a/pkg/workflow/template/static/builtin-apply-component.cue +++ b/pkg/workflow/template/static/builtin-apply-component.cue @@ -5,8 +5,9 @@ import ( oam: op.oam // apply component and traits apply: oam.#ApplyComponent & { - value: parameter.value - cluster: parameter.cluster + value: parameter.value + cluster: parameter.cluster + namespace: parameter.namespace } if apply.output != _|_ { @@ -18,5 +19,6 @@ if apply.outputs != _|_ { } parameter: { value: {...} - cluster: *"" | string + cluster: *"" | string + namespace: *"" | string } diff --git a/references/docgen/def-doc/workflowstep/apply-component.eg.md b/references/docgen/def-doc/workflowstep/apply-component.eg.md index 45671a313..c2d2122b1 100644 --- a/references/docgen/def-doc/workflowstep/apply-component.eg.md +++ b/references/docgen/def-doc/workflowstep/apply-component.eg.md @@ -24,4 +24,5 @@ spec: properties: component: express-server # cluster: -``` \ No newline at end of file + # namespace: +``` diff --git a/vela-templates/definitions/internal/workflowstep/apply-component.cue b/vela-templates/definitions/internal/workflowstep/apply-component.cue index fb294e63b..fc6b67e6f 100644 --- a/vela-templates/definitions/internal/workflowstep/apply-component.cue +++ b/vela-templates/definitions/internal/workflowstep/apply-component.cue @@ -14,5 +14,7 @@ template: { component: string // +usage=Specify the cluster cluster: *"" | string + // +usage=Specify the namespace + namespace: *"" | string } }