From bce7138ac45221b8ec2d9d702751985c70a004ee Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Fri, 20 Sep 2024 16:24:31 +0200 Subject: [PATCH 1/2] Fix the openshift templates * Specify that the postgresql images should be taken from openshift * Use an init container in the rails-postgresql template to init the database --- .../rails-postgresql-persistent.json | 2 +- openshift/templates/rails-postgresql.json | 84 ++++++++++++++++++- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/openshift/templates/rails-postgresql-persistent.json b/openshift/templates/rails-postgresql-persistent.json index 10ccca8e..04993563 100644 --- a/openshift/templates/rails-postgresql-persistent.json +++ b/openshift/templates/rails-postgresql-persistent.json @@ -408,7 +408,7 @@ "annotations": { "description": "Defines how to deploy the database", "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\", \"namespace\": \"openshift\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { diff --git a/openshift/templates/rails-postgresql.json b/openshift/templates/rails-postgresql.json index ce79fe0b..4d93f9c2 100644 --- a/openshift/templates/rails-postgresql.json +++ b/openshift/templates/rails-postgresql.json @@ -147,7 +147,7 @@ "annotations": { "description": "Defines how to deploy the application server", "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"},{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.initContainers[0].image\"}]" } }, "spec": { @@ -179,6 +179,86 @@ } }, "spec": { + "initContainers": [ + { + "name": "ruby-init-container", + "image": " ", + "command": [ + "./migrate-database.sh" + ], + "env": [ + { + "name": "DATABASE_SERVICE_NAME", + "value": "${DATABASE_SERVICE_NAME}" + }, + { + "name": "POSTGRESQL_USER", + "valueFrom": { + "secretKeyRef": { + "name": "${NAME}", + "key": "database-user" + } + } + }, + { + "name": "POSTGRESQL_PASSWORD", + "valueFrom": { + "secretKeyRef": { + "name": "${NAME}", + "key": "database-password" + } + } + }, + { + "name": "SECRET_KEY_BASE", + "valueFrom": { + "secretKeyRef": { + "name": "${NAME}", + "key": "keybase" + } + } + }, + { + "name": "POSTGRESQL_DATABASE", + "value": "${DATABASE_NAME}" + }, + { + "name": "POSTGRESQL_MAX_CONNECTIONS", + "value": "${POSTGRESQL_MAX_CONNECTIONS}" + }, + { + "name": "POSTGRESQL_SHARED_BUFFERS", + "value": "${POSTGRESQL_SHARED_BUFFERS}" + }, + { + "name": "APPLICATION_DOMAIN", + "value": "${APPLICATION_DOMAIN}" + }, + { + "name": "APPLICATION_USER", + "valueFrom": { + "secretKeyRef": { + "name": "${NAME}", + "key": "application-user" + } + } + }, + { + "name": "APPLICATION_PASSWORD", + "valueFrom": { + "secretKeyRef": { + "name": "${NAME}", + "key": "application-password" + } + } + }, + { + "name": "RAILS_ENV", + "value": "${RAILS_ENV}" + } + ] + } + ], "containers": [ { "name": "${NAME}", @@ -316,7 +396,7 @@ "annotations": { "description": "Defines how to deploy the database", "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:12-el8\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:12-el8\", \"namespace\": \"openshift\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { From 6c29e30342addb7e0daf3e398e7f576282c313e9 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 24 Sep 2024 13:51:43 +0200 Subject: [PATCH 2/2] Use the NAMESPACE and POSTGRESQL_VERSION for finding the postgresql image and remove the recreteParams that were not exactly working well. The intended function is done by the initContainer. --- .../rails-postgresql-persistent.json | 2 +- openshift/templates/rails-postgresql.json | 22 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/openshift/templates/rails-postgresql-persistent.json b/openshift/templates/rails-postgresql-persistent.json index 04993563..23d03391 100644 --- a/openshift/templates/rails-postgresql-persistent.json +++ b/openshift/templates/rails-postgresql-persistent.json @@ -408,7 +408,7 @@ "annotations": { "description": "Defines how to deploy the database", "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\", \"namespace\": \"openshift\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\", \"namespace\": \"${NAMESPACE}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { diff --git a/openshift/templates/rails-postgresql.json b/openshift/templates/rails-postgresql.json index 4d93f9c2..9697c587 100644 --- a/openshift/templates/rails-postgresql.json +++ b/openshift/templates/rails-postgresql.json @@ -152,18 +152,7 @@ }, "spec": { "strategy": { - "type": "Recreate", - "recreateParams": { - "pre": { - "failurePolicy": "Abort", - "execNewPod": { - "command": [ - "./migrate-database.sh" - ], - "containerName": "${NAME}" - } - } - } + "type": "Recreate" }, "replicas": 1, "selector": { @@ -396,7 +385,7 @@ "annotations": { "description": "Defines how to deploy the database", "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:12-el8\", \"namespace\": \"openshift\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\", \"namespace\": \"${NAMESPACE}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { @@ -518,6 +507,13 @@ "required": true, "value": "3.1-ubi8" }, + { + "name": "POSTGRESQL_VERSION", + "displayName": "Postgresql Version", + "description": "Version of Postgresql image to be used (12-el8 by default).", + "required": true, + "value": "12-el8" + }, { "name": "MEMORY_LIMIT", "displayName": "Memory Limit",