Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
KEYCLOAK-14075 Downgrade to Postgresql 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Laskawiec authored and slaskawi committed May 11, 2020
1 parent ee06f11 commit 3ed671b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ All images used by the Operator might be controlled using dedicated Environmenta
| `RHSSO` for OpenJDK | `IMAGE_RHSSO_OPENJDK` | `registry.redhat.io/rh-sso-7/sso74-openshift-rhel8:7.4-1` |
| Init container | `IMAGE_KEYCLOAK_INIT_CONTAINER` | `quay.io/keycloak/keycloak-init-container:master` |
| Backup container | `IMAGE_RHMI_BACKUP_CONTAINER` | `quay.io/integreatly/backup-container:1.0.10` |
| Postgresql | `IMAGE_POSTGRESQL` | `postgres:11.5` |
| Postgresql | `IMAGE_POSTGRESQL` | `registry.redhat.io/rhel8/postgresql-10:1` |

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
// Required by the Integreately Backup Image
DatabaseSecretDatabaseProperty = "POSTGRES_DATABASE" // nolint
// Required by the Integreately Backup Image
DatabaseSecretSuperuserProperty = "POSTGRES_SUPERUSER" // nolint
DatabaseSecretVersionProperty = "POSTGRES_VERSION" // nolint
DatabaseSecretExternalAddressProperty = "POSTGRES_EXTERNAL_ADDRESS" // nolint
DatabaseSecretExternalPortProperty = "POSTGRES_EXTERNAL_PORT" // nolint
KeycloakServicePort = 8443
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/database_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func DatabaseSecret(cr *v1alpha1.Keycloak) *v1.Secret {
DatabaseSecretUsernameProperty: PostgresqlUsername,
DatabaseSecretPasswordProperty: cr.ObjectMeta.Name + "-" + GenerateRandomString(PostgresqlPasswordLength),
// The 3 entries below are not used by the Operator itself but rather by the Backup container
DatabaseSecretDatabaseProperty: PostgresqlDatabase,
DatabaseSecretSuperuserProperty: "true",
DatabaseSecretHostProperty: PostgresqlServiceName,
DatabaseSecretDatabaseProperty: PostgresqlDatabase,
DatabaseSecretHostProperty: PostgresqlServiceName,
DatabaseSecretVersionProperty: "10",
},
}
}
Expand All @@ -46,11 +46,11 @@ func DatabaseSecretReconciled(cr *v1alpha1.Keycloak, currentState *v1.Secret) *v
if _, ok := reconciled.Data[DatabaseSecretDatabaseProperty]; !ok {
reconciled.StringData[DatabaseSecretDatabaseProperty] = PostgresqlDatabase
}
if _, ok := reconciled.Data[DatabaseSecretSuperuserProperty]; !ok {
reconciled.StringData[DatabaseSecretSuperuserProperty] = "true"
}
if _, ok := reconciled.Data[DatabaseSecretHostProperty]; !ok {
reconciled.StringData[DatabaseSecretHostProperty] = PostgresqlServiceName
}
if _, ok := reconciled.Data[DatabaseSecretVersionProperty]; !ok {
reconciled.StringData[DatabaseSecretVersionProperty] = "10"
}
return reconciled
}
4 changes: 2 additions & 2 deletions pkg/model/image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const (
DefaultRHSSOImageOpenJ9 = "registry.redhat.io/rh-sso-7/sso74-openshift-rhel8:7.4-1"
DefaultRHSSOImageOpenJDK = "registry.redhat.io/rh-sso-7/sso74-openshift-rhel8:7.4-1"
DefaultKeycloakInitContainer = "quay.io/keycloak/keycloak-init-container:master"
DefaultRHMIBackupContainer = "quay.io/integreatly/backup-container:1.0.10"
DefaultPostgresqlImage = "postgres:11.5"
DefaultRHMIBackupContainer = "quay.io/integreatly/backup-container:1.0.14"
DefaultPostgresqlImage = "registry.access.redhat.com/rhscl/postgresql-10-rhel7:1"
)

