Feat: support parallel apply in deploy2env (#2938)

Signed-off-by: Yin Da <yd219913@alibaba-inc.com>
This commit is contained in:
Somefive
2021-12-16 21:05:23 +08:00
committed by GitHub
parent 416fc45999
commit 5f2085b470
5 changed files with 68 additions and 25 deletions
@@ -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
}
+45 -14
View File
@@ -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)
}
}
+5 -4
View File
@@ -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?: {...}
...
+6 -1
View File
@@ -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")
}
@@ -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
}
}