Skip to content

Commit

Permalink
Merge pull request #112 from sclorg/nodejs_shared_claster
Browse files Browse the repository at this point in the history
Enables testing NOdeJS Helm chart on shared cluster.
  • Loading branch information
phracek authored Nov 1, 2024
2 parents 68446fb + 1ec8479 commit 9c6df18
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 13 deletions.
4 changes: 2 additions & 2 deletions charts/redhat/nodejs-application/src/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions charts/redhat/nodejs-application/src/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
[
{
Expand All @@ -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
Expand All @@ -32,14 +34,18 @@ spec:
name: {{ .Values.name }}
spec:
containers:
- image: " "
- name: nodejs-example
{{ if .Values.registry.enabled }}
image: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest"
{{ else }}
image: " "
{{ end }}
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 30
timeoutSeconds: 3
name: nodejs-example
ports:
- containerPort: 8080
readinessProbe:
Expand Down
20 changes: 20 additions & 0 deletions charts/redhat/nodejs-application/src/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
}
}
5 changes: 5 additions & 0 deletions charts/redhat/nodejs-application/src/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
48 changes: 39 additions & 9 deletions tests/test_nodejs_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,67 @@ 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"
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}".replace("-minimal", "")
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}".replace("-minimal", "")
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"])

0 comments on commit 9c6df18

Please sign in to comment.