From 0fc315437aa763336fd5b45803ca15321325161a Mon Sep 17 00:00:00 2001 From: peefy Date: Thu, 19 Oct 2023 16:49:24 +0800 Subject: [PATCH] feat: add append-env mutation models --- examples/mutation/append-env/kcl.mod | 4 +++ examples/mutation/append-env/main.k | 10 ++++++ examples/mutation/append-env/suite/good.yaml | 37 ++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 examples/mutation/append-env/kcl.mod create mode 100644 examples/mutation/append-env/main.k create mode 100644 examples/mutation/append-env/suite/good.yaml diff --git a/examples/mutation/append-env/kcl.mod b/examples/mutation/append-env/kcl.mod new file mode 100644 index 0000000..26414e4 --- /dev/null +++ b/examples/mutation/append-env/kcl.mod @@ -0,0 +1,4 @@ +[package] +name = "append-env" +edition = "*" +version = "0.0.1" diff --git a/examples/mutation/append-env/main.k b/examples/mutation/append-env/main.k new file mode 100644 index 0000000..77e04d5 --- /dev/null +++ b/examples/mutation/append-env/main.k @@ -0,0 +1,10 @@ +items = [item | { + if item.kind == "Pod": + spec.containers: [{ + env += option("params").env + } for container in item.spec.containers] + elif item.kind == "Deployment": + spec.template.spec.containers: [{ + env += option("params").env + } for container in item.spec.template.spec.containers] +} for item in option("items") or []] diff --git a/examples/mutation/append-env/suite/good.yaml b/examples/mutation/append-env/suite/good.yaml new file mode 100644 index 0000000..03c306b --- /dev/null +++ b/examples/mutation/append-env/suite/good.yaml @@ -0,0 +1,37 @@ +apiVersion: krm.kcl.dev/v1alpha1 +kind: KCLRun +metadata: + name: append-env + annotations: + krm.kcl.dev/version: 0.0.1 + krm.kcl.dev/type: mutation + documentation: >- + Append env list for `Pod` and `Deployment` resources +spec: + params: + env: + name: test_name + value: test_value + source: ./examples/mutation/append-env/main.k +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80