From 95d6b7456d7e38f93f5a5986bcb567e95bfc6045 Mon Sep 17 00:00:00 2001 From: KK <68334452+healthjyk@users.noreply.github.com> Date: Thu, 4 Jan 2024 11:37:26 +0800 Subject: [PATCH 1/5] feat: add sample nginx (#143) --- example/nginx/dev/kcl.mod | 11 +++++++++++ example/nginx/dev/main.k | 26 ++++++++++++++++++++++++++ example/nginx/dev/stack.yaml | 2 ++ example/nginx/dev/workspace.yaml | 10 ++++++++++ example/nginx/project.yaml | 4 ++++ example/sample-job/prod/kcl.mod | 1 - 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 example/nginx/dev/kcl.mod create mode 100644 example/nginx/dev/main.k create mode 100644 example/nginx/dev/stack.yaml create mode 100644 example/nginx/dev/workspace.yaml create mode 100644 example/nginx/project.yaml diff --git a/example/nginx/dev/kcl.mod b/example/nginx/dev/kcl.mod new file mode 100644 index 00000000..104c0b0f --- /dev/null +++ b/example/nginx/dev/kcl.mod @@ -0,0 +1,11 @@ +[package] +name = "public-service" +edition = "0.5.0" +version = "0.1.0" + +[dependencies] +# should update the tag! +catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.0" } + +[profile] +entries = ["main.k"] diff --git a/example/nginx/dev/main.k b/example/nginx/dev/main.k new file mode 100644 index 00000000..d7821d3d --- /dev/null +++ b/example/nginx/dev/main.k @@ -0,0 +1,26 @@ +import catalog.models.schema.v1 as ac +import catalog.models.schema.v1.workload as wl +import catalog.models.schema.v1.workload.container as c +import catalog.models.schema.v1.workload.network as n + +nginx: ac.AppConfiguration { + workload: wl.Service { + containers: { + wordpress: c.Container { + image = "nginx:1.25.2" + resources: { + "cpu": "500m" + "memory": "512Mi" + } + } + } + replicas: 1 + ports: [ + n.Port { + port: 80 + protocol: "TCP" + public: True + } + ] + } +} \ No newline at end of file diff --git a/example/nginx/dev/stack.yaml b/example/nginx/dev/stack.yaml new file mode 100644 index 00000000..1be7264f --- /dev/null +++ b/example/nginx/dev/stack.yaml @@ -0,0 +1,2 @@ +# The stack basic info +name: dev diff --git a/example/nginx/dev/workspace.yaml b/example/nginx/dev/workspace.yaml new file mode 100644 index 00000000..0d8bced7 --- /dev/null +++ b/example/nginx/dev/workspace.yaml @@ -0,0 +1,10 @@ +modules: + port: + default: + type: alicloud + annotations: + service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small + +runtimes: + kubernetes: + kubeconfig: /etc/kubeconfig.yaml # Replace with your own kubeconfig file path \ No newline at end of file diff --git a/example/nginx/project.yaml b/example/nginx/project.yaml new file mode 100644 index 00000000..d3398312 --- /dev/null +++ b/example/nginx/project.yaml @@ -0,0 +1,4 @@ +# The project basic info +name: nginx +generator: + type: AppConfiguration diff --git a/example/sample-job/prod/kcl.mod b/example/sample-job/prod/kcl.mod index f96a2d12..dbcf333b 100644 --- a/example/sample-job/prod/kcl.mod +++ b/example/sample-job/prod/kcl.mod @@ -7,4 +7,3 @@ version = "0.1.0" catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.1" } [profile] entries = ["main.k"] - From b9c01f017091caad7a9994b6d6f1345cbc2f7fc1 Mon Sep 17 00:00:00 2001 From: ffforest Date: Thu, 11 Jan 2024 12:32:39 +0800 Subject: [PATCH 2/5] chore: update simple-service example --- .gitignore | 5 ++- example/sample-job/{prod => dev}/kcl.mod | 0 example/sample-job/{prod => dev}/main.k | 0 example/sample-job/{prod => dev}/stack.yaml | 2 +- example/sample-job/project.yaml | 2 +- example/simple-service/{prod => dev}/kcl.mod | 0 example/simple-service/dev/main.k | 36 +++++++++++++++++++ .../simple-service/{prod => dev}/stack.yaml | 2 +- example/simple-service/prod/main.k | 21 ----------- 9 files changed, 43 insertions(+), 25 deletions(-) rename example/sample-job/{prod => dev}/kcl.mod (100%) rename example/sample-job/{prod => dev}/main.k (100%) rename example/sample-job/{prod => dev}/stack.yaml (69%) rename example/simple-service/{prod => dev}/kcl.mod (100%) create mode 100644 example/simple-service/dev/main.k rename example/simple-service/{prod => dev}/stack.yaml (69%) delete mode 100644 example/simple-service/prod/main.k diff --git a/.gitignore b/.gitignore index 5d173842..4d71ae20 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ kusion_state.json changed_list.txt -*.lock \ No newline at end of file +*#.lock + +# kusion state +kusion_state.yaml diff --git a/example/sample-job/prod/kcl.mod b/example/sample-job/dev/kcl.mod similarity index 100% rename from example/sample-job/prod/kcl.mod rename to example/sample-job/dev/kcl.mod diff --git a/example/sample-job/prod/main.k b/example/sample-job/dev/main.k similarity index 100% rename from example/sample-job/prod/main.k rename to example/sample-job/dev/main.k diff --git a/example/sample-job/prod/stack.yaml b/example/sample-job/dev/stack.yaml similarity index 69% rename from example/sample-job/prod/stack.yaml rename to example/sample-job/dev/stack.yaml index 0db97e71..2b0941bc 100644 --- a/example/sample-job/prod/stack.yaml +++ b/example/sample-job/dev/stack.yaml @@ -1,2 +1,2 @@ # The stack basic info -name: prod \ No newline at end of file +name: dev \ No newline at end of file diff --git a/example/sample-job/project.yaml b/example/sample-job/project.yaml index 82b282a5..ea2e3c4a 100644 --- a/example/sample-job/project.yaml +++ b/example/sample-job/project.yaml @@ -1,4 +1,4 @@ # The project basic info -name: sample-job +name: helloworld generator: type: AppConfiguration \ No newline at end of file diff --git a/example/simple-service/prod/kcl.mod b/example/simple-service/dev/kcl.mod similarity index 100% rename from example/simple-service/prod/kcl.mod rename to example/simple-service/dev/kcl.mod diff --git a/example/simple-service/dev/main.k b/example/simple-service/dev/main.k new file mode 100644 index 00000000..551d92bd --- /dev/null +++ b/example/simple-service/dev/main.k @@ -0,0 +1,36 @@ +import catalog.models.schema.v1 as ac +import catalog.models.schema.v1.workload as wl +import catalog.models.schema.v1.workload.container as c +import catalog.models.schema.v1.workload.container.probe as p +import catalog.models.schema.v1.workload.network as n + +helloworld: ac.AppConfiguration { + workload: wl.Service { + containers: { + "helloworld": c.Container { + image: "gcr.io/google-samples/gb-frontend:v4" + env: { + "env1": "VALUE" + "env2": "VALUE2" + } + resources: { + "cpu": "500m" + "memory": "512M" + } + # Configure an HTTP readiness probe + readinessProbe: p.Probe { + probeHandler: p.Http { + url: "http://localhost:80" + } + initialDelaySeconds: 10 + } + } + } + replicas: 2 + ports: [ + n.Port { + port: 80 + } + ] + } +} \ No newline at end of file diff --git a/example/simple-service/prod/stack.yaml b/example/simple-service/dev/stack.yaml similarity index 69% rename from example/simple-service/prod/stack.yaml rename to example/simple-service/dev/stack.yaml index 0db97e71..2b0941bc 100644 --- a/example/simple-service/prod/stack.yaml +++ b/example/simple-service/dev/stack.yaml @@ -1,2 +1,2 @@ # The stack basic info -name: prod \ No newline at end of file +name: dev \ No newline at end of file diff --git a/example/simple-service/prod/main.k b/example/simple-service/prod/main.k deleted file mode 100644 index 20a14bda..00000000 --- a/example/simple-service/prod/main.k +++ /dev/null @@ -1,21 +0,0 @@ -import catalog.models.schema.v1 as ac -import catalog.models.schema.v1.workload as wl -import catalog.models.schema.v1.workload.container as c - -# main.k declares desired configurations for prod stack. -simplesvc: ac.AppConfiguration { - workload: wl.Service { - containers: { - "nginx": c.Container { - # use nginx:1.25.2 as target image - image = "nginx:1.25.2" - # resource requirements for nginx container - resources: { - "cpu": "500m" - "memory": "512Mi" - } - } - } - replicas: 1 - } -} \ No newline at end of file From f721eeee38fb6644b6d04d08e6d41f711af11058 Mon Sep 17 00:00:00 2001 From: ffforest Date: Thu, 11 Jan 2024 12:33:12 +0800 Subject: [PATCH 3/5] chore: add prometheus and opsrule --- example/simple-service/dev/main.k | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/example/simple-service/dev/main.k b/example/simple-service/dev/main.k index 551d92bd..386aae8e 100644 --- a/example/simple-service/dev/main.k +++ b/example/simple-service/dev/main.k @@ -3,6 +3,8 @@ import catalog.models.schema.v1.workload as wl import catalog.models.schema.v1.workload.container as c import catalog.models.schema.v1.workload.container.probe as p import catalog.models.schema.v1.workload.network as n +import catalog.models.schema.v1.monitoring as m +import catalog.models.schema.v1.trait as t helloworld: ac.AppConfiguration { workload: wl.Service { @@ -27,10 +29,20 @@ helloworld: ac.AppConfiguration { } } replicas: 2 + # Comment the following block to un-expose service ports: [ n.Port { - port: 80 + port: 8080 + targetPort: 80 } ] } + # Comment the following block to remove opsRule + opsRule: t.OpsRule { + maxUnavailable: "30%" + } + # Comment the following block to disable monitoring + monitoring: m.Prometheus{ + path: "/metrics" + } } \ No newline at end of file From 94a548c5f1f46b4208f7c7510d2e4ef75a086fdf Mon Sep 17 00:00:00 2001 From: ffforest Date: Thu, 11 Jan 2024 12:38:23 +0800 Subject: [PATCH 4/5] chore: update simple-job example --- example/{sample-job => simple-job}/dev/kcl.mod | 2 +- example/{sample-job => simple-job}/dev/main.k | 2 +- example/{sample-job => simple-job}/dev/stack.yaml | 0 example/{sample-job => simple-job}/project.yaml | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename example/{sample-job => simple-job}/dev/kcl.mod (89%) rename example/{sample-job => simple-job}/dev/main.k (93%) rename example/{sample-job => simple-job}/dev/stack.yaml (100%) rename example/{sample-job => simple-job}/project.yaml (77%) diff --git a/example/sample-job/dev/kcl.mod b/example/simple-job/dev/kcl.mod similarity index 89% rename from example/sample-job/dev/kcl.mod rename to example/simple-job/dev/kcl.mod index dbcf333b..51991b4a 100644 --- a/example/sample-job/dev/kcl.mod +++ b/example/simple-job/dev/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "sample-job" +name = "simple-job" edition = "0.1.0" version = "0.1.0" diff --git a/example/sample-job/dev/main.k b/example/simple-job/dev/main.k similarity index 93% rename from example/sample-job/dev/main.k rename to example/simple-job/dev/main.k index 4abfd77d..ebdd1b59 100644 --- a/example/sample-job/dev/main.k +++ b/example/simple-job/dev/main.k @@ -2,7 +2,7 @@ import catalog.models.schema.v1 as ac import catalog.models.schema.v1.workload as wl import catalog.models.schema.v1.workload.container as c -samplejob: ac.AppConfiguration { +helloworld: ac.AppConfiguration { workload: wl.Job { containers: { "busybox": c.Container { diff --git a/example/sample-job/dev/stack.yaml b/example/simple-job/dev/stack.yaml similarity index 100% rename from example/sample-job/dev/stack.yaml rename to example/simple-job/dev/stack.yaml diff --git a/example/sample-job/project.yaml b/example/simple-job/project.yaml similarity index 77% rename from example/sample-job/project.yaml rename to example/simple-job/project.yaml index ea2e3c4a..6072de8c 100644 --- a/example/sample-job/project.yaml +++ b/example/simple-job/project.yaml @@ -1,4 +1,4 @@ # The project basic info -name: helloworld +name: simple-job generator: type: AppConfiguration \ No newline at end of file From 9bedb942614f4557f3b398f84adb7b81de467167 Mon Sep 17 00:00:00 2001 From: ffforest Date: Thu, 11 Jan 2024 15:34:58 +0800 Subject: [PATCH 5/5] chore: update catalog version to 0.1.2 --- example/simple-job/dev/kcl.mod | 2 +- example/simple-service/dev/kcl.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/simple-job/dev/kcl.mod b/example/simple-job/dev/kcl.mod index 51991b4a..807cb40e 100644 --- a/example/simple-job/dev/kcl.mod +++ b/example/simple-job/dev/kcl.mod @@ -4,6 +4,6 @@ edition = "0.1.0" version = "0.1.0" [dependencies] -catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.1" } +catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.2" } [profile] entries = ["main.k"] diff --git a/example/simple-service/dev/kcl.mod b/example/simple-service/dev/kcl.mod index cc4bc59b..5c942df1 100644 --- a/example/simple-service/dev/kcl.mod +++ b/example/simple-service/dev/kcl.mod @@ -4,7 +4,7 @@ edition = "0.1.0" version = "0.1.0" [dependencies] -catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.1" } +catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.2" } [profile] entries = ["main.k"]