diff --git a/charts/vela-core/templates/defwithtemplate/deploy2env.yaml b/charts/vela-core/templates/defwithtemplate/deploy2env.yaml index ac97f8fd4..d9dd2c691 100644 --- a/charts/vela-core/templates/defwithtemplate/deploy2env.yaml +++ b/charts/vela-core/templates/defwithtemplate/deploy2env.yaml @@ -16,9 +16,10 @@ spec: ) app: op.#ApplyEnvBindApp & { - env: parameter.env - policy: parameter.policy - app: context.name + env: parameter.env + policy: parameter.policy + parallel: parameter.parallel + app: context.name // context.namespace indicates the namespace of the app namespace: context.namespace } @@ -27,5 +28,7 @@ spec: policy: *"" | string // +usage=Declare the name of the env in policy env: string + // +usage=components are applied in parallel + parallel: *false | bool } diff --git a/pkg/stdlib/pkgs/multicluster.cue b/pkg/stdlib/pkgs/multicluster.cue index e7c542de4..431e3738d 100644 --- a/pkg/stdlib/pkgs/multicluster.cue +++ b/pkg/stdlib/pkgs/multicluster.cue @@ -141,6 +141,33 @@ } } +#ApplyComponentsToEnv: #Steps & { + inputs: { + decisions: [...#PlacementDecision] + components: [...#Component] + env: string + waitHealthy: bool + } @step(1) + + outputs: #Steps & { + for decision in inputs.decisions { + for key, comp in inputs.components { + "\(decision.cluster)-\(decision.namespace)-\(key)": #ApplyComponent & { + value: comp + if decision.cluster != _|_ { + cluster: decision.cluster + } + if decision.namespace != _|_ { + namespace: decision.namespace + } + waitHealthy: inputs.waitHealthy + env: inputs.env + } @step(1) + } + } + } @step(2) +} + #ApplyEnvBindApp: { #do: "steps" @@ -148,6 +175,7 @@ policy: string app: string namespace: string + parallel: bool env_: env policy_: policy @@ -158,21 +186,24 @@ } } @step(1) - apply: #Steps & { - for decision in prepare.outputs.decisions { - for key, comp in prepare.outputs.components { - "\(decision.cluster)-\(decision.namespace)-\(key)": #ApplyComponent & { - value: comp - if decision.cluster != _|_ { - cluster: decision.cluster - } - if decision.namespace != _|_ { - namespace: decision.namespace - } - env: env_ - } @step(2) - } + apply: #ApplyComponentsToEnv & { + inputs: { + decisions: prepare.outputs.decisions + components: prepare.outputs.components + env: env_ + waitHealthy: !parallel } + } @step(2) + + if parallel { + wait: #ApplyComponentsToEnv & { + inputs: { + decisions: prepare.outputs.decisions + components: prepare.outputs.components + env: env_ + waitHealthy: true + } + } @step(3) } } diff --git a/pkg/stdlib/pkgs/oam.cue b/pkg/stdlib/pkgs/oam.cue index 054aedee1..963f27215 100644 --- a/pkg/stdlib/pkgs/oam.cue +++ b/pkg/stdlib/pkgs/oam.cue @@ -1,8 +1,9 @@ #ApplyComponent: { - #provider: "oam" - #do: "component-apply" - cluster: *"" | string - env: *"" | string + #provider: "oam" + #do: "component-apply" + cluster: *"" | string + env: *"" | string + waitHealthy: *true | bool value: {...} patch?: {...} ... diff --git a/pkg/workflow/providers/oam/apply.go b/pkg/workflow/providers/oam/apply.go index bd8bb2a74..fc9f10904 100644 --- a/pkg/workflow/providers/oam/apply.go +++ b/pkg/workflow/providers/oam/apply.go @@ -106,7 +106,12 @@ func (p *provider) ApplyComponent(ctx wfContext.Context, v *value.Value, act wfT } } - if !healthy { + waitHealthy, err := v.GetBool("waitHealthy") + if err != nil { + waitHealthy = true + } + + if waitHealthy && !healthy { act.Wait("wait healthy") } diff --git a/vela-templates/definitions/internal/workflowstep/deploy2env.cue b/vela-templates/definitions/internal/workflowstep/deploy2env.cue index f71d18d33..4cd91dde2 100644 --- a/vela-templates/definitions/internal/workflowstep/deploy2env.cue +++ b/vela-templates/definitions/internal/workflowstep/deploy2env.cue @@ -10,9 +10,10 @@ import ( } template: { app: op.#ApplyEnvBindApp & { - env: parameter.env - policy: parameter.policy - app: context.name + env: parameter.env + policy: parameter.policy + parallel: parameter.parallel + app: context.name // context.namespace indicates the namespace of the app namespace: context.namespace } @@ -22,5 +23,7 @@ template: { policy: *"" | string // +usage=Declare the name of the env in policy env: string + // +usage=components are applied in parallel + parallel: *false | bool } }