From 7b41af0b245d3e272aff7ee14dc6e2edcaa233a4 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 29 Oct 2024 12:24:00 +0100 Subject: [PATCH] Add support testing Ruby Helm Charts on Shared Cluster. Everything is driven by 'registry.enabled' variable in 'values.yaml' file. Signed-off-by: Petr "Stone" Hracek --- .../ruby-rails-application/src/Chart.yaml | 4 ++-- .../src/templates/buildconfig.yaml | 9 +++++++++ .../src/templates/deployment.yaml | 8 +++++++- .../src/values.schema.json | 20 +++++++++++++++++++ .../ruby-rails-application/src/values.yaml | 5 +++++ tests/test_ruby_rails_application.py | 14 ++++++++----- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/charts/redhat/ruby-rails-application/src/Chart.yaml b/charts/redhat/ruby-rails-application/src/Chart.yaml index 2ad423c..48d813e 100644 --- a/charts/redhat/ruby-rails-application/src/Chart.yaml +++ b/charts/redhat/ruby-rails-application/src/Chart.yaml @@ -2,13 +2,13 @@ description: This content is experimental, do not use it in production. An examp using this template, including OpenShift considerations, see https://github.com/sclorg/rails-ex/blob/master/README.md. name: ruby-rails-application tags: quickstart,ruby,rails -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/ruby-rails-application/src/templates/buildconfig.yaml b/charts/redhat/ruby-rails-application/src/templates/buildconfig.yaml index fb610e5..e5d1067 100644 --- a/charts/redhat/ruby-rails-application/src/templates/buildconfig.yaml +++ b/charts/redhat/ruby-rails-application/src/templates/buildconfig.yaml @@ -9,10 +9,19 @@ metadata: template: rails-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/ruby-rails-application/src/templates/deployment.yaml b/charts/redhat/ruby-rails-application/src/templates/deployment.yaml index a78ee89..e141ad5 100644 --- a/charts/redhat/ruby-rails-application/src/templates/deployment.yaml +++ b/charts/redhat/ruby-rails-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: rails-example @@ -35,7 +37,11 @@ spec: - env: - name: RAILS_ENV value: {{ .Values.rails_env }} - image: "{{ .Values.name }}:latest" + {{ 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/ruby-rails-application/src/values.schema.json b/charts/redhat/ruby-rails-application/src/values.schema.json index d67cc18..c3f40de 100644 --- a/charts/redhat/ruby-rails-application/src/values.schema.json +++ b/charts/redhat/ruby-rails-application/src/values.schema.json @@ -53,6 +53,26 @@ "rubygem_mirror": { "type": "string", "description": "The custom RubyGems 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/ruby-rails-application/src/values.yaml b/charts/redhat/ruby-rails-application/src/values.yaml index 898838d..e8459ff 100644 --- a/charts/redhat/ruby-rails-application/src/values.yaml +++ b/charts/redhat/ruby-rails-application/src/values.yaml @@ -10,3 +10,8 @@ rubygem_mirror: "" # TODO: must define a default value for .rubygem_mirror secret_key_base: "" # TODO: must define a default value for .secret_key_base source_repository_ref: "master" # TODO: must define a default value for .source_repository_ref source_repository_url: https://github.com/sclorg/rails-ex.git +registry: + enabled: false + name: "quay.io" + namespace: "something" + push_secret: "" diff --git a/tests/test_ruby_rails_application.py b/tests/test_ruby_rails_application.py index 7f2ebd1..b71700a 100644 --- a/tests/test_ruby_rails_application.py +++ b/tests/test_ruby_rails_application.py @@ -37,16 +37,18 @@ def test_curl_connection(self, version, branch): assert self.hc_api.helm_installation() self.hc_api.package_name = "ruby-rails-application" assert self.hc_api.helm_package() + pod_name = f"rails-ex-{version}".replace(".", "-") assert self.hc_api.helm_installation( values={ "ruby_version": f"{version}", "source_repository_ref": f"{branch}", - "namespace": self.hc_api.namespace + "namespace": self.hc_api.namespace, + "name": pod_name } ) - assert self.hc_api.is_s2i_pod_running(pod_name_prefix="rails-example", timeout=300) + assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name, timeout=600) assert self.hc_api.test_helm_curl_output( - route_name="rails-example", + route_name=pod_name, expected_str="Welcome to your Rails application" ) @@ -67,12 +69,14 @@ def test_by_helm_test(self, version, branch): assert self.hc_api.helm_installation() self.hc_api.package_name = "ruby-rails-application" assert self.hc_api.helm_package() + pod_name = f"rails-ex-{version}".replace(".", "-") assert self.hc_api.helm_installation( values={ "ruby_version": f"{version}", "source_repository_ref": f"{branch}", - "namespace": self.hc_api.namespace + "namespace": self.hc_api.namespace, + "name": pod_name } ) - assert self.hc_api.is_s2i_pod_running(pod_name_prefix="rails-example", timeout=300) + assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name, timeout=600) assert self.hc_api.test_helm_chart(expected_str=["Welcome to your Rails application"])