From 81e4062ea5db46bd6a36c9683fbe3dccf0165b0d Mon Sep 17 00:00:00 2001 From: Peefy Date: Tue, 5 Nov 2024 11:48:34 +0800 Subject: [PATCH 1/2] docs: add inherit oam app example Signed-off-by: Peefy --- examples/kubevela/inherit-oam-app/kcl.mod | 7 ++++++ .../kubevela/inherit-oam-app/kcl.mod.lock | 10 +++++++++ examples/kubevela/inherit-oam-app/main.k | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 examples/kubevela/inherit-oam-app/kcl.mod create mode 100644 examples/kubevela/inherit-oam-app/kcl.mod.lock create mode 100644 examples/kubevela/inherit-oam-app/main.k diff --git a/examples/kubevela/inherit-oam-app/kcl.mod b/examples/kubevela/inherit-oam-app/kcl.mod new file mode 100644 index 00000000..d012b457 --- /dev/null +++ b/examples/kubevela/inherit-oam-app/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "inherit-oam-app" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +oam = "0.2.1" diff --git a/examples/kubevela/inherit-oam-app/kcl.mod.lock b/examples/kubevela/inherit-oam-app/kcl.mod.lock new file mode 100644 index 00000000..972bf458 --- /dev/null +++ b/examples/kubevela/inherit-oam-app/kcl.mod.lock @@ -0,0 +1,10 @@ +[dependencies] + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.31.2" + version = "1.31.2" + [dependencies.oam] + name = "oam" + full_name = "oam_0.2.1" + version = "0.2.1" + sum = "bz5HT/ggMm6heYVUOaZd5mOLIv/q2jicXupv0ChDlsE=" diff --git a/examples/kubevela/inherit-oam-app/main.k b/examples/kubevela/inherit-oam-app/main.k new file mode 100644 index 00000000..699c2c4d --- /dev/null +++ b/examples/kubevela/inherit-oam-app/main.k @@ -0,0 +1,22 @@ +import oam + +schema MyApplication(oam.Application): + metadata.annotations = { + "some-key" = "some-value" + } # Extend default values + + check: + "some-key" in metadata.annotations if metadata.annotations # Extend validation rules + +MyApplication { + metadata.name = "kcl-play-svc" + spec.components = [{ + name = metadata.name + type = "webservice" + properties = { + image = "kcllang/kcl" + ports = [{port = 80, expose = True}] + cmd = ["kcl", "play"] + } + }] +} From 87543404cf2b4f1a6addca3a8d77c782ce81fcd0 Mon Sep 17 00:00:00 2001 From: Peefy Date: Tue, 5 Nov 2024 12:01:47 +0800 Subject: [PATCH 2/2] docs: add template oam app example Signed-off-by: Peefy --- examples/kubevela/template-oam-app/kcl.mod | 7 +++++ .../kubevela/template-oam-app/kcl.mod.lock | 10 +++++++ examples/kubevela/template-oam-app/main.k | 27 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 examples/kubevela/template-oam-app/kcl.mod create mode 100644 examples/kubevela/template-oam-app/kcl.mod.lock create mode 100644 examples/kubevela/template-oam-app/main.k diff --git a/examples/kubevela/template-oam-app/kcl.mod b/examples/kubevela/template-oam-app/kcl.mod new file mode 100644 index 00000000..d012b457 --- /dev/null +++ b/examples/kubevela/template-oam-app/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "inherit-oam-app" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +oam = "0.2.1" diff --git a/examples/kubevela/template-oam-app/kcl.mod.lock b/examples/kubevela/template-oam-app/kcl.mod.lock new file mode 100644 index 00000000..972bf458 --- /dev/null +++ b/examples/kubevela/template-oam-app/kcl.mod.lock @@ -0,0 +1,10 @@ +[dependencies] + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.31.2" + version = "1.31.2" + [dependencies.oam] + name = "oam" + full_name = "oam_0.2.1" + version = "0.2.1" + sum = "bz5HT/ggMm6heYVUOaZd5mOLIv/q2jicXupv0ChDlsE=" diff --git a/examples/kubevela/template-oam-app/main.k b/examples/kubevela/template-oam-app/main.k new file mode 100644 index 00000000..4a545ec6 --- /dev/null +++ b/examples/kubevela/template-oam-app/main.k @@ -0,0 +1,27 @@ +import oam + +schema MyTemplate: + name: str + image: str + cmd?: [str] + port: int = 80 + +schema MyApplication[template: MyTemplate](oam.Application): + metadata = {name = "kcl-play-svc"} + spec = { + components = [{ + name = metadata.name + type = "webservice" + properties = { + image = "kcllang/kcl" + ports = [{port = 80, expose = True}] + cmd = ["kcl", "play"] + } + }] + } + +MyApplication({ + name = "kcl-play-svc" + image = "kcllang/kcl" + cmd: ["kcl", "play"] +}) {}