From f87787355628ffc6cbacf85fc75d3807c9340f49 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 29 Oct 2024 16:35:24 +0100 Subject: [PATCH 1/2] Enables testing NOdeJS Helm chart on shared cluster. The enablement has to be specified in values.yaml file Signed-off-by: Petr "Stone" Hracek --- .../redhat/nodejs-application/src/Chart.yaml | 4 +- .../src/templates/buildconfig.yaml | 9 ++++ .../src/templates/deployment.yaml | 6 +++ .../nodejs-application/src/values.schema.json | 20 ++++++++ .../redhat/nodejs-application/src/values.yaml | 5 ++ tests/test_nodejs_application.py | 48 +++++++++++++++---- 6 files changed, 81 insertions(+), 11 deletions(-) diff --git a/charts/redhat/nodejs-application/src/Chart.yaml b/charts/redhat/nodejs-application/src/Chart.yaml index 2610041..dfe0624 100644 --- a/charts/redhat/nodejs-application/src/Chart.yaml +++ b/charts/redhat/nodejs-application/src/Chart.yaml @@ -2,13 +2,13 @@ description: This content is experimental, do not use it in production. An examp about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md. name: nodejs-application tags: quickstart,nodejs -version: 0.0.1 +version: 0.0.2 kubeVersion: '>=1.20.0' annotations: charts.openshift.io/name: Red Hat Apache Rails application with no database (experimental) charts.openshift.io/provider: Red Hat charts.openshift.io/providerType: redhat apiVersion: v2 -appVersion: 0.0.1 +appVersion: 0.0.2 sources: - https://github.com/sclorg/helm-charts diff --git a/charts/redhat/nodejs-application/src/templates/buildconfig.yaml b/charts/redhat/nodejs-application/src/templates/buildconfig.yaml index 7969a79..056abe9 100644 --- a/charts/redhat/nodejs-application/src/templates/buildconfig.yaml +++ b/charts/redhat/nodejs-application/src/templates/buildconfig.yaml @@ -9,10 +9,19 @@ metadata: template: nodejs-example name: {{ .Values.name }} spec: + {{ if .Values.registry.enabled }} + output: + to: + kind: DockerImage + name: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest" + pushSecret: + name: {{ .Values.registry.push_secret }} + {{ else }} output: to: kind: ImageStreamTag name: {{ .Values.name }}:latest + {{ end }} source: contextDir: {{ .Values.context_dir }} git: diff --git a/charts/redhat/nodejs-application/src/templates/deployment.yaml b/charts/redhat/nodejs-application/src/templates/deployment.yaml index 1fb6d53..188cb50 100644 --- a/charts/redhat/nodejs-application/src/templates/deployment.yaml +++ b/charts/redhat/nodejs-application/src/templates/deployment.yaml @@ -3,6 +3,7 @@ kind: Deployment metadata: annotations: description: Defines how to deploy the application server + {{ if not .Values.registry.enabled }} image.openshift.io/triggers: |- [ { @@ -13,6 +14,7 @@ metadata: "fieldPath": "spec.template.spec.containers[0].image" } ] + {{ end }} template.alpha.openshift.io/wait-for-ready: "true" labels: app: nodejs-example @@ -32,7 +34,11 @@ spec: name: {{ .Values.name }} spec: containers: + {{ if .Values.registry.enabled }} + - image: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest" + {{ else }} - image: " " + {{ end }} livenessProbe: httpGet: path: / diff --git a/charts/redhat/nodejs-application/src/values.schema.json b/charts/redhat/nodejs-application/src/values.schema.json index c2e4943..31ecebb 100644 --- a/charts/redhat/nodejs-application/src/values.schema.json +++ b/charts/redhat/nodejs-application/src/values.schema.json @@ -49,6 +49,26 @@ "npm_mirror": { "type": "string", "description": "The custom NPM mirror URL." + }, + "registry": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "name": { + "type": "string", + "description": "The name of registry that will be used for pushing built image." + }, + "namespace": { + "type": "string", + "description": "The namespace of registry that will be used for pushing built image." + }, + "push_secret": { + "type": "string", + "description": "The push secret to push image to registry." + } + } } } } diff --git a/charts/redhat/nodejs-application/src/values.yaml b/charts/redhat/nodejs-application/src/values.yaml index db91f68..b9e0480 100644 --- a/charts/redhat/nodejs-application/src/values.yaml +++ b/charts/redhat/nodejs-application/src/values.yaml @@ -9,3 +9,8 @@ nodejs_version: 20-ubi8 npm_mirror: "" # TODO: must define a default value for .npm_mirror source_repository_ref: "master" # TODO: must define a default value for .source_repository_ref source_repository_url: https://github.com/sclorg/nodejs-ex.git +registry: + enabled: false + name: "quay.io" + namespace: "something" + push_secret: "" diff --git a/tests/test_nodejs_application.py b/tests/test_nodejs_application.py index affddcf..6fe5122 100644 --- a/tests/test_nodejs_application.py +++ b/tests/test_nodejs_application.py @@ -18,7 +18,20 @@ def setup_method(self): def teardown_method(self): self.hc_api.delete_project() - def test_curl_connection(self): + @pytest.mark.parametrize( + "version", + [ + "20-ubi9", + "20-ubi9-minimal" + "20-ubi8", + "20-ubi8-minimal", + "18-ubi9", + "18-ubi9-minimal", + "18-ubi8", + "18-ubi8-minimal", + ], + ) + def test_curl_connection(self, version): if self.hc_api.oc_api.shared_cluster: pytest.skip("Do NOT test on shared cluster") self.hc_api.package_name = "nodejs-imagestreams" @@ -26,29 +39,46 @@ def test_curl_connection(self): assert self.hc_api.helm_installation() self.hc_api.package_name = "nodejs-application" assert self.hc_api.helm_package() + pod_name = f"nodejs-ex-{version}" assert self.hc_api.helm_installation( values={ - "nodejs_version": "20-ubi8", - "namespace": self.hc_api.namespace + "nodejs_version": version, + "namespace": self.hc_api.namespace, + "name": pod_name } ) - assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nodejs-example") + assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name) assert self.hc_api.test_helm_curl_output( - route_name="nodejs-example", + route_name=pod_name, expected_str="Node.js Crud Application" ) - def test_by_helm_test(self): + @pytest.mark.parametrize( + "version", + [ + "20-ubi9", + "20-ubi9-minimal" + "20-ubi8", + "20-ubi8-minimal", + "18-ubi9", + "18-ubi9-minimal", + "18-ubi8", + "18-ubi8-minimal", + ], + ) + def test_by_helm_test(self, version): self.hc_api.package_name = "nodejs-imagestreams" self.hc_api.helm_package() assert self.hc_api.helm_installation() self.hc_api.package_name = "nodejs-application" assert self.hc_api.helm_package() + pod_name = f"nodejs-ex-{version}" assert self.hc_api.helm_installation( values={ - "nodejs": "20-ubi8", - "namespace": self.hc_api.namespace + "nodejs": version, + "namespace": self.hc_api.namespace, + "name": pod_name } ) - assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nodejs-example") + assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name) assert self.hc_api.test_helm_chart(expected_str=["Node.js Crud Application"]) From 1ec8479686dd73a874cc3e16ef1459ee189833e8 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 30 Oct 2024 10:30:37 +0100 Subject: [PATCH 2/2] Image name should be smaller then 64 chars. Minimal has been deleted Signed-off-by: Petr "Stone" Hracek --- .../redhat/nodejs-application/src/templates/deployment.yaml | 6 +++--- tests/test_nodejs_application.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/charts/redhat/nodejs-application/src/templates/deployment.yaml b/charts/redhat/nodejs-application/src/templates/deployment.yaml index 188cb50..d7e50cb 100644 --- a/charts/redhat/nodejs-application/src/templates/deployment.yaml +++ b/charts/redhat/nodejs-application/src/templates/deployment.yaml @@ -34,10 +34,11 @@ spec: name: {{ .Values.name }} spec: containers: + - name: nodejs-example {{ if .Values.registry.enabled }} - - image: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest" + image: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest" {{ else }} - - image: " " + image: " " {{ end }} livenessProbe: httpGet: @@ -45,7 +46,6 @@ spec: port: 8080 initialDelaySeconds: 30 timeoutSeconds: 3 - name: nodejs-example ports: - containerPort: 8080 readinessProbe: diff --git a/tests/test_nodejs_application.py b/tests/test_nodejs_application.py index 6fe5122..ea59419 100644 --- a/tests/test_nodejs_application.py +++ b/tests/test_nodejs_application.py @@ -39,7 +39,7 @@ def test_curl_connection(self, version): assert self.hc_api.helm_installation() self.hc_api.package_name = "nodejs-application" assert self.hc_api.helm_package() - pod_name = f"nodejs-ex-{version}" + pod_name = f"nodejs-ex-{version}".replace("-minimal", "") assert self.hc_api.helm_installation( values={ "nodejs_version": version, @@ -72,7 +72,7 @@ def test_by_helm_test(self, version): assert self.hc_api.helm_installation() self.hc_api.package_name = "nodejs-application" assert self.hc_api.helm_package() - pod_name = f"nodejs-ex-{version}" + pod_name = f"nodejs-ex-{version}".replace("-minimal", "") assert self.hc_api.helm_installation( values={ "nodejs": version,