From 96138273ce60d24d318f08998f12015aea002e0b Mon Sep 17 00:00:00 2001 From: devthejo Date: Tue, 29 Aug 2023 10:09:50 +0200 Subject: [PATCH 1/5] feat: chart static-app using zerodowntime probes --- .../tests/__snapshots__/static-app.dev.yaml | 441 ++++++++++++++++++ .../tests/samples/static-app/config.yaml | 3 + .../tests/samples/static-app/values.yaml | 2 + plugins/contrib/charts/static-app/Chart.yaml | 3 + .../static-app/kontinuous.values.schema.json | 130 ++++++ .../static-app/templates/autoscaler.yaml | 42 ++ .../static-app/templates/deployment.yaml | 95 ++++ .../charts/static-app/templates/ingress.yaml | 39 ++ .../static-app/templates/namespace.yaml | 16 + .../charts/static-app/templates/redirect.yaml | 23 + .../charts/static-app/templates/service.yaml | 17 + plugins/contrib/charts/static-app/values.yaml | 70 +++ 12 files changed, 881 insertions(+) create mode 100644 packages/kontinuous/tests/__snapshots__/static-app.dev.yaml create mode 100644 packages/kontinuous/tests/samples/static-app/config.yaml create mode 100644 packages/kontinuous/tests/samples/static-app/values.yaml create mode 100644 plugins/contrib/charts/static-app/Chart.yaml create mode 100644 plugins/contrib/charts/static-app/kontinuous.values.schema.json create mode 100644 plugins/contrib/charts/static-app/templates/autoscaler.yaml create mode 100644 plugins/contrib/charts/static-app/templates/deployment.yaml create mode 100644 plugins/contrib/charts/static-app/templates/ingress.yaml create mode 100644 plugins/contrib/charts/static-app/templates/namespace.yaml create mode 100644 plugins/contrib/charts/static-app/templates/redirect.yaml create mode 100644 plugins/contrib/charts/static-app/templates/service.yaml create mode 100644 plugins/contrib/charts/static-app/values.yaml diff --git a/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml b/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml new file mode 100644 index 0000000000..7ae461af0a --- /dev/null +++ b/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml @@ -0,0 +1,441 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test build manifests with snapshots static-app.dev 1`] = ` +"apiVersion: v1 +kind: Namespace +metadata: + annotations: + field.cattle.io/projectId: \\"1234\\" + kontinuous/gitBranch: feature-branch-1 + kontinuous/mainNamespace: \\"true\\" + kapp.k14s.io/exists: \\"\\" + kontinuous/chartPath: project.fabrique.contrib.rancher-namespace + kontinuous/source: project/charts/fabrique/charts/contrib/charts/rancher-namespace/templates/namespace.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + janitor/ttl: 7d + labels: + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: namespace-test-static-app-feature-branch-1-69vu59uj + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + cert: wildcard + name: test-static-app-feature-branch-1 +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: netpol-ingress + namespace: test-static-app-feature-branch-1 + annotations: + kontinuous/chartPath: project.fabrique.contrib.security-policies + kontinuous/source: project/charts/fabrique/charts/contrib/charts/security-policies/templates/network-policy.yml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + labels: + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: networkpolicy-netpol-ingress-61ndxljw + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous +spec: + ingress: + - from: + - podSelector: {} + - from: + - namespaceSelector: + matchLabels: + network-policy/source: ingress-controller + - from: + - namespaceSelector: + matchLabels: + network-policy/source: monitoring + podSelector: {} + policyTypes: + - Ingress +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: default + annotations: + kontinuous/chartPath: project.fabrique.contrib.security-policies + kontinuous/source: project/charts/fabrique/charts/contrib/charts/security-policies/templates/service-account.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + labels: + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: serviceaccount-default-2g5dmk74 + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + namespace: test-static-app-feature-branch-1 +automountServiceAccountToken: false +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + component: site + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: deployment-site-kmsczrbj + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + name: site + namespace: test-static-app-feature-branch-1 + annotations: + kontinuous/chartPath: project.fabrique.contrib.site + kontinuous/source: project/charts/fabrique/charts/contrib/charts/site/templates/deployment.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/depname.full: project.fabrique.contrib.site.deployment.site + kontinuous/depname.chartResource: site.deployment.site + kontinuous/depname.chartName: site + kontinuous/depname.chartPath: project.fabrique.contrib.site + kontinuous/depname.resourcePath: deployment.site + kontinuous/depname.resourceName: site + kontinuous/depname.chartNameTopFull: site + kontinuous/depname.chartNameTop: site + kontinuous/plugin.log: \\"false\\" + reloader.stakater.com/auto: \\"true\\" +spec: + replicas: 1 + selector: + matchLabels: + component: site + strategy: + type: RollingUpdate + template: + metadata: + labels: + component: site + application: test-static-app + namespace: test-static-app-feature-branch-1 + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: deployment-site-kmsczrbj + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + annotations: + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: namespace + operator: In + values: + - test-static-app-feature-branch-1 + - key: component + operator: In + values: + - site + topologyKey: kubernetes.io/hostname + containers: + - image: harbor.fabrique.social.gouv.fr/test-static-app/app:sha-ffac537e6cbbf934b08745a378932722df287a53 + name: app + ports: + - containerPort: 8080 + name: http + livenessProbe: + failureThreshold: 15 + httpGet: + path: /live + port: 8080 + initialDelaySeconds: 30 + periodSeconds: 5 + timeoutSeconds: 5 + readinessProbe: + failureThreshold: 15 + httpGet: + path: /ready + port: 8080 + initialDelaySeconds: 1 + periodSeconds: 5 + successThreshold: 1 + timeoutSeconds: 1 + startupProbe: + failureThreshold: 12 + httpGet: + path: /live + port: 8080 + periodSeconds: 5 + lifecycle: + preStop: + exec: + command: + - /pre-stop.sh + resources: + limits: + cpu: 1 + memory: 1Gi + requests: + cpu: 41m + memory: 121Mi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + component: static-app + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: deployment-static-app-1dyc8ubf + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + name: static-app + namespace: test-static-app-feature-branch-1 + annotations: + kontinuous/chartPath: project.fabrique.contrib.static-app + kontinuous/source: project/charts/fabrique/charts/contrib/charts/static-app/templates/deployment.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/depname.full: project.fabrique.contrib.static-app.deployment.static-app + kontinuous/depname.chartResource: static-app.deployment.static-app + kontinuous/depname.chartName: static-app + kontinuous/depname.chartPath: project.fabrique.contrib.static-app + kontinuous/depname.resourcePath: deployment.static-app + kontinuous/depname.resourceName: static-app + kontinuous/depname.chartNameTopFull: static-app + kontinuous/depname.chartNameTop: static-app + kontinuous/plugin.log: \\"false\\" + reloader.stakater.com/auto: \\"true\\" +spec: + replicas: 1 + selector: + matchLabels: + component: static-app + strategy: + type: RollingUpdate + template: + metadata: + labels: + component: static-app + application: test-static-app + namespace: test-static-app-feature-branch-1 + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: deployment-static-app-1dyc8ubf + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + annotations: + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: namespace + operator: In + values: + - test-static-app-feature-branch-1 + - key: component + operator: In + values: + - static-app + topologyKey: kubernetes.io/hostname + containers: + - image: harbor.fabrique.social.gouv.fr/test-static-app/app:sha-ffac537e6cbbf934b08745a378932722df287a53 + name: app + ports: + - containerPort: 8080 + name: http + livenessProbe: + failureThreshold: 15 + httpGet: + path: /live + port: 8080 + initialDelaySeconds: 30 + periodSeconds: 5 + timeoutSeconds: 5 + readinessProbe: + failureThreshold: 15 + httpGet: + path: /ready + port: 8080 + initialDelaySeconds: 1 + periodSeconds: 5 + successThreshold: 1 + timeoutSeconds: 1 + startupProbe: + failureThreshold: 12 + httpGet: + path: /live + port: 8080 + periodSeconds: 5 + lifecycle: + preStop: + exec: + command: + - /pre-stop.sh + resources: + limits: + cpu: 1 + memory: 1Gi + requests: + cpu: 41m + memory: 121Mi +--- +apiVersion: v1 +kind: Service +metadata: + labels: + component: site + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: service-site-684o81sg + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + name: site + namespace: test-static-app-feature-branch-1 + annotations: + kontinuous/chartPath: project.fabrique.contrib.site + kontinuous/source: project/charts/fabrique/charts/contrib/charts/site/templates/service.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + component: site + type: ClusterIP +--- +apiVersion: v1 +kind: Service +metadata: + labels: + component: static-app + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: service-static-app-54t7mvr8 + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + name: static-app + namespace: test-static-app-feature-branch-1 + annotations: + kontinuous/chartPath: project.fabrique.contrib.static-app + kontinuous/source: project/charts/fabrique/charts/contrib/charts/static-app/templates/service.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + component: static-app + type: ClusterIP +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + kontinuous/chartPath: project.fabrique.contrib.site + kontinuous/source: project/charts/fabrique/charts/contrib/charts/site/templates/ingress.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + labels: + component: site + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: ingress-site-ni9q5ueo + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + name: site + namespace: test-static-app-feature-branch-1 +spec: + rules: + - host: site-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr + http: + paths: + - backend: + service: + name: site + port: + name: http + path: / + pathType: Prefix + tls: + - hosts: + - site-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr + secretName: wildcard-crt +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + kontinuous/chartPath: project.fabrique.contrib.static-app + kontinuous/source: project/charts/fabrique/charts/contrib/charts/static-app/templates/ingress.yaml + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + labels: + component: static-app + application: test-static-app + kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 + kontinuous/deployment.env: test-static-app-feature-branch-1 + kontinuous/ref: feature-branch-1 + kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 + kontinuous/resourceName: ingress-static-app-4wuyb69i + app.kubernetes.io/manifest-managed-by: kontinuous + app.kubernetes.io/manifest-created-by: kontinuous + name: static-app + namespace: test-static-app-feature-branch-1 +spec: + rules: + - host: static-app-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr + http: + paths: + - backend: + service: + name: static-app + port: + name: http + path: / + pathType: Prefix + tls: + - hosts: + - static-app-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr + secretName: wildcard-crt +" +`; diff --git a/packages/kontinuous/tests/samples/static-app/config.yaml b/packages/kontinuous/tests/samples/static-app/config.yaml new file mode 100644 index 0000000000..ff779aad47 --- /dev/null +++ b/packages/kontinuous/tests/samples/static-app/config.yaml @@ -0,0 +1,3 @@ +dependencies: + fabrique: + import: socialgouv/kontinuous/plugins/fabrique \ No newline at end of file diff --git a/packages/kontinuous/tests/samples/static-app/values.yaml b/packages/kontinuous/tests/samples/static-app/values.yaml new file mode 100644 index 0000000000..f2cb1bdd18 --- /dev/null +++ b/packages/kontinuous/tests/samples/static-app/values.yaml @@ -0,0 +1,2 @@ +site: + ~chart: static-app diff --git a/plugins/contrib/charts/static-app/Chart.yaml b/plugins/contrib/charts/static-app/Chart.yaml new file mode 100644 index 0000000000..66cdacd9a8 --- /dev/null +++ b/plugins/contrib/charts/static-app/Chart.yaml @@ -0,0 +1,3 @@ +apiVersion: v2 +name: static-app +version: 1.164.0 diff --git a/plugins/contrib/charts/static-app/kontinuous.values.schema.json b/plugins/contrib/charts/static-app/kontinuous.values.schema.json new file mode 100644 index 0000000000..200675dbd3 --- /dev/null +++ b/plugins/contrib/charts/static-app/kontinuous.values.schema.json @@ -0,0 +1,130 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/contrib/charts/app/kontinuous.values.schema.json", + "title": "schema for helm chart static-app", + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^\\.": { "type": ["string", "number", "boolean"] } + }, + "properties": { + "~chart": { + "description": "Target this chart: static-app", + "type": "string" + }, + "~forceRestart": { + "description": "Force restart on every deployment. default true", + "type": "boolean", + "default": true + }, + "~needs": { + "description": "Job or deployment dependencies", + "type": "array", + "items": { + "type": "string" + }, + "examples": ["[build-app]"] + }, + "image": { + "description": "Full path to docker image", + "examples": ["ghcr.io/socialgouv/docker/nginx:8.2.0"], + "type": "string" + }, + "imagePackage": { + "description": "Name of the package on the registry", + "type": "string" + }, + "imageProject": { + "description": "Project name in the docker registry, default to projectName on local registry as harbor, default to organization name on ghcr.io", + "type": "string" + }, + "imageRepository": { + "description": "Repository for the docker image, default to git repository name", + "type": "string" + }, + "probesPath": { + "description": "Path to application health probe. Defaults to /healthz", + "type": "string", + "examples": ["/healthz"] + }, + "probesPort": { + "description": "Port for probes calls", + "type": ["string", "number"] + }, + "containerPort": { + "description": "Container port, defaults to 3000", + "type": ["string", "number"] + }, + "host": { + "description": "Hostname for the deployment", + "type": "string" + }, + "ingress": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { + "description": "Ingress enable. default to true", + "type": "boolean" + }, + "path": { + "description": "URL path to map the ingress to", + "type": "string", + "examples": ["/"] + }, + "rewriteTarget": { + "description": "Redirect path on the service", + "type": "string", + "examples": ["/$1"] + }, + "annotations": { + "type": "object", + "additionalProperties": true + } + } + }, + "certSecretName": { + "description": "Name of existing SSL cert secret if any.", + "type": "string" + }, + "addVolumes": { + "description": "List of PVC claimNames to add to the deployment", + "type": "array", + "items": { + "type": "string" + }, + "examples": ["[uploads]"] + }, + "env": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.Container/properties/env" + }, + "envFrom": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.Container/properties/envFrom" + }, + "vars": { "type": "object", "additionalProperties": true }, + "volumes": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.PodSpec/properties/volumes" + }, + "volumeMounts": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.Container/properties/volumeMounts" + }, + "replicas": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.apps.v1.DeploymentSpec/properties/replicas" + }, + "resources": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.ResourceRequirements" + }, + "livenessProbe": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.Probe", + "description": "Periodic probe of container liveness. Container will be restarted if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes" + }, + "readinessProbe": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.Probe", + "description": "Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes" + }, + "startupProbe": { + "$ref": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json#/definitions/io.k8s.api.core.v1.Probe", + "description": "StartupProbe indicates that the Pod has successfully initialized. If specified, no other probes are executed until this completes successfully. If this probe fails, the Pod will be restarted, just as if the livenessProbe failed. This can be used to provide different probe parameters at the beginning of a Pod's lifecycle, when it might take a long time to load data or warm a cache, than during steady-state operation. This cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes" + } + } +} diff --git a/plugins/contrib/charts/static-app/templates/autoscaler.yaml b/plugins/contrib/charts/static-app/templates/autoscaler.yaml new file mode 100644 index 0000000000..64df84b067 --- /dev/null +++ b/plugins/contrib/charts/static-app/templates/autoscaler.yaml @@ -0,0 +1,42 @@ +{{ if .Values.autoscale.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ (or .Values.component .Chart.Name) | lower }} + namespace: {{ or .Values.namespace .Values.global.namespace }} + labels: + component: {{ (or .Values.component .Chart.Name) | lower }} +spec: + minReplicas: {{ .Values.autoscale.minReplicas }} + maxReplicas: {{ .Values.autoscale.maxReplicas }} + metrics: + - resource: + name: cpu + target: + averageUtilization: {{ .Values.autoscale.averageUtilization.cpu }} + type: Utilization + type: Resource + - resource: + name: memory + target: + averageUtilization: {{ .Values.autoscale.averageUtilization.memory }} + type: Utilization + type: Resource + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ (or .Values.component .Chart.Name) | lower }} +--- +# see https://carvel.dev/kapp/docs/develop/hpa-deployment-rebase/ +apiVersion: kapp.k14s.io/v1alpha1 +kind: Config +rebaseRules: +- path: [spec, replicas] + type: copy + sources: [existing, new] + resourceMatchers: + - kindNamespaceNameMatcher: + kind: Deployment + namespace: {{ or .Values.namespace .Values.global.namespace }} + name: {{ (or .Values.component .Chart.Name) | lower }} +{{ end }} \ No newline at end of file diff --git a/plugins/contrib/charts/static-app/templates/deployment.yaml b/plugins/contrib/charts/static-app/templates/deployment.yaml new file mode 100644 index 0000000000..6d81e41836 --- /dev/null +++ b/plugins/contrib/charts/static-app/templates/deployment.yaml @@ -0,0 +1,95 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + component: {{ (or .Values.component .Chart.Name) | lower }} + application: {{ .Values.global.repositoryName }} + name: {{ (or .Values.component .Chart.Name) | lower }} + namespace: {{ or .Values.namespace .Values.global.namespace }} + annotations: {} +spec: + replicas: {{ or .Values.replicas .Values.global.replicas 1 }} + selector: + matchLabels: + component: {{ (or .Values.component .Chart.Name) | lower }} + strategy: + type: {{ .Values.strategyType }} + template: + metadata: + labels: + component: {{ (or .Values.component .Chart.Name) | lower }} + application: {{ .Values.global.repositoryName }} + namespace: {{ or .Values.namespace .Values.global.namespace }} + spec: + affinity: + {{- include "contrib-helpers.anti-affinity" . | nindent 8}} + initContainers: + {{- if .Values.waitForPostgres }} + {{- include "contrib-helpers.init-containers.wait-for-postgres" . | nindent 8 }} + {{- end }} + volumes: + {{- if gt (len .Values.volumes) 0 }} + {{- tpl (.Values.volumes | toYaml) . | nindent 8 }} + {{- end }} + {{- range $volumeName := .Values.addVolumes }} + - name: "{{ tpl $volumeName $ }}" + persistentVolumeClaim: + claimName: "{{ tpl $volumeName $ }}" + {{- end }} + containers: + - {{- if .Values.image }} + image: "{{ .Values.image }}" + {{- else }} + image: "{{ or .Values.registry .Values.global.registry }}{{ if (or .Values.imageProject .Values.global.imageProject) }}{{ (print "/" (or .Values.imageProject .Values.global.imageProject)) }}{{ end }}{{ if (or .Values.imageRepository .Values.global.imageRepository) }}{{ (print "/" (or .Values.imageRepository .Values.global.imageRepository)) }}{{ end }}{{ if .Values.imagePackage }}{{ (print "/" .Values.imagePackage) }}{{ end }}:{{ or .Values.imageTag .Values.global.imageTag }}" + {{- end }} + {{- if .Values.entrypoint }} + command: | + {{- tpl (.Values.entrypoint | toYaml) $ | nindent 12 }} + {{- end }} + {{- if .Values.cmd }} + args: + {{- range $arg := .Values.args }} + - "{{ tpl $arg $ }}" + {{- end }} + {{- end }} + name: app + ports: + - containerPort: {{ .Values.containerPort }} + name: http + livenessProbe: + {{- include "contrib-helpers.livenessProbe" . | nindent 12 }} + readinessProbe: + {{- include "contrib-helpers.readinessProbe" . | nindent 12 }} + startupProbe: + {{- include "contrib-helpers.startupProbe" . | nindent 12 }} + {{ if .Values.lifecycle }} + lifecycle: + {{- tpl (.Values.lifecycle | toYaml) . | nindent 12 }} + {{ end }} + resources: + limits: + cpu: {{ .Values.resources.limits.cpu | quote }} + memory: {{ .Values.resources.limits.memory | quote }} + requests: + cpu: {{ .Values.resources.requests.cpu | quote }} + memory: {{ .Values.resources.requests.memory | quote }} + env: + {{- if gt (len .Values.env) 0 }} + {{- tpl (.Values.env | toYaml) . | nindent 12 }} + {{- end }} + {{- range $name, $value := .Values.vars }} + - name: "{{ $name }}" + value: "{{ tpl $value $ }}" + {{- end }} + envFrom: + {{- if gt (len .Values.envFrom) 0 }} + {{- tpl (.Values.envFrom | toYaml) . | nindent 12 }} + {{- end }} + volumeMounts: + {{- if gt (len .Values.volumeMounts) 0 }} + {{- tpl (.Values.volumeMounts | toYaml) . | nindent 12 }} + {{- end }} + {{- range $volumeName := .Values.addVolumes }} + - name: "{{ tpl $volumeName $ }}" + mountPath: "/mnt/{{ tpl $volumeName $ }}" + {{- end }} \ No newline at end of file diff --git a/plugins/contrib/charts/static-app/templates/ingress.yaml b/plugins/contrib/charts/static-app/templates/ingress.yaml new file mode 100644 index 0000000000..7a41fc8ff6 --- /dev/null +++ b/plugins/contrib/charts/static-app/templates/ingress.yaml @@ -0,0 +1,39 @@ +{{ if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + {{ if .Values.ingress.rewriteTarget }} + nginx.ingress.kubernetes.io/rewrite-target: {{ .Values.ingress.rewriteTarget | quote }} + {{ end }} + {{ range $key, $val := (merge dict .Values.global.ingress.annotations .Values.ingress.annotations) }} + "{{ $key }}": {{ $val | quote }} + {{ end }} + labels: + component: {{ (or .Values.component .Chart.Name) | lower }} + application: {{ .Values.global.repositoryName }} + name: {{ (or .Values.component .Chart.Name) | lower }} + namespace: {{ or .Values.namespace .Values.global.namespace }} +spec: + rules: + - host: >- + {{- include "contrib-helpers.ingress-host" . | nindent 8 }} + http: + paths: + {{ range $val := (or .Values.ingress.paths (list .Values.ingress.path)) }} + - backend: + service: + name: {{ (or $.Values.component $.Chart.Name) | lower }} + port: + name: http + path: {{ $val | quote }} + pathType: Prefix + {{ end }} + + tls: + - hosts: + - >- + {{- include "contrib-helpers.ingress-host" . | nindent 10 }} + {{ include "contrib-helpers.ingress-secret" . | nindent 6 }} +{{ end }} \ No newline at end of file diff --git a/plugins/contrib/charts/static-app/templates/namespace.yaml b/plugins/contrib/charts/static-app/templates/namespace.yaml new file mode 100644 index 0000000000..9877f1e0e7 --- /dev/null +++ b/plugins/contrib/charts/static-app/templates/namespace.yaml @@ -0,0 +1,16 @@ +{{ if .Values.namespace }} +apiVersion: v1 +kind: Namespace +metadata: + annotations: + field.cattle.io/projectId: "{{ or .Values.rancherProjectId .Values.global.rancherProjectId }}" + kontinuous/gitBranch: "{{ or .Values.global.gitBranch "" }}" + kontinuous/mainNamespace: "true" + kapp.k14s.io/exists: "" + labels: + application: {{ .Values.global.repositoryName }} + {{- if not .Values.global.isProd }} + cert: wildcard + {{- end }} + name: {{ .Values.namespace }} +{{ end }} \ No newline at end of file diff --git a/plugins/contrib/charts/static-app/templates/redirect.yaml b/plugins/contrib/charts/static-app/templates/redirect.yaml new file mode 100644 index 0000000000..811b0443bd --- /dev/null +++ b/plugins/contrib/charts/static-app/templates/redirect.yaml @@ -0,0 +1,23 @@ +{{ if gt (len .Values.redirectFrom) 0 }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: "{{ (or .Values.component .Chart.Name) | lower }}-redirect" + annotations: + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/permanent-redirect: https://{{- include "contrib-helpers.ingress-host" . -}}$request_uri + {{- range $key, $val := (merge dict .Values.global.ingress.annotations .Values.ingress.annotations) }} + "{{ $key }}": {{ $val | quote }} + {{- end }} +spec: + rules: + {{ range $host := .Values.redirectFrom }} + - host: "{{ tpl $host $ }}" + {{ end }} + tls: + - hosts: + {{ range $host := .Values.redirectFrom }} + - "{{ tpl $host $ }}" + {{ end }} + secretName: "{{ (or .Values.component .Chart.Name) | lower }}-redirect" +{{ end }} \ No newline at end of file diff --git a/plugins/contrib/charts/static-app/templates/service.yaml b/plugins/contrib/charts/static-app/templates/service.yaml new file mode 100644 index 0000000000..af890f5e95 --- /dev/null +++ b/plugins/contrib/charts/static-app/templates/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + component: {{ (or .Values.component .Chart.Name) | lower }} + application: {{ .Values.global.repositoryName }} + name: {{ (or .Values.component .Chart.Name) | lower }} + namespace: {{ or .Values.namespace .Values.global.namespace }} + annotations: {} +spec: + ports: + - name: http + port: {{ .Values.servicePort }} + targetPort: {{ .Values.containerPort }} + selector: + component: {{ (or .Values.component .Chart.Name) | lower }} + type: ClusterIP \ No newline at end of file diff --git a/plugins/contrib/charts/static-app/values.yaml b/plugins/contrib/charts/static-app/values.yaml new file mode 100644 index 0000000000..9f675ccfd4 --- /dev/null +++ b/plugins/contrib/charts/static-app/values.yaml @@ -0,0 +1,70 @@ +enabled: +namespace: +host: +registry: +imagePath: +imageProject: +imageRepository: +imagePackage: app +imageTag: +image: +ttl: +rancherProjectId: +isProd: false +isPreProd: false +replicas: +containerPort: 8080 +servicePort: 80 +env: [] +vars: {} +envFrom: [] +livenessProbe: + httpGet: + path: /live + port: 8080 +startupProbe: + httpGet: + path: /live + port: 8080 +readinessProbe: + httpGet: + path: /ready + port: 8080 +lifecycle: + preStop: + exec: + command: ["/pre-stop.sh"] +resources: + limits: + cpu: + memory: + requests: + cpu: + memory: +autoscale: + enabled: false + minReplicas: 2 + maxReplicas: 10 + averageUtilization: + cpu: 70 + memory: 80 +certSecretName: +waitForPostgres: false +addVolumes: [] +volumes: [] +volumeMounts: [] +redirectFrom: [] +ingress: + enabled: true + annotations: {} + path: / + paths: + rewriteTarget: +entrypoint: +args: [] +antiAffinity: + enabled: +onChangedPaths: +onChangedAnnotate: +onChangedNeeds: +strategyType: RollingUpdate \ No newline at end of file From 2c4670f6c9438a72eb8f8ffdfe92061021ef86a0 Mon Sep 17 00:00:00 2001 From: devthejo Date: Tue, 29 Aug 2023 10:12:37 +0200 Subject: [PATCH 2/5] fix: jsonschema --- plugins/contrib/charts/static-app/kontinuous.values.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/contrib/charts/static-app/kontinuous.values.schema.json b/plugins/contrib/charts/static-app/kontinuous.values.schema.json index 200675dbd3..fda77c7de1 100644 --- a/plugins/contrib/charts/static-app/kontinuous.values.schema.json +++ b/plugins/contrib/charts/static-app/kontinuous.values.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/contrib/charts/app/kontinuous.values.schema.json", + "$id": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/contrib/charts/static-app/kontinuous.values.schema.json", "title": "schema for helm chart static-app", "type": "object", "additionalProperties": false, From a6e5743e929edb66904a8a661f7766b0e0cb74ca Mon Sep 17 00:00:00 2001 From: devthejo Date: Tue, 29 Aug 2023 10:41:15 +0200 Subject: [PATCH 3/5] fix: up --- plugins/contrib/Chart.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/contrib/Chart.yaml b/plugins/contrib/Chart.yaml index d131df9d19..16ca132422 100644 --- a/plugins/contrib/Chart.yaml +++ b/plugins/contrib/Chart.yaml @@ -25,6 +25,10 @@ dependencies: repository: file://./charts/app version: 1.164.0 condition: app.enabled + - name: static-app + repository: file://./charts/static-app + version: 1.164.0 + condition: static-app.enabled - name: daemon repository: file://./charts/daemon version: 1.164.0 From c7ff23a39be689ee7d9a1ff0422633fcd621b689 Mon Sep 17 00:00:00 2001 From: devthejo Date: Tue, 29 Aug 2023 11:06:23 +0200 Subject: [PATCH 4/5] fix: snapshots --- .../tests/__snapshots__/static-app.dev.yaml | 179 ------------------ 1 file changed, 179 deletions(-) diff --git a/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml b/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml index 7ae461af0a..d3ae5f9bec 100644 --- a/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml +++ b/packages/kontinuous/tests/__snapshots__/static-app.dev.yaml @@ -192,118 +192,6 @@ spec: cpu: 41m memory: 121Mi --- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - component: static-app - application: test-static-app - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - kontinuous/deployment.env: test-static-app-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: deployment-static-app-1dyc8ubf - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - name: static-app - namespace: test-static-app-feature-branch-1 - annotations: - kontinuous/chartPath: project.fabrique.contrib.static-app - kontinuous/source: project/charts/fabrique/charts/contrib/charts/static-app/templates/deployment.yaml - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - kontinuous/depname.full: project.fabrique.contrib.static-app.deployment.static-app - kontinuous/depname.chartResource: static-app.deployment.static-app - kontinuous/depname.chartName: static-app - kontinuous/depname.chartPath: project.fabrique.contrib.static-app - kontinuous/depname.resourcePath: deployment.static-app - kontinuous/depname.resourceName: static-app - kontinuous/depname.chartNameTopFull: static-app - kontinuous/depname.chartNameTop: static-app - kontinuous/plugin.log: \\"false\\" - reloader.stakater.com/auto: \\"true\\" -spec: - replicas: 1 - selector: - matchLabels: - component: static-app - strategy: - type: RollingUpdate - template: - metadata: - labels: - component: static-app - application: test-static-app - namespace: test-static-app-feature-branch-1 - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - kontinuous/deployment.env: test-static-app-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: deployment-static-app-1dyc8ubf - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - annotations: - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - spec: - affinity: - podAntiAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 1 - podAffinityTerm: - labelSelector: - matchExpressions: - - key: namespace - operator: In - values: - - test-static-app-feature-branch-1 - - key: component - operator: In - values: - - static-app - topologyKey: kubernetes.io/hostname - containers: - - image: harbor.fabrique.social.gouv.fr/test-static-app/app:sha-ffac537e6cbbf934b08745a378932722df287a53 - name: app - ports: - - containerPort: 8080 - name: http - livenessProbe: - failureThreshold: 15 - httpGet: - path: /live - port: 8080 - initialDelaySeconds: 30 - periodSeconds: 5 - timeoutSeconds: 5 - readinessProbe: - failureThreshold: 15 - httpGet: - path: /ready - port: 8080 - initialDelaySeconds: 1 - periodSeconds: 5 - successThreshold: 1 - timeoutSeconds: 1 - startupProbe: - failureThreshold: 12 - httpGet: - path: /live - port: 8080 - periodSeconds: 5 - lifecycle: - preStop: - exec: - command: - - /pre-stop.sh - resources: - limits: - cpu: 1 - memory: 1Gi - requests: - cpu: 41m - memory: 121Mi ---- apiVersion: v1 kind: Service metadata: @@ -333,35 +221,6 @@ spec: component: site type: ClusterIP --- -apiVersion: v1 -kind: Service -metadata: - labels: - component: static-app - application: test-static-app - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - kontinuous/deployment.env: test-static-app-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: service-static-app-54t7mvr8 - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - name: static-app - namespace: test-static-app-feature-branch-1 - annotations: - kontinuous/chartPath: project.fabrique.contrib.static-app - kontinuous/source: project/charts/fabrique/charts/contrib/charts/static-app/templates/service.yaml - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 -spec: - ports: - - name: http - port: 80 - targetPort: 8080 - selector: - component: static-app - type: ClusterIP ---- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: @@ -399,43 +258,5 @@ spec: - hosts: - site-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr secretName: wildcard-crt ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - annotations: - kubernetes.io/ingress.class: nginx - kontinuous/chartPath: project.fabrique.contrib.static-app - kontinuous/source: project/charts/fabrique/charts/contrib/charts/static-app/templates/ingress.yaml - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - labels: - component: static-app - application: test-static-app - kontinuous/deployment: test-static-app-feature-branch-1-ffac537e6cbbf934b087-27at1928 - kontinuous/deployment.env: test-static-app-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: ingress-static-app-4wuyb69i - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - name: static-app - namespace: test-static-app-feature-branch-1 -spec: - rules: - - host: static-app-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr - http: - paths: - - backend: - service: - name: static-app - port: - name: http - path: / - pathType: Prefix - tls: - - hosts: - - static-app-test-static-app-feature-branch-1.dev.fabrique.social.gouv.fr - secretName: wildcard-crt " `; From 165af4ce7dc8e987bd36067aceea56b0ca722ab9 Mon Sep 17 00:00:00 2001 From: devthejo Date: Tue, 29 Aug 2023 12:37:47 +0200 Subject: [PATCH 5/5] fix: up --- plugins/contrib/charts/static-app/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/contrib/charts/static-app/templates/deployment.yaml b/plugins/contrib/charts/static-app/templates/deployment.yaml index 6d81e41836..0d00d25b5f 100644 --- a/plugins/contrib/charts/static-app/templates/deployment.yaml +++ b/plugins/contrib/charts/static-app/templates/deployment.yaml @@ -43,7 +43,7 @@ spec: image: "{{ or .Values.registry .Values.global.registry }}{{ if (or .Values.imageProject .Values.global.imageProject) }}{{ (print "/" (or .Values.imageProject .Values.global.imageProject)) }}{{ end }}{{ if (or .Values.imageRepository .Values.global.imageRepository) }}{{ (print "/" (or .Values.imageRepository .Values.global.imageRepository)) }}{{ end }}{{ if .Values.imagePackage }}{{ (print "/" .Values.imagePackage) }}{{ end }}:{{ or .Values.imageTag .Values.global.imageTag }}" {{- end }} {{- if .Values.entrypoint }} - command: | + command: {{- tpl (.Values.entrypoint | toYaml) $ | nindent 12 }} {{- end }} {{- if .Values.cmd }}