From cd7a0fb18e71c4466e5056d5d062099e8d19ec1a Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 11 Apr 2022 15:45:12 +0300 Subject: [PATCH 1/3] Rename cue module Signed-off-by: Stefan Prodan --- cue/cue.mod/module.cue | 2 +- cue/go.mod | 2 +- cue/main.cue | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cue/cue.mod/module.cue b/cue/cue.mod/module.cue index f2eda68..05f9e86 100644 --- a/cue/cue.mod/module.cue +++ b/cue/cue.mod/module.cue @@ -1 +1 @@ -module: "github.com/stefanprodan/podinfo/cuelang" +module: "github.com/stefanprodan/podinfo/cue" diff --git a/cue/go.mod b/cue/go.mod index 99642d0..d28088e 100644 --- a/cue/go.mod +++ b/cue/go.mod @@ -1,4 +1,4 @@ -module github.com/stefanprodan/podinfo/cuelang +module github.com/stefanprodan/podinfo/cue go 1.17 diff --git a/cue/main.cue b/cue/main.cue index a43e506..53fc9a4 100644 --- a/cue/main.cue +++ b/cue/main.cue @@ -1,7 +1,7 @@ package main import ( - podinfo "github.com/stefanprodan/podinfo/cuelang/podinfo" + podinfo "github.com/stefanprodan/podinfo/cue/podinfo" ) resources: (podinfo.#Application & { @@ -14,7 +14,7 @@ resources: (podinfo.#Application & { } image: { repository: "ghcr.io/stefanprodan/podinfo" - tag: "6.0.3" + tag: "6.1.1" } service: { grpcPort: 6666 From b26a34b5b6265274947e1beba11101fe5e0b9f07 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 11 Apr 2022 16:29:35 +0300 Subject: [PATCH 2/3] cue: Fix label selectors Signed-off-by: Stefan Prodan --- Makefile | 7 +++++- cue/main.cue | 10 +++++--- cue/podinfo/app.cue | 4 --- cue/podinfo/config.cue | 9 +++---- cue/podinfo/deployment.cue | 13 +++++++--- cue/podinfo/hpa.cue | 45 ++++++++++++++++++++-------------- cue/podinfo/service.cue | 2 +- cue/podinfo/servicemonitor.cue | 2 +- 8 files changed, 54 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 7d4cfc4..9827836 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ version-set: /usr/bin/sed -i '' "s/podinfo:$$current/podinfo:$$next/g" deploy/webapp/backend/deployment.yaml && \ /usr/bin/sed -i '' "s/podinfo:$$current/podinfo:$$next/g" deploy/bases/frontend/deployment.yaml && \ /usr/bin/sed -i '' "s/podinfo:$$current/podinfo:$$next/g" deploy/bases/backend/deployment.yaml && \ - /usr/bin/sed -i '' "s/tag:\(\s*\)$$current/tag:\1$$next/g" cue/main.cue && \ + /usr/bin/sed -i '' "s/$$current/$$next/g" cue/main.cue && \ echo "Version $$next set in code, deployment, chart and kustomize" release: @@ -89,3 +89,8 @@ release: swagger: go get github.com/swaggo/swag/cmd/swag cd pkg/api && $$(go env GOPATH)/bin/swag init -g server.go + +.PHONY: cue +cue: + @cd cue && cue fmt ./... && cue vet --all-errors --concrete ./... + @cd cue && cue gen \ No newline at end of file diff --git a/cue/main.cue b/cue/main.cue index 53fc9a4..6c9cbeb 100644 --- a/cue/main.cue +++ b/cue/main.cue @@ -9,15 +9,19 @@ resources: (podinfo.#Application & { meta: { name: "podinfo" annotations: { - "app.kubernetes.io/name": "podinfo" + "app.kubernetes.io/part-of": "podinfo" } } image: { repository: "ghcr.io/stefanprodan/podinfo" tag: "6.1.1" } - service: { - grpcPort: 6666 + resources: requests: cpu: "100m" + hpa: { + enabled: true + minReplicas: 2 + maxReplicas: 4 + cpu: 99 } } }).out diff --git a/cue/podinfo/app.cue b/cue/podinfo/app.cue index 7d3d482..bae7fe4 100644 --- a/cue/podinfo/app.cue +++ b/cue/podinfo/app.cue @@ -1,9 +1,5 @@ package podinfo -#selectorLabels: { - "app.kubernetes.io/name": "podinfo" -} - #Application: { input: #Config out: { diff --git a/cue/podinfo/config.cue b/cue/podinfo/config.cue index f55e2ca..38d137d 100644 --- a/cue/podinfo/config.cue +++ b/cue/podinfo/config.cue @@ -12,6 +12,9 @@ import ( tag: string pullPolicy: *"IfNotPresent" | string } + selectorLabels: { + "app.kubernetes.io/name": meta.name + } replicas: *1 | int service: #serviceConfig host: string @@ -43,12 +46,6 @@ import ( nodeSelector: {[ string]: string} affinity: corev1.#Affinity tolerations: [ ...corev1.#Toleration] - linkerd: { - enabled: *false | bool - } - redis: { - enabled: *false | bool - } tls: { enabled: *false | bool port: *9899 | int diff --git a/cue/podinfo/deployment.cue b/cue/podinfo/deployment.cue index b5e5e4a..ed72e78 100644 --- a/cue/podinfo/deployment.cue +++ b/cue/podinfo/deployment.cue @@ -19,13 +19,13 @@ import ( type: "RollingUpdate" rollingUpdate: maxUnavailable: 1 } - selector: matchLabels: #selectorLabels + selector: matchLabels: _config.selectorLabels template: { metadata: { - labels: #selectorLabels + labels: _config.selectorLabels annotations: { "prometheus.io/scrape": "true" - "prometheus.io/port": "\(_config.service.httpPort)" + "prometheus.io/port": "\(_config.service.metricsPort)" _config.podAnnotations } } @@ -41,6 +41,8 @@ import ( command: [ "./podinfo", "--port=\(_config.service.httpPort)", + "--port-metrics=\(_config.service.metricsPort)", + "--grpc-port=\(_config.service.grpcPort)", "--level=\(_config.logLevel)", "--random-delay=\(_config.faults.delay)", "--random-error=\(_config.faults.error)", @@ -56,6 +58,11 @@ import ( containerPort: _config.service.metricsPort protocol: "TCP" }, + { + name: "grpc" + containerPort: _config.service.grpcPort + protocol: "TCP" + }, ] livenessProbe: { exec: { diff --git a/cue/podinfo/hpa.cue b/cue/podinfo/hpa.cue index 7ea6592..6ca626a 100644 --- a/cue/podinfo/hpa.cue +++ b/cue/podinfo/hpa.cue @@ -6,8 +6,8 @@ import ( #hpaConfig: { enabled: *false | bool - cpu: int - memory: string + cpu: *0 | int + memory: *"" | string minReplicas: int maxReplicas: int } @@ -25,24 +25,31 @@ import ( } minReplicas: _config.hpa.minReplicas maxReplicas: _config.hpa.maxReplicas - metrics: [ { - type: "Resource" - resource: { - name: "cpu" - target: { - type: "Utilization" - averageUtilization: _config.hpa.cpu + metrics: [ + if _config.hpa.cpu > 0 { + { + type: "Resource" + resource: { + name: "cpu" + target: { + type: "Utilization" + averageUtilization: _config.hpa.cpu + } + } } - } - }, { - type: "Resource" - resource: { - name: "memory" - target: { - type: "AverageValue" - averageValue: _config.hpa.memory + }, + if _config.hpa.memory != "" { + { + type: "Resource" + resource: { + name: "memory" + target: { + type: "AverageValue" + averageValue: _config.hpa.memory + } + } } - } - }] + }, + ] } } diff --git a/cue/podinfo/service.cue b/cue/podinfo/service.cue index bd1a4ba..3bee3de 100644 --- a/cue/podinfo/service.cue +++ b/cue/podinfo/service.cue @@ -21,7 +21,7 @@ import ( metadata: _config.meta spec: corev1.#ServiceSpec & { type: "ClusterIP" - selector: #selectorLabels + selector: _config.selectorLabels ports: [{ name: "http" port: _config.service.externalPort diff --git a/cue/podinfo/servicemonitor.cue b/cue/podinfo/servicemonitor.cue index 9b91468..fe33b80 100644 --- a/cue/podinfo/servicemonitor.cue +++ b/cue/podinfo/servicemonitor.cue @@ -18,6 +18,6 @@ package podinfo interval: _config.serviceMonitor.interval }] namespaceSelector: matchNames: _config.meta.namespace - selector: matchLabels: #selectorLabels + selector: matchLabels: _config.selectorLabels } } From 8179263f5253491746f610b960422c9807c5d431 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 11 Apr 2022 16:30:15 +0300 Subject: [PATCH 3/3] Release 6.1.2 Signed-off-by: Stefan Prodan --- charts/podinfo/Chart.yaml | 4 ++-- charts/podinfo/values-prod.yaml | 2 +- charts/podinfo/values.yaml | 2 +- cue/main.cue | 2 +- deploy/bases/backend/deployment.yaml | 2 +- deploy/bases/frontend/deployment.yaml | 2 +- deploy/webapp/backend/deployment.yaml | 2 +- deploy/webapp/frontend/deployment.yaml | 2 +- kustomize/deployment.yaml | 2 +- pkg/version/version.go | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/charts/podinfo/Chart.yaml b/charts/podinfo/Chart.yaml index ecaeb03..f214934 100644 --- a/charts/podinfo/Chart.yaml +++ b/charts/podinfo/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 -version: 6.1.1 -appVersion: 6.1.1 +version: 6.1.2 +appVersion: 6.1.2 name: podinfo engine: gotpl description: Podinfo Helm chart for Kubernetes diff --git a/charts/podinfo/values-prod.yaml b/charts/podinfo/values-prod.yaml index cae8aec..d188d22 100644 --- a/charts/podinfo/values-prod.yaml +++ b/charts/podinfo/values-prod.yaml @@ -8,7 +8,7 @@ backends: [] image: repository: ghcr.io/stefanprodan/podinfo - tag: 6.1.1 + tag: 6.1.2 pullPolicy: IfNotPresent ui: diff --git a/charts/podinfo/values.yaml b/charts/podinfo/values.yaml index ffb6282..2a554a1 100644 --- a/charts/podinfo/values.yaml +++ b/charts/podinfo/values.yaml @@ -8,7 +8,7 @@ backends: [] image: repository: ghcr.io/stefanprodan/podinfo - tag: 6.1.1 + tag: 6.1.2 pullPolicy: IfNotPresent ui: diff --git a/cue/main.cue b/cue/main.cue index 6c9cbeb..88ab259 100644 --- a/cue/main.cue +++ b/cue/main.cue @@ -14,7 +14,7 @@ resources: (podinfo.#Application & { } image: { repository: "ghcr.io/stefanprodan/podinfo" - tag: "6.1.1" + tag: "6.1.2" } resources: requests: cpu: "100m" hpa: { diff --git a/deploy/bases/backend/deployment.yaml b/deploy/bases/backend/deployment.yaml index 0b82306..f1d05c4 100644 --- a/deploy/bases/backend/deployment.yaml +++ b/deploy/bases/backend/deployment.yaml @@ -23,7 +23,7 @@ spec: spec: containers: - name: backend - image: ghcr.io/stefanprodan/podinfo:6.1.1 + image: ghcr.io/stefanprodan/podinfo:6.1.2 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/deploy/bases/frontend/deployment.yaml b/deploy/bases/frontend/deployment.yaml index ac90cab..d46cb34 100644 --- a/deploy/bases/frontend/deployment.yaml +++ b/deploy/bases/frontend/deployment.yaml @@ -23,7 +23,7 @@ spec: spec: containers: - name: frontend - image: ghcr.io/stefanprodan/podinfo:6.1.1 + image: ghcr.io/stefanprodan/podinfo:6.1.2 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/deploy/webapp/backend/deployment.yaml b/deploy/webapp/backend/deployment.yaml index c8b674c..b9a1aab 100644 --- a/deploy/webapp/backend/deployment.yaml +++ b/deploy/webapp/backend/deployment.yaml @@ -25,7 +25,7 @@ spec: serviceAccountName: webapp containers: - name: backend - image: ghcr.io/stefanprodan/podinfo:6.1.1 + image: ghcr.io/stefanprodan/podinfo:6.1.2 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/deploy/webapp/frontend/deployment.yaml b/deploy/webapp/frontend/deployment.yaml index 9fe0c13..c7a7609 100644 --- a/deploy/webapp/frontend/deployment.yaml +++ b/deploy/webapp/frontend/deployment.yaml @@ -25,7 +25,7 @@ spec: serviceAccountName: webapp containers: - name: frontend - image: ghcr.io/stefanprodan/podinfo:6.1.1 + image: ghcr.io/stefanprodan/podinfo:6.1.2 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/kustomize/deployment.yaml b/kustomize/deployment.yaml index 9bf46ce..3e9fac4 100644 --- a/kustomize/deployment.yaml +++ b/kustomize/deployment.yaml @@ -23,7 +23,7 @@ spec: spec: containers: - name: podinfod - image: ghcr.io/stefanprodan/podinfo:6.1.1 + image: ghcr.io/stefanprodan/podinfo:6.1.2 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/pkg/version/version.go b/pkg/version/version.go index 32a4d80..282ce70 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,4 +1,4 @@ package version -var VERSION = "6.1.1" +var VERSION = "6.1.2" var REVISION = "unknown"