var Images = NewImageManager()
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/postgresql_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func PostgresqlBackup(cr *v1alpha1.KeycloakBackup) *v13.Job {
Name: cr.Name,
Image: Images.Images[PostgresqlImage],
Command: []string{"/bin/sh", "-c"},
Args: []string{"pg_dumpall --clean --if-exists --oids | tee /backup/backup.sql"},
Args: []string{"pg_dump $POSTGRES_DB | tee /backup/backup.sql"},
Env: []v1.EnvVar{
{
Name: "POSTGRES_USER",
Expand Down Expand Up @@ -120,7 +120,7 @@ func PostgresqlBackupReconciled(cr *v1alpha1.KeycloakBackup, currentState *v13.J
Name: cr.Name,
Image: Images.Images[PostgresqlImage],
Command: []string{"/bin/sh", "-c"},
Args: []string{"pg_dumpall --clean --if-exists --oids | tee /backup/backup.sql"},
Args: []string{"pg_dump $POSTGRES_DB | tee /backup/backup.sql"},
Env: []v1.EnvVar{
{
Name: "POSTGRES_USER",
Expand Down
50 changes: 9 additions & 41 deletions pkg/model/postgresql_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func PostgresqlDeployment(cr *v1alpha1.Keycloak) *v13.Deployment {
Command: []string{
"/bin/sh",
"-c",
"psql -h 127.0.0.1 -U $POSTGRES_USER -q -d $POSTGRES_DB -c 'SELECT 1'",
"psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'",
},
},
},
Expand All @@ -70,7 +70,7 @@ func PostgresqlDeployment(cr *v1alpha1.Keycloak) *v13.Deployment {
},
Env: []v1.EnvVar{
{
Name: "POSTGRES_USER",
Name: "POSTGRESQL_USER",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Expand All @@ -81,18 +81,7 @@ func PostgresqlDeployment(cr *v1alpha1.Keycloak) *v13.Deployment {
},
},
{
Name: "PGUSER",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: DatabaseSecretName,
},
Key: DatabaseSecretUsernameProperty,
},
},
},
{
Name: "POSTGRES_PASSWORD",
Name: "POSTGRESQL_PASSWORD",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Expand All @@ -103,19 +92,14 @@ func PostgresqlDeployment(cr *v1alpha1.Keycloak) *v13.Deployment {
},
},
{
Name: "POSTGRES_DB",
Name: "POSTGRESQL_DATABASE",
Value: PostgresqlDatabase,
},
{
// Due to permissions issue, we need to create a subdirectory in the PVC
Name: "PGDATA",
Value: "/var/lib/postgresql/data/pgdata",
},
},
VolumeMounts: []v1.VolumeMount{
{
Name: PostgresqlPersistentVolumeName,
MountPath: "/var/lib/postgresql/data",
MountPath: "/var/lib/pgsql/data",
},
},
},
Expand Down Expand Up @@ -170,7 +154,7 @@ func PostgresqlDeploymentReconciled(cr *v1alpha1.Keycloak, currentState *v13.Dep
Command: []string{
"/bin/sh",
"-c",
"psql -h 127.0.0.1 -U $POSTGRES_USER -q -d $POSTGRES_DB -c 'SELECT 1'",
"psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'",
},
},
},
Expand All @@ -186,7 +170,7 @@ func PostgresqlDeploymentReconciled(cr *v1alpha1.Keycloak, currentState *v13.Dep
},
Env: []v1.EnvVar{
{
Name: "POSTGRES_USER",
Name: "POSTGRESQL_USER",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Expand All @@ -197,18 +181,7 @@ func PostgresqlDeploymentReconciled(cr *v1alpha1.Keycloak, currentState *v13.Dep
},
},
{
Name: "PGUSER",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: DatabaseSecretName,
},
Key: DatabaseSecretUsernameProperty,
},
},
},
{
Name: "POSTGRES_PASSWORD",
Name: "POSTGRESQL_PASSWORD",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Expand All @@ -219,14 +192,9 @@ func PostgresqlDeploymentReconciled(cr *v1alpha1.Keycloak, currentState *v13.Dep
},
},
{
Name: "POSTGRES_DB",
Name: "POSTGRESQL_DATABASE",
Value: PostgresqlDatabase,
},
{
// Due to permissions issue, we need to create a subdirectory in the PVC
Name: "PGDATA",
Value: "/var/lib/postgresql/data/pgdata",
},
},
VolumeMounts: []v1.VolumeMount{
{
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/keycloak_main_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package e2e

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/keycloak/keycloak-operator/pkg/apis"
keycloakv1alpha1 "github.com/keycloak/keycloak-operator/pkg/apis/keycloak/v1alpha1"
framework "github.com/operator-framework/operator-sdk/pkg/test"
Expand Down

0 comments on commit 3ed671b

Please sign in to comment.