Files
kubevela/pkg/stdlib/op.cue
Jian.Li 6cbdbe84b2 Refactor application code to make it run as Dag workflow (#2236)
* Refactor: remove use of AppConfig in AppRevision

* Refactor: remove insert secret and configmap

* Feat(workflow): upgrade

* Fix(conflict): workflow cherry

* Feat(workflow): support DAG mode

* Feat(workflow): prepare steps in step

* Feat(tools): random string

* Fix(rand): gosec weak random

* Fix(ci): test passing

* Feat(workflow): generate steps

* Fix: fix rebase from master

* Fix: fix workflow ut

* Feat(test): add test cases

* Fix: fix lint and rebase from master

* Refactor: application code

* Fix: fix ci lint

* Fix: make code reviewable

* Fix: workflow_test.go

* Feat: collect services

* Fix(ci): unit tests

* Feat: make one

* Test: application with input/output and workflow

* Fix: trace test

* Fix: update step index falied

* Feat: refactor op.#Load

* Fix: delete dead code

* Refactor: op.xxx

* Fix: patch component

* Test: add generator test

* Fix: add license

* Fix: pending e2e plugin test

* Fix: disable test/e2e-test

* Fix: patch by script

Co-authored-by: 天元 <jianbo.sjb@alibaba-inc.com>
Co-authored-by: FogDong <dongtianxin.tx@alibaba-inc.com>
2021-09-12 10:12:46 +08:00

162 lines
2.8 KiB
CUE

import (
"encoding/yaml"
"encoding/json"
"encoding/base64"
"strings"
)
#ConditionalWait: {
#do: "wait"
continue: bool
}
#Break: {
#do: "break"
message: string
}
#Apply: kube.#Apply
#ApplyApplication: #Steps & {
load: oam.#LoadComponets @step(1)
components: #Steps & {
for name, c in load.value {
"\(name)": oam.#Apply & {
value: c
}
}
} @step(2)
}
#ApplyComponent: oam.#ApplyComponent
#ApplyRemaining: #Steps & {
// exceptions specify the resources not to apply.
exceptions: [...string]
_exceptions: {for c in exceptions {"\(c)": true}}
load: ws.#Load @step(1)
components: #Steps & {
for name, c in load.value {
if _exceptions[name] == _|_ {
"\(name)": oam.#Apply & {
value: c
}
}
}
} @step(2)
}
#DingTalk: #Steps & {
message: dingDing.#DingMessage
dingUrl: string
do: http.#Do & {
method: "POST"
url: dingUrl
request: {
body: json.Marshal(message)
header: "Content-Type": "application/json"
}
}
}
#Slack: #Steps & {
message: slack.#SlackMessage
slackUrl: string
do: http.#Do & {
method: "POST"
url: slackUrl
request: {
body: json.Marshal(message)
header: "Content-Type": "application/json"
}
}
}
#ApplyEnvBindApp: #Steps & {
env: string
policy: string
app: string
namespace: string
_namespace: namespace
envBinding: kube.#Read & {
value: {
apiVersion: "core.oam.dev/v1alpha1"
kind: "EnvBinding"
metadata: {
name: policy
namespace: _namespace
}
}
} @step(1)
// wait until envBinding.value.status equal "finished"
wait: #ConditionalWait & {
continue: envBinding.value.status.phase == "finished"
} @step(2)
configMap: kube.#Read & {
value: {
apiVersion: "v1"
kind: "ConfigMap"
metadata: {
name: policy
namespace: _namespace
}
data?: _
}
} @step(3)
target: "\(policy)-\(env)-\(app)"
apply: kube.#Apply & {
value: {
yaml.Unmarshal(configMap.value.data[target])
}
} @step(4)
if apply.value.kind == "Application" {
"wait-app": #ConditionalWait & {
continue: apply.value.status.status == "running"
} @step(5)
}
if apply.value.kind == "ManifestWork" {
"wait-manifestWork": #ConditionalWait & {
continue: len(apply.value.status.resourceStatus) != 0
} @step(6)
for manifest in apply.value.status.resourceStatus.manifests {
for condition in manifest.conditions {
"wait-\(manifest.resourceMeta.kind)-\(condition.reason)": #ConditionalWait & {
continue: condition.status == "True"
} @step(7)
}
}
}
}
#HTTPGet: http.#Do & {method: "GET"}
#HTTPPost: http.#Do & {method: "POST"}
#HTTPPut: http.#Do & {method: "PUT"}
#HTTPDelete: http.#Do & {method: "DELETE"}
#Load: oam.#LoadComponets
#Read: kube.#Read
#Steps: {
#do: "steps"
...
}
#Task: task.#Task
NoExist: _|_
context: _