From e0adeab0e5e5147d4185228b91145890f1fbbb61 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Wed, 4 Dec 2024 14:11:06 +1100 Subject: [PATCH 1/6] add fake-services app --- applications/fake-services | 1 + 1 file changed, 1 insertion(+) create mode 160000 applications/fake-services diff --git a/applications/fake-services b/applications/fake-services new file mode 160000 index 00000000..c614d006 --- /dev/null +++ b/applications/fake-services @@ -0,0 +1 @@ +Subproject commit c614d00676040af088d0d7557561dd884df9403d From 0b410c5134279156995799a3df545ebfef6e7500 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Wed, 4 Dec 2024 14:19:56 +1100 Subject: [PATCH 2/6] remove submodule --- applications/fake-services | 1 - 1 file changed, 1 deletion(-) delete mode 160000 applications/fake-services diff --git a/applications/fake-services b/applications/fake-services deleted file mode 160000 index c614d006..00000000 --- a/applications/fake-services +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c614d00676040af088d0d7557561dd884df9403d From 8cced99c2364689495b1b872e2ac48af551bc0fb Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Wed, 4 Dec 2024 14:21:37 +1100 Subject: [PATCH 3/6] add fake-services app --- applications/fake-services/Makefile | 50 +++++++++++ applications/fake-services/README.md | 8 ++ applications/fake-services/app/.helmignore | 23 ++++++ applications/fake-services/app/Chart.lock | 9 ++ applications/fake-services/app/Chart.yaml | 29 +++++++ applications/fake-services/app/README.md | 10 +++ .../fake-services/app/templates/NOTES.txt | 0 .../fake-services/app/templates/_helpers.tpl | 71 ++++++++++++++++ .../app/templates/backend-deployment.yaml | 39 +++++++++ .../app/templates/backend-service.yaml | 14 ++++ .../app/templates/frontend-deployment.yaml | 39 +++++++++ .../app/templates/frontend-service.yaml | 15 ++++ .../fake-services/app/templates/ingress.yaml | 16 ++++ applications/fake-services/app/values.yaml | 45 ++++++++++ applications/fake-services/notes.md | 14 ++++ .../fake-services/replicated/backup.yaml | 5 ++ .../fake-services/replicated/k8s-app.yaml | 9 ++ .../fake-services/replicated/kots-app.yaml | 10 +++ .../fake-services/replicated/kots-chart.yaml | 38 +++++++++ .../fake-services/replicated/kots-config.yaml | 82 +++++++++++++++++++ .../fake-services/replicated/kots-ec.yaml | 13 +++ 21 files changed, 539 insertions(+) create mode 100644 applications/fake-services/Makefile create mode 100644 applications/fake-services/README.md create mode 100644 applications/fake-services/app/.helmignore create mode 100644 applications/fake-services/app/Chart.lock create mode 100644 applications/fake-services/app/Chart.yaml create mode 100644 applications/fake-services/app/README.md create mode 100644 applications/fake-services/app/templates/NOTES.txt create mode 100644 applications/fake-services/app/templates/_helpers.tpl create mode 100644 applications/fake-services/app/templates/backend-deployment.yaml create mode 100644 applications/fake-services/app/templates/backend-service.yaml create mode 100644 applications/fake-services/app/templates/frontend-deployment.yaml create mode 100644 applications/fake-services/app/templates/frontend-service.yaml create mode 100644 applications/fake-services/app/templates/ingress.yaml create mode 100644 applications/fake-services/app/values.yaml create mode 100644 applications/fake-services/notes.md create mode 100644 applications/fake-services/replicated/backup.yaml create mode 100644 applications/fake-services/replicated/k8s-app.yaml create mode 100644 applications/fake-services/replicated/kots-app.yaml create mode 100644 applications/fake-services/replicated/kots-chart.yaml create mode 100644 applications/fake-services/replicated/kots-config.yaml create mode 100644 applications/fake-services/replicated/kots-ec.yaml diff --git a/applications/fake-services/Makefile b/applications/fake-services/Makefile new file mode 100644 index 00000000..512c441f --- /dev/null +++ b/applications/fake-services/Makefile @@ -0,0 +1,50 @@ +REPLICATED_APP=gerard-helm-fake-service +REPLICATED_DIR=$(shell pwd)/replicated +CHART_DIR=$(shell pwd)/app +CHART_VERSION=0.5.0 +CHANNELS=Stable Unstable Beta + +clean-charts: + rm -rf $(REPLICATED_DIR)/*.tgz + +bump-chart-version: + yq -i '.version = "$(CHART_VERSION)"' $(CHART_DIR)/Chart.yaml + yq -i '.spec.chart.chartVersion = "$(CHART_VERSION)"' $(REPLICATED_DIR)/kots-chart.yaml + +helm-dep-up: + helm dep up $(CHART_DIR) + +helm-dep-list: + helm dep list $(CHART_DIR) + +helm-install-dry-run: + helm install $(REPLICATED_APP) --dry-run --debug $(CHART_DIR) + +helm-template: + helm template $(REPLICATED_APP) $(CHART_DIR) + +helm-install: + helm install $(REPLICATED_APP) --debug --wait $(CHART_DIR) + +helm-uninstall: + helm uninstall $(REPLICATED_APP) + +prepare-release: clean-charts helm-dep-up bump-chart-version + helm package --destination $(REPLICATED_DIR) --debug ./app + echo "Packaged Helm chart to $(REPLICATED_DIR)" + +replicated-lint: + replicated release lint --yaml-dir $(REPLICATED_DIR) + +replicated-release: prepare-release replicated-lint + replicated release create --yaml-dir $(REPLICATED_DIR) + +replicated-promote: + $(eval SEQUENCE := $(shell replicated release ls --output json | jq '.[0].sequence')) + @for channel in $(CHANNELS); do \ + echo "Promoting release sequence $(SEQUENCE) to $$channel channel..."; \ + replicated release promote $(SEQUENCE) $$channel; \ + done + +sync-platform-examples: + rsync -av --exclude '.git' --exclude '.gitignore' . /Users/gerard/dev/platform-examples/applications/fake-services/ \ No newline at end of file diff --git a/applications/fake-services/README.md b/applications/fake-services/README.md new file mode 100644 index 00000000..c4e82215 --- /dev/null +++ b/applications/fake-services/README.md @@ -0,0 +1,8 @@ +# helm-fake-service + +This repository contains an example Helm chart that distributed with Replicated Embedded Cluster. + +## Components + +- A Helm chart using [fake-service](https://github.com/nicholasjackson/fake-service) +- Replicated [manifests](https://docs.replicated.com/reference/custom-resource-about) to deploy the chart with Replicated diff --git a/applications/fake-services/app/.helmignore b/applications/fake-services/app/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/applications/fake-services/app/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/applications/fake-services/app/Chart.lock b/applications/fake-services/app/Chart.lock new file mode 100644 index 00000000..f50184f6 --- /dev/null +++ b/applications/fake-services/app/Chart.lock @@ -0,0 +1,9 @@ +dependencies: +- name: ingress-nginx + repository: https://kubernetes.github.io/ingress-nginx + version: 4.11.3 +- name: replicated + repository: oci://registry.replicated.com/library + version: 1.0.0-beta.31 +digest: sha256:c349fc2fe99276ed430877ef2a0cf0e05150cd27f6e4eae2d7bfe47733f64846 +generated: "2024-11-27T11:01:55.491515+11:00" diff --git a/applications/fake-services/app/Chart.yaml b/applications/fake-services/app/Chart.yaml new file mode 100644 index 00000000..f236dde6 --- /dev/null +++ b/applications/fake-services/app/Chart.yaml @@ -0,0 +1,29 @@ +apiVersion: v2 +name: fake-service +description: A Helm chart for Kubernetes +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.5.0 +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" +dependencies: + - name: ingress-nginx + version: 4.11.3 + repository: https://kubernetes.github.io/ingress-nginx + condition: ingress-nginx.enabled + - name: replicated + repository: oci://registry.replicated.com/library + version: 1.0.0-beta.31 diff --git a/applications/fake-services/app/README.md b/applications/fake-services/app/README.md new file mode 100644 index 00000000..33b868b0 --- /dev/null +++ b/applications/fake-services/app/README.md @@ -0,0 +1,10 @@ +# fake-service + +This Helm chart will install: + +- A fake-service frontend +- A fake-service backend + +The `frontend` service will be exposed with an `Ingress`. + +We will not install `ingress-nginx` as part of the Helm chart but install `ingress-nginx` controller separately. E.g. with `k0s` Helm chart (extension)[https://docs.k0sproject.io/head/helm-charts/?h=helm+extension#example] diff --git a/applications/fake-services/app/templates/NOTES.txt b/applications/fake-services/app/templates/NOTES.txt new file mode 100644 index 00000000..e69de29b diff --git a/applications/fake-services/app/templates/_helpers.tpl b/applications/fake-services/app/templates/_helpers.tpl new file mode 100644 index 00000000..3158dff0 --- /dev/null +++ b/applications/fake-services/app/templates/_helpers.tpl @@ -0,0 +1,71 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "fake-service.name" -}} +{{- default .Chart.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "fake-service.fullname" -}} +{{- $name := "fake-service-app" }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "fake-service.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "fake-service.labels" -}} +helm.sh/chart: {{ include "fake-service.chart" . }} +{{ include "fake-service.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "fake-service.selectorLabels" -}} +app.kubernetes.io/name: {{ include "fake-service.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Frontend labels selector +*/}} +{{- define "fake-service.frontend.selectorLabels" -}} +app.kubernetes.io/name: {{ include "fake-service.name" . }}-frontend +{{- end }} + +{{/* +Backend labels selector +*/}} +{{- define "fake-service.backend.selectorLabels" -}} +app.kubernetes.io/name: {{ include "fake-service.name" . }}-backend +{{- end }} + +{{/* +Frontend service name +*/}} +{{- define "fake-service.frontend.name" -}} +frontend-service +{{- end }} + +{{/* +Backend service name +*/}} +{{- define "fake-service.backend.name" -}} +backend-service +{{- end }} \ No newline at end of file diff --git a/applications/fake-services/app/templates/backend-deployment.yaml b/applications/fake-services/app/templates/backend-deployment.yaml new file mode 100644 index 00000000..936da4d6 --- /dev/null +++ b/applications/fake-services/app/templates/backend-deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend + labels: + {{- include "fake-service.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "fake-service.backend.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "fake-service.backend.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.image.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}" + ports: + - name: backend + containerPort: {{ .Values.backend.port }} + protocol: TCP + env: + - name: NAME + value: {{ .Values.backend.name }} + - name: MESSAGE + value: "{{ .Values.backend.message }}" + - name: LISTEN_ADDR + value: "0.0.0.0:{{ .Values.backend.port }}" + - name: SERVER_TYPE + value: "{{ .Values.backend.serverType }}" + - name: LOG_LEVEL + value: "{{ .Values.backend.logLevel }}" + - name: ERROR_RATE + value: "{{ .Values.backend.errorRate }}" diff --git a/applications/fake-services/app/templates/backend-service.yaml b/applications/fake-services/app/templates/backend-service.yaml new file mode 100644 index 00000000..6a71bba2 --- /dev/null +++ b/applications/fake-services/app/templates/backend-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "fake-service.backend.name" . }} + labels: {{- include "fake-service.labels" . | nindent 4 }} +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: backend + protocol: TCP + name: backend + selector: + {{- include "fake-service.backend.selectorLabels" . | nindent 4 }} diff --git a/applications/fake-services/app/templates/frontend-deployment.yaml b/applications/fake-services/app/templates/frontend-deployment.yaml new file mode 100644 index 00000000..cb54a4b5 --- /dev/null +++ b/applications/fake-services/app/templates/frontend-deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend + labels: + {{- include "fake-service.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "fake-service.frontend.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "fake-service.frontend.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.image.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}" + ports: + - name: frontend + containerPort: {{ .Values.frontend.port }} + protocol: TCP + env: + - name: NAME + value: {{ .Values.frontend.name }} + - name: MESSAGE + value: "{{ .Values.frontend.message }}" + - name: LISTEN_ADDR + value: "0.0.0.0:{{ .Values.frontend.port }}" + - name: SERVER_TYPE + value: "{{ .Values.frontend.serverType }}" + - name: LOG_LEVEL + value: "{{ .Values.frontend.logLevel }}" + - name: UPSTREAM_URIS + value: "http://{{ include "fake-service.backend.name" . }}.{{ .Release.Namespace }}" \ No newline at end of file diff --git a/applications/fake-services/app/templates/frontend-service.yaml b/applications/fake-services/app/templates/frontend-service.yaml new file mode 100644 index 00000000..09a48dfd --- /dev/null +++ b/applications/fake-services/app/templates/frontend-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "fake-service.frontend.name" . }} + labels: {{- include "fake-service.labels" . | nindent 4 }} +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: frontend + protocol: TCP + name: frontend + selector: + {{- include "fake-service.frontend.selectorLabels" . | nindent 4 }} + diff --git a/applications/fake-services/app/templates/ingress.yaml b/applications/fake-services/app/templates/ingress.yaml new file mode 100644 index 00000000..57b97646 --- /dev/null +++ b/applications/fake-services/app/templates/ingress.yaml @@ -0,0 +1,16 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "fake-service.name" . }}-ingress +spec: + ingressClassName: nginx + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ include "fake-service.frontend.name" . }} + port: + number: 80 diff --git a/applications/fake-services/app/values.yaml b/applications/fake-services/app/values.yaml new file mode 100644 index 00000000..8d4b595d --- /dev/null +++ b/applications/fake-services/app/values.yaml @@ -0,0 +1,45 @@ +image: + registry: docker.io + repository: nicholasjackson/fake-service + tag: v0.26.2 + pullPolicy: IfNotPresent + imagePullSecrets: [] + +frontend: + name: "frontend" + message: "Hello from frontend!" + serverType: "http" + logLevel: "debug" + port: 9090 + +backend: + name: "backend" + message: "Hello from backend!" + serverType: "http" + logLevel: "debug" + port: 9091 + errorRate: 0 + origin: "*" + +ingress-nginx: + enabled: true + imagePullSecrets: [] + controller: + image: + registry: registry.k8s.io + image: ingress-nginx/controller + tag: v1.11.3 + digest: "" + admissionWebhooks: + patch: + image: + registry: registry.k8s.io + image: ingress-nginx/kube-webhook-certgen + tag: v1.4.4 + digest: "" + service: + type: NodePort + nodePorts: + http: 30080 + ingressClassResource: + default: true diff --git a/applications/fake-services/notes.md b/applications/fake-services/notes.md new file mode 100644 index 00000000..fe5519d3 --- /dev/null +++ b/applications/fake-services/notes.md @@ -0,0 +1,14 @@ +# Development notes + +## Develop the Helm chart + +```bash +helm create app +``` + +- Test with + +```bash +helm template foo ./app +helm install foo ./app --dry-run +``` diff --git a/applications/fake-services/replicated/backup.yaml b/applications/fake-services/replicated/backup.yaml new file mode 100644 index 00000000..b339d22b --- /dev/null +++ b/applications/fake-services/replicated/backup.yaml @@ -0,0 +1,5 @@ +apiVersion: velero.io/v1 +kind: Backup +metadata: + name: backup + spec: {} diff --git a/applications/fake-services/replicated/k8s-app.yaml b/applications/fake-services/replicated/k8s-app.yaml new file mode 100644 index 00000000..df5f0678 --- /dev/null +++ b/applications/fake-services/replicated/k8s-app.yaml @@ -0,0 +1,9 @@ +apiVersion: app.k8s.io/v1beta1 +kind: Application +metadata: + name: fake-service +spec: + descriptor: + links: + - description: Open App + url: https://repl{{ ConfigOption "hostname" }}:30080 diff --git a/applications/fake-services/replicated/kots-app.yaml b/applications/fake-services/replicated/kots-app.yaml new file mode 100644 index 00000000..69910926 --- /dev/null +++ b/applications/fake-services/replicated/kots-app.yaml @@ -0,0 +1,10 @@ +apiVersion: kots.io/v1beta1 +kind: Application +metadata: + name: fake-service +spec: + title: Fake Services + icon: https://www.shareicon.net/data/256x256/2016/05/16/766096_zoo_512x512.png + statusInformers: + - deployment/frontend + - deployment/backend diff --git a/applications/fake-services/replicated/kots-chart.yaml b/applications/fake-services/replicated/kots-chart.yaml new file mode 100644 index 00000000..2386181b --- /dev/null +++ b/applications/fake-services/replicated/kots-chart.yaml @@ -0,0 +1,38 @@ +apiVersion: kots.io/v1beta2 +kind: HelmChart +metadata: + name: fake-service +spec: + chart: + name: fake-service + chartVersion: 0.5.0 + helmUpgradeFlags: + - --debug + values: + image: + registry: '{{repl HasLocalRegistry | ternary LocalRegistryHost "proxy.replicated.com" }}' + repository: '{{repl HasLocalRegistry | ternary LocalRegistryNamespace "proxy/gerard-helm-fake-service/429114214526.dkr.ecr.ap-southeast-2.amazonaws.com/gerard" }}/fake-service' + imagePullSecrets: + - name: "{{repl ImagePullSecretName }}" + frontend: + name: repl{{ ConfigOption "frontend_name" }} + message: repl{{ ConfigOption "frontend_message" }} + logLevel: repl{{ ConfigOption "frontend_log_level" }} + backend: + name: repl{{ ConfigOption "backend_name" }} + message: repl{{ ConfigOption "backend_message" }} + logLevel: repl{{ ConfigOption "backend_log_level" }} + errorRate: repl{{ ConfigOption "backend_error_rate" }} + origin: repl{{ ConfigOption "backend_origin" }} + ingress-nginx: + imagePullSecrets: + - name: "{{repl ImagePullSecretName }}" + controller: + image: + registry: '{{repl HasLocalRegistry | ternary LocalRegistryHost "proxy.replicated.com" }}' + image: '{{repl HasLocalRegistry | ternary LocalRegistryNamespace "proxy/gerard-helm-fake-service/429114214526.dkr.ecr.ap-southeast-2.amazonaws.com/gerard" }}/controller' + admissionWebhooks: + patch: + image: + registry: '{{repl HasLocalRegistry | ternary LocalRegistryHost "proxy.replicated.com" }}' + image: '{{repl HasLocalRegistry | ternary LocalRegistryNamespace "proxy/gerard-helm-fake-service/429114214526.dkr.ecr.ap-southeast-2.amazonaws.com/gerard" }}/kube-webhook-certgen' diff --git a/applications/fake-services/replicated/kots-config.yaml b/applications/fake-services/replicated/kots-config.yaml new file mode 100644 index 00000000..d09e5d75 --- /dev/null +++ b/applications/fake-services/replicated/kots-config.yaml @@ -0,0 +1,82 @@ +apiVersion: kots.io/v1beta1 +kind: Config +metadata: + name: fake-service +spec: + groups: + - name: Global settings + title: Global settings + description: Global settings + items: + - name: hostname + title: Hostname + type: text + required: false + - name: Frontend settings + title: Frontend settings + description: Frontend settings + items: + - name: frontend_name + title: Service Name + type: text + required: true + - name: frontend_message + title: Message + type: text + required: true + default: Hello from frontend! + - name: frontend_log_level + title: Log level + type: radio + default: debug + items: + - name: debug + title: Debug + - name: info + title: Info + - name: warn + title: Warn + - name: error + title: Error + - name: trace + title: Trace + - name: Backend settings + title: Backend settings + description: Backend settings + items: + - name: backend_name + title: Service Name + type: text + required: true + - name: backend_message + title: Message + type: text + required: true + default: Hello from backend! + - name: backend_log_level + title: Log level + type: radio + default: debug + items: + - name: debug + title: Debug + - name: info + title: Info + - name: warn + title: Warn + - name: error + title: Error + - name: trace + title: Trace + - name: backend_error_rate + title: Error rate + type: text + default: "0" + validation: + regex: + pattern: "^(0|1(\\.0)?|0\\.\\d{1,3})$" + message: "Decimal percentage of request where handler will report an error. e.g. 0.1 = 10% of all requests will result in an error" + - name: backend_origin + title: Allowed origins + type: text + default: "\\*" diff --git a/applications/fake-services/replicated/kots-ec.yaml b/applications/fake-services/replicated/kots-ec.yaml new file mode 100644 index 00000000..2b50dd4d --- /dev/null +++ b/applications/fake-services/replicated/kots-ec.yaml @@ -0,0 +1,13 @@ +apiVersion: embeddedcluster.replicated.com/v1beta1 +kind: Config +spec: + version: 1.19.0+k8s-1.30 + roles: + controller: + name: management + labels: + management: "true" + custom: + - name: app + labels: + app: "true" From f074130f48cad30ccc0c0a532d51c14091836637 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Thu, 5 Dec 2024 12:15:53 +1100 Subject: [PATCH 4/6] wip --- applications/fake-services/Makefile | 2 +- applications/fake-services/app/Chart.yaml | 2 +- .../fake-services/app/templates/_helpers.tpl | 29 +++++++++++++++- .../app/templates/backend-deployment.yaml | 5 +-- .../app/templates/custom-metrics-job.yaml | 33 +++++++++++++++++++ .../app/templates/frontend-deployment.yaml | 5 +-- .../app/templates/replicated-pull-secret.yaml | 9 +++++ .../fake-services/replicated/kots-app.yaml | 2 ++ .../fake-services/replicated/kots-chart.yaml | 2 +- .../fake-services/replicated/kots-config.yaml | 4 +++ 10 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 applications/fake-services/app/templates/custom-metrics-job.yaml create mode 100644 applications/fake-services/app/templates/replicated-pull-secret.yaml diff --git a/applications/fake-services/Makefile b/applications/fake-services/Makefile index 512c441f..0b97ad59 100644 --- a/applications/fake-services/Makefile +++ b/applications/fake-services/Makefile @@ -1,7 +1,7 @@ REPLICATED_APP=gerard-helm-fake-service REPLICATED_DIR=$(shell pwd)/replicated CHART_DIR=$(shell pwd)/app -CHART_VERSION=0.5.0 +CHART_VERSION=0.7.0 CHANNELS=Stable Unstable Beta clean-charts: diff --git a/applications/fake-services/app/Chart.yaml b/applications/fake-services/app/Chart.yaml index f236dde6..9db5acc0 100644 --- a/applications/fake-services/app/Chart.yaml +++ b/applications/fake-services/app/Chart.yaml @@ -13,7 +13,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.5.0 +version: 0.7.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/applications/fake-services/app/templates/_helpers.tpl b/applications/fake-services/app/templates/_helpers.tpl index 3158dff0..624d043c 100644 --- a/applications/fake-services/app/templates/_helpers.tpl +++ b/applications/fake-services/app/templates/_helpers.tpl @@ -68,4 +68,31 @@ Backend service name */}} {{- define "fake-service.backend.name" -}} backend-service -{{- end }} \ No newline at end of file +{{- end }} + + +{{/* +Image Pull Secrets +*/}} +{{- define "helpers.imagePullSecrets" -}} +{{- $pullSecrets := list -}} + +{{/* Add existing imagePullSecrets if defined */}} +{{- if .Values.image.imagePullSecrets -}} +{{- $pullSecrets = concat $pullSecrets .Values.image.imagePullSecrets -}} +{{- end -}} + +{{/* Add replicated pull secret if global dockerconfigjson is defined for Helm CLI install*/}} +{{- if .Values.global.replicated.dockerconfigjson -}} +{{- $replicatedSecret := dict "name" "replicated-pull-secret" -}} +{{- $pullSecrets = append $pullSecrets $replicatedSecret -}} +{{- end -}} + +{{/* Output the imagePullSecrets block only if we have any secrets */}} +{{- if $pullSecrets -}} +imagePullSecrets: +{{- range $pullSecrets }} + - name: {{ .name }} +{{- end -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/applications/fake-services/app/templates/backend-deployment.yaml b/applications/fake-services/app/templates/backend-deployment.yaml index 936da4d6..cccbf10d 100644 --- a/applications/fake-services/app/templates/backend-deployment.yaml +++ b/applications/fake-services/app/templates/backend-deployment.yaml @@ -13,10 +13,7 @@ spec: labels: {{- include "fake-service.backend.selectorLabels" . | nindent 8 }} spec: - {{- with .Values.image.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- include "helpers.imagePullSecrets" . | nindent 6 }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}" diff --git a/applications/fake-services/app/templates/custom-metrics-job.yaml b/applications/fake-services/app/templates/custom-metrics-job.yaml new file mode 100644 index 00000000..16b4cfa6 --- /dev/null +++ b/applications/fake-services/app/templates/custom-metrics-job.yaml @@ -0,0 +1,33 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: lucky-number-sender +spec: + schedule: "* * * * *" # Run every minute + successfulJobsHistoryLimit: 3 + failedJobsHistoryLimit: 1 + concurrencyPolicy: Forbid + jobTemplate: + spec: + template: + spec: + containers: + - name: lucky-sender + image: curlimages/curl:latest + command: ["/bin/sh"] + args: + - -c + - | + # Get seconds since epoch and use it as random seed + NUM=$(date +%s) + LUCKY_NUMBER=$(expr $NUM % 35 + 1) + + # Send the metric + curl -v -X POST 'http://replicated:3000/api/v1/app/custom-metrics' \ + -H 'Content-Type: application/json' \ + -d "{ + \"data\": { + \"lucky_number\": $LUCKY_NUMBER + } + }" + restartPolicy: OnFailure \ No newline at end of file diff --git a/applications/fake-services/app/templates/frontend-deployment.yaml b/applications/fake-services/app/templates/frontend-deployment.yaml index cb54a4b5..26109390 100644 --- a/applications/fake-services/app/templates/frontend-deployment.yaml +++ b/applications/fake-services/app/templates/frontend-deployment.yaml @@ -13,10 +13,7 @@ spec: labels: {{- include "fake-service.frontend.selectorLabels" . | nindent 8 }} spec: - {{- with .Values.image.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- include "helpers.imagePullSecrets" . | nindent 6 }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}" diff --git a/applications/fake-services/app/templates/replicated-pull-secret.yaml b/applications/fake-services/app/templates/replicated-pull-secret.yaml new file mode 100644 index 00000000..d68f993f --- /dev/null +++ b/applications/fake-services/app/templates/replicated-pull-secret.yaml @@ -0,0 +1,9 @@ +{{ if .Values.global.replicated.dockerconfigjson }} +apiVersion: v1 +kind: Secret +metadata: + name: replicated-pull-secret +type: kubernetes.io/dockerconfigjson +data: + .dockerconfigjson: {{ .Values.global.replicated.dockerconfigjson }} +{{ end }} \ No newline at end of file diff --git a/applications/fake-services/replicated/kots-app.yaml b/applications/fake-services/replicated/kots-app.yaml index 69910926..6622b940 100644 --- a/applications/fake-services/replicated/kots-app.yaml +++ b/applications/fake-services/replicated/kots-app.yaml @@ -8,3 +8,5 @@ spec: statusInformers: - deployment/frontend - deployment/backend + additionalImages: + - curlimages/curl:latest \ No newline at end of file diff --git a/applications/fake-services/replicated/kots-chart.yaml b/applications/fake-services/replicated/kots-chart.yaml index 2386181b..494acc7e 100644 --- a/applications/fake-services/replicated/kots-chart.yaml +++ b/applications/fake-services/replicated/kots-chart.yaml @@ -5,7 +5,7 @@ metadata: spec: chart: name: fake-service - chartVersion: 0.5.0 + chartVersion: 0.7.0 helmUpgradeFlags: - --debug values: diff --git a/applications/fake-services/replicated/kots-config.yaml b/applications/fake-services/replicated/kots-config.yaml index d09e5d75..da0784fb 100644 --- a/applications/fake-services/replicated/kots-config.yaml +++ b/applications/fake-services/replicated/kots-config.yaml @@ -12,6 +12,10 @@ spec: title: Hostname type: text required: false + - name: password + title: Password + type: password + required: false - name: Frontend settings title: Frontend settings description: Frontend settings From 23d7bb10fca79241b8beed80a7bfe88258c611b9 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Fri, 6 Dec 2024 16:27:17 +1100 Subject: [PATCH 5/6] wip --- .../.github/workflows/replicated-release.yaml | 169 ++++++++++++++++++ applications/fake-services/Makefile | 2 +- applications/fake-services/app/Chart.yaml | 2 +- .../fake-services/app/templates/_helpers.tpl | 6 +- .../app/templates/replicated-pull-secret.yaml | 8 +- .../fake-services/replicated/kots-chart.yaml | 2 +- .../replicated/kots-sample-config-values.yaml | 12 ++ 7 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 applications/fake-services/.github/workflows/replicated-release.yaml create mode 100644 applications/fake-services/replicated/kots-sample-config-values.yaml diff --git a/applications/fake-services/.github/workflows/replicated-release.yaml b/applications/fake-services/.github/workflows/replicated-release.yaml new file mode 100644 index 00000000..5c5be897 --- /dev/null +++ b/applications/fake-services/.github/workflows/replicated-release.yaml @@ -0,0 +1,169 @@ +name: replicated-release + +on: + push: + tags: + - 'v*.*.*' + workflow_dispatch: + inputs: + tag: + description: 'Version tag (e.g. v1.0.0)' + required: true + type: string + +jobs: + push-to-replicated: + runs-on: ubuntu-22.04 + outputs: + channel-slug: ${{ steps.create-release.outputs.channel-slug }} + release-sequence: ${{ steps.create-release.outputs.release-sequence }} + app-version: ${{ steps.set-release-version.outputs.VERSION }} + steps: + - uses: actions/checkout@v3 + + - name: Set release version + id: set-release-version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + else + echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + fi + + - name: Package Helm chart + id: package-helm-chart + run: | + helm package ./app --debug -u -d ./replicated \ + --version ${{ env.VERSION }} \ + --app-version ${{ env.VERSION }} + + - name: Install yq + run: | + wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq &&\ + chmod +x /usr/local/bin/yq + + - name: Update HelmChart kind + run: | + yq -i '.spec.chart.chartVersion = "${{ env.VERSION }}"' replicated/kots-chart.yaml + + - name: Define Channel name + run: echo "CHANNEL_NAME=${{ env.VERSION }}-${GITHUB_RUN_ID}${GITHUB_RUN_ATTEMPT}" >> $GITHUB_ENV + + - name: Create Replicated release + id: create-release + uses: replicatedhq/compatibility-actions/create-release@v1 + with: + app-slug: ${{ secrets.REPLICATED_APP }} + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + yaml-dir: ./replicated + promote-channel: ${{ env.CHANNEL_NAME }} + version: ${{ env.VERSION }} + + compatibility-matrix: + needs: push-to-replicated + strategy: + fail-fast: false + matrix: + cluster: [{distribution: kind, version: v1.31.2}] + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Set release version + id: set-release-version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + else + echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + fi + - name: Create Customer + id: create-customer + uses: replicatedhq/replicated-actions/create-customer@v1 + with: + app-slug: ${{ secrets.REPLICATED_APP }} + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + customer-name: ${{ env.VERSION }}-${{ matrix.cluster.distribution }}-${{ matrix.cluster.version }} + channel-slug: ${{ needs.push-to-replicated.outputs.channel-slug }} + customer-email: ${{ env.VERSION }}@example.com + expires-in: 14 + license-type: dev + + - name: Create Cluster + id: create-cluster + uses: replicatedhq/replicated-actions/create-cluster@v1 + with: + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + kubernetes-distribution: ${{ matrix.cluster.distribution }} + kubernetes-version: ${{ matrix.cluster.version }} + cluster-name: ${{ env.VERSION }}-${{ matrix.cluster.distribution }}-${{ matrix.cluster.version }} + timeout-minutes: 5 + ttl: 10m + + - name: Deploy the app + uses: replicatedhq/replicated-actions/kots-install@v1 + with: + kubeconfig: ${{ steps.create-cluster.outputs.cluster-kubeconfig }} + app-slug: ${{ secrets.REPLICATED_APP }}/${{ needs.push-to-replicated.outputs.channel-slug }} + license-file: ${{ steps.create-customer.outputs.license-file }} + app-version-label: ${{ env.VERSION }} + config-values: ./replicated/kots-sample-config-values.yaml + + - name: Run a test + # mask the kubeconfig so it doesn't show up in the logs + run: | + echo "Running connectivity test..." + echo "${{ steps.create-cluster.outputs.cluster-kubeconfig }}" > kubeconfig.yaml + sleep 60 + kubectl wait --for=condition=ready pods -l app.kubernetes.io/name=fake-service-frontend --timeout=60s --kubeconfig='./kubeconfig.yaml' + kubectl port-forward svc/frontend-service --pod-running-timeout=2m --kubeconfig='./kubeconfig.yaml' 8080:80 & + sleep 60 + curl -f http://localhost:8080 + echo "Test complete" + + - name: Remove Cluster + id: remove-cluster + uses: replicatedhq/replicated-actions/remove-cluster@v1 + continue-on-error: true # It could be that the cluster is already removed + with: + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + cluster-id: ${{ steps.create-cluster.outputs.cluster-id }} + + - name: Archive Customer + id: archive-customer + if: always() + uses: replicatedhq/replicated-actions/archive-customer@v1 + with: + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + customer-id: ${{ steps.create-customer.outputs.customer-id }} + + promote-to-stable: + needs: + - compatibility-matrix + - push-to-replicated + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Promote to Stable channel + uses: replicatedhq/replicated-actions/promote-release@v1 + with: + app-slug: ${{ secrets.REPLICATED_APP }} + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + channel-to: stable + release-sequence: ${{ needs.push-to-replicated.outputs.release-sequence }} + release-version: ${{ needs.push-to-replicated.outputs.app-version }} + + cleanup-channel: + needs: + - compatibility-matrix + - push-to-replicated + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Archive Replicated Channel + uses: replicatedhq/replicated-actions/archive-channel@v1 + with: + app-slug: ${{ secrets.REPLICATED_APP }} + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + channel-slug: ${{ needs.push-to-replicated.outputs.channel-slug }} \ No newline at end of file diff --git a/applications/fake-services/Makefile b/applications/fake-services/Makefile index 0b97ad59..aa6734a6 100644 --- a/applications/fake-services/Makefile +++ b/applications/fake-services/Makefile @@ -1,7 +1,7 @@ REPLICATED_APP=gerard-helm-fake-service REPLICATED_DIR=$(shell pwd)/replicated CHART_DIR=$(shell pwd)/app -CHART_VERSION=0.7.0 +CHART_VERSION=0.8.0 CHANNELS=Stable Unstable Beta clean-charts: diff --git a/applications/fake-services/app/Chart.yaml b/applications/fake-services/app/Chart.yaml index 9db5acc0..636e5592 100644 --- a/applications/fake-services/app/Chart.yaml +++ b/applications/fake-services/app/Chart.yaml @@ -13,7 +13,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.7.0 +version: 0.8.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/applications/fake-services/app/templates/_helpers.tpl b/applications/fake-services/app/templates/_helpers.tpl index 624d043c..429f8b28 100644 --- a/applications/fake-services/app/templates/_helpers.tpl +++ b/applications/fake-services/app/templates/_helpers.tpl @@ -82,11 +82,15 @@ Image Pull Secrets {{- $pullSecrets = concat $pullSecrets .Values.image.imagePullSecrets -}} {{- end -}} -{{/* Add replicated pull secret if global dockerconfigjson is defined for Helm CLI install*/}} +{{/* Add replicated pull secret if global dockerconfigjson is defined */}} +{{- if hasKey .Values "global" -}} +{{- if hasKey .Values.global "replicated" -}} {{- if .Values.global.replicated.dockerconfigjson -}} {{- $replicatedSecret := dict "name" "replicated-pull-secret" -}} {{- $pullSecrets = append $pullSecrets $replicatedSecret -}} {{- end -}} +{{- end -}} +{{- end -}} {{/* Output the imagePullSecrets block only if we have any secrets */}} {{- if $pullSecrets -}} diff --git a/applications/fake-services/app/templates/replicated-pull-secret.yaml b/applications/fake-services/app/templates/replicated-pull-secret.yaml index d68f993f..d6a7cf9a 100644 --- a/applications/fake-services/app/templates/replicated-pull-secret.yaml +++ b/applications/fake-services/app/templates/replicated-pull-secret.yaml @@ -1,9 +1,11 @@ -{{ if .Values.global.replicated.dockerconfigjson }} +{{- if and (hasKey .Values "global") (hasKey .Values.global "replicated") (hasKey .Values.global.replicated "dockerconfigjson") -}} +{{- if .Values.global.replicated.dockerconfigjson -}} apiVersion: v1 kind: Secret metadata: name: replicated-pull-secret type: kubernetes.io/dockerconfigjson data: - .dockerconfigjson: {{ .Values.global.replicated.dockerconfigjson }} -{{ end }} \ No newline at end of file + .dockerconfigjson: {{ .Values.global.replicated.dockerconfigjson | quote }} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/applications/fake-services/replicated/kots-chart.yaml b/applications/fake-services/replicated/kots-chart.yaml index 494acc7e..292e65e7 100644 --- a/applications/fake-services/replicated/kots-chart.yaml +++ b/applications/fake-services/replicated/kots-chart.yaml @@ -5,7 +5,7 @@ metadata: spec: chart: name: fake-service - chartVersion: 0.7.0 + chartVersion: 0.8.0 helmUpgradeFlags: - --debug values: diff --git a/applications/fake-services/replicated/kots-sample-config-values.yaml b/applications/fake-services/replicated/kots-sample-config-values.yaml new file mode 100644 index 00000000..0149aeb7 --- /dev/null +++ b/applications/fake-services/replicated/kots-sample-config-values.yaml @@ -0,0 +1,12 @@ +apiVersion: kots.io/v1beta1 +kind: ConfigValues +spec: + values: + frontend_message: + value: thisistheway + backend_message: + value: thisistheway + backend_name: + value: Payment + frontend_name: + value: Checkout From 91c559235f9fc11f867b1cae93919a603c86b114 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Mon, 9 Dec 2024 07:53:59 +1100 Subject: [PATCH 6/6] add GH action for unstable --- .../replicated-release-unstable.yaml | 58 +++++++++++++++++++ .../.github/workflows/replicated-release.yaml | 4 ++ 2 files changed, 62 insertions(+) create mode 100644 applications/fake-services/.github/workflows/replicated-release-unstable.yaml diff --git a/applications/fake-services/.github/workflows/replicated-release-unstable.yaml b/applications/fake-services/.github/workflows/replicated-release-unstable.yaml new file mode 100644 index 00000000..45b0d710 --- /dev/null +++ b/applications/fake-services/.github/workflows/replicated-release-unstable.yaml @@ -0,0 +1,58 @@ +name: replicated-release-unstable + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + push-to-replicated: + runs-on: ubuntu-22.04 + outputs: + channel-slug: ${{ steps.create-release.outputs.channel-slug }} + release-sequence: ${{ steps.create-release.outputs.release-sequence }} + app-version: ${{ steps.set-release-version.outputs.VERSION }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get latest tag + id: get-latest-tag + run: | + # Get the latest tag, defaulting to 0.1.0 if none exists + latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.1.0") + echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV + + - name: Set release version + id: set-release-version + run: | + VERSION=${{ env.LATEST_TAG }}-$(git rev-parse --short HEAD) + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + - name: Package Helm chart + id: package-helm-chart + run: | + helm package ./app --debug -u -d ./replicated \ + --version ${{ env.VERSION }} \ + --app-version ${{ env.VERSION }} + + - name: Install yq + run: | + wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq &&\ + chmod +x /usr/local/bin/yq + + - name: Update HelmChart kind + run: | + yq -i '.spec.chart.chartVersion = "${{ env.VERSION }}"' replicated/kots-chart.yaml + + - name: Create Replicated release + id: create-release + uses: replicatedhq/compatibility-actions/create-release@v1 + with: + app-slug: ${{ secrets.REPLICATED_APP }} + api-token: ${{ secrets.REPLICATED_API_TOKEN }} + yaml-dir: ./replicated + promote-channel: unstable + version: ${{ env.VERSION }} \ No newline at end of file diff --git a/applications/fake-services/.github/workflows/replicated-release.yaml b/applications/fake-services/.github/workflows/replicated-release.yaml index 5c5be897..95bf9d90 100644 --- a/applications/fake-services/.github/workflows/replicated-release.yaml +++ b/applications/fake-services/.github/workflows/replicated-release.yaml @@ -26,8 +26,10 @@ jobs: run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT else echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT fi - name: Package Helm chart @@ -74,8 +76,10 @@ jobs: run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT else echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT fi - name: Create Customer id: create-customer