From 9e74e73911cc6ee44b558c96190356104ec47d4b Mon Sep 17 00:00:00 2001 From: Nick Beenham <1985327+superbeeny@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:46:22 -0500 Subject: [PATCH] Adding Postgres Helm chart to rad init (#8072) # Description Adding Postgres installation to the Radius Helm chart ## Type of change - This pull request adds or changes features of Radius and has an approved issue (issue link required). Fixes: #8071 Updated issue: https://github.com/radius-project/radius/issues/8096 --------- Signed-off-by: Nick Beenham --- .../Chart/templates/database/configmaps.yaml | 13 ++ deploy/Chart/templates/database/service.yaml | 16 +++ .../templates/database/serviceaccount.yaml | 8 ++ .../Chart/templates/database/statefulset.yaml | 52 ++++++++ deploy/Chart/values.yaml | 14 +++ .../noncloud/resources/sql_test.go | 118 ------------------ .../datastoresrp-resources-sqldb-manual.bicep | 104 --------------- .../datastoresrp-resources-sqldb-recipe.bicep | 94 -------------- 8 files changed, 103 insertions(+), 316 deletions(-) create mode 100644 deploy/Chart/templates/database/configmaps.yaml create mode 100644 deploy/Chart/templates/database/service.yaml create mode 100644 deploy/Chart/templates/database/serviceaccount.yaml create mode 100644 deploy/Chart/templates/database/statefulset.yaml delete mode 100644 test/functional-portable/datastoresrp/noncloud/resources/sql_test.go delete mode 100644 test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-manual.bicep delete mode 100644 test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-recipe.bicep diff --git a/deploy/Chart/templates/database/configmaps.yaml b/deploy/Chart/templates/database/configmaps.yaml new file mode 100644 index 0000000000..6c902390ff --- /dev/null +++ b/deploy/Chart/templates/database/configmaps.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: database-secret + namespace: "{{ .Release.Namespace }}" + labels: + control-plane: database + app.kubernetes.io/name: database + app.kubernetes.io/part-of: radius +data: + POSTGRES_DB: ps_db + POSTGRES_USER: ps_user + POSTGRES_PASSWORD: SecurePassword \ No newline at end of file diff --git a/deploy/Chart/templates/database/service.yaml b/deploy/Chart/templates/database/service.yaml new file mode 100644 index 0000000000..c10a9818fd --- /dev/null +++ b/deploy/Chart/templates/database/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: database + namespace: "{{ .Release.Namespace }}" + labels: + app.kubernetes.io/name: database + app.kubernetes.io/part-of: radius +spec: + ports: + - port: 5432 + name: postgres + protocol: TCP + targetPort: 5432 + selector: + app.kubernetes.io/name: database \ No newline at end of file diff --git a/deploy/Chart/templates/database/serviceaccount.yaml b/deploy/Chart/templates/database/serviceaccount.yaml new file mode 100644 index 0000000000..617e26e0eb --- /dev/null +++ b/deploy/Chart/templates/database/serviceaccount.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: database + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: database + app.kubernetes.io/part-of: radius diff --git a/deploy/Chart/templates/database/statefulset.yaml b/deploy/Chart/templates/database/statefulset.yaml new file mode 100644 index 0000000000..33d32f2be6 --- /dev/null +++ b/deploy/Chart/templates/database/statefulset.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: database + namespace: "{{ .Release.Namespace }}" + labels: + control-plane: database + app.kubernetes.io/name: database + app.kubernetes.io/part-of: radius +spec: + serviceName: "database" + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: database + template: + metadata: + labels: + control-plane: database + app.kubernetes.io/name: database + app.kubernetes.io/part-of: radius + spec: + serviceAccountName: database + containers: + - name: database + securityContext: + allowPrivilegeEscalation: false + image: "{{ .Values.database.image }}:{{ .Values.database.tag }}" + imagePullPolicy: IfNotPresent + resources: + requests: + memory: "{{ .Values.database.resources.requests.memory }}" + cpu: "{{ .Values.database.resources.requests.cpu }}" + limits: + memory: "{{ .Values.database.resources.limits.memory }}" + cpu: "{{ .Values.database.resources.limits.cpu }}" + envFrom: + - configMapRef: + name: database-secret + ports: + - containerPort: 5432 + name: postgres + + volumeClaimTemplates: + - metadata: + name: database + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "{{ .Values.database.storageClassName }}" + resources: + requests: + storage: {{ .Values.database.storageSize }} \ No newline at end of file diff --git a/deploy/Chart/values.yaml b/deploy/Chart/values.yaml index d750295570..d22d987f26 100644 --- a/deploy/Chart/values.yaml +++ b/deploy/Chart/values.yaml @@ -112,3 +112,17 @@ dashboard: memory: "60Mi" limits: memory: "300Mi" + +database: + image: ghcr.io/radius-project/mirror/postgres + tag: latest + storageClassName: "standard" # set to the storage class name if required + # Minimum resource requirements, may need to revisit and scale. + storageSize: "1Gi" + resources: + requests: + cpu: "2" + memory: "512Mi" + limits: + cpu: "2" + memory: "1024Mi" \ No newline at end of file diff --git a/test/functional-portable/datastoresrp/noncloud/resources/sql_test.go b/test/functional-portable/datastoresrp/noncloud/resources/sql_test.go deleted file mode 100644 index f1f265114f..0000000000 --- a/test/functional-portable/datastoresrp/noncloud/resources/sql_test.go +++ /dev/null @@ -1,118 +0,0 @@ -/* -Copyright 2023 The Radius Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package resource_test - -import ( - "runtime" - "testing" - - "github.com/radius-project/radius/test/rp" - "github.com/radius-project/radius/test/step" - "github.com/radius-project/radius/test/testutil" - "github.com/radius-project/radius/test/validation" -) - -func Test_SQLDatabase_Manual(t *testing.T) { - // https://github.com/microsoft/mssql-docker/issues/668 - if runtime.GOARCH == "arm64" { - t.Skip("skipping Test_SQL, unsupported architecture") - } - template := "testdata/datastoresrp-resources-sqldb-manual.bicep" - name := "dsrp-resources-sql" - appNamespace := "default-dsrp-resources-sql" - - test := rp.NewRPTest(t, name, []rp.TestStep{ - { - Executor: step.NewDeployExecutor(template, testutil.GetMagpieImage()), - RPResources: &validation.RPResourceSet{ - Resources: []validation.RPResource{ - { - Name: name, - Type: validation.ApplicationsResource, - }, - { - Name: "sql-app-ctnr", - Type: validation.ContainersResource, - App: name, - }, - { - Name: "sql-db", - Type: validation.SQLDatabasesResource, - App: name, - }, - { - Name: "sql-ctnr", - Type: validation.ContainersResource, - App: name, - }, - }, - }, - K8sObjects: &validation.K8sObjectSet{ - Namespaces: map[string][]validation.K8sObject{ - appNamespace: { - validation.NewK8sPodForResource(name, "sql-app-ctnr"), - validation.NewK8sPodForResource(name, "sql-ctnr"), - }, - }, - }, - }, - }) - - test.Test(t) -} - -// Test_SQLDatabase_Recipe validates: -// the creation of a sql database from recipe -// container using the sqlDatabases portable resource to connect to the sql database resource -func Test_SQLDatabase_Recipe(t *testing.T) { - template := "testdata/datastoresrp-resources-sqldb-recipe.bicep" - name := "dsrp-resources-sqldb-recipe" - appNamespace := "dsrp-resources-sqldb-recipe-app" - test := rp.NewRPTest(t, name, []rp.TestStep{ - { - Executor: step.NewDeployExecutor(template, testutil.GetMagpieImage(), testutil.GetBicepRecipeRegistry(), testutil.GetBicepRecipeVersion()), - RPResources: &validation.RPResourceSet{ - Resources: []validation.RPResource{ - { - Name: "dsrp-resources-env-sql-recipe-env", - Type: validation.EnvironmentsResource, - }, - { - Name: "dsrp-resources-sqldb-recipe", - Type: validation.ApplicationsResource, - App: name, - }, - { - Name: "sql-recipe-app-ctnr", - Type: validation.ContainersResource, - App: name, - }, - }, - }, - K8sObjects: &validation.K8sObjectSet{ - Namespaces: map[string][]validation.K8sObject{ - appNamespace: { - validation.NewK8sPodForResource(name, "sql-recipe-app-ctnr").ValidateLabels(false), - validation.NewK8sPodForResource(name, "sql-recipe-resource").ValidateLabels(false), - }, - }, - }, - }, - }) - - test.Test(t) -} diff --git a/test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-manual.bicep b/test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-manual.bicep deleted file mode 100644 index 1439c50243..0000000000 --- a/test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-manual.bicep +++ /dev/null @@ -1,104 +0,0 @@ -extension radius - -@description('Specifies the location for resources.') -param location string = 'global' - -@description('Specifies the image for the container resource.') -param magpieImage string - -@description('Specifies the port for the container resource.') -param magpiePort int = 3000 - -@description('Specifies the environment for resources.') -param environment string = 'test' - -@description('Specifies the image for the sql container resource.') -param sqlImage string = 'mcr.microsoft.com/mssql/server:2019-latest' - -@description('Specifies the port for the container resource.') -param sqlPort int = 1433 - -@description('Specifies the SQL username.') -param username string = 'sa' - -@description('Specifies the SQL password.') -@secure() -param password string = newGuid() - -resource app 'Applications.Core/applications@2023-10-01-preview' = { - name: 'dsrp-resources-sql' - location: location - properties: { - environment: environment - } -} - -resource webapp 'Applications.Core/containers@2023-10-01-preview' = { - name: 'sql-app-ctnr' - location: location - properties: { - application: app.id - connections: { - sql: { - source: db.id - } - } - container: { - image: magpieImage - env: { - CONNECTION_SQL_CONNECTIONSTRING: { - value: db.listSecrets().connectionString - } - } - readinessProbe: { - kind: 'httpGet' - containerPort: magpiePort - path: '/healthz' - } - } - } -} - -resource db 'Applications.Datastores/sqlDatabases@2023-10-01-preview' = { - name: 'sql-db' - location: location - properties: { - application: app.id - environment: environment - server: 'sql-ctnr' - database: 'master' - resourceProvisioning: 'manual' - port: sqlPort - username: username - secrets: { - password: password - } - } -} - -resource sqlContainer 'Applications.Core/containers@2023-10-01-preview' = { - name: 'sql-ctnr' - location: location - properties: { - application: app.id - container: { - image: sqlImage - env: { - ACCEPT_EULA: { - value: 'Y' - } - MSSQL_PID: { - value: 'Developer' - } - MSSQL_SA_PASSWORD: { - value: password - } - } - ports: { - sql: { - containerPort: sqlPort - } - } - } - } -} diff --git a/test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-recipe.bicep b/test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-recipe.bicep deleted file mode 100644 index dbd75d2e1b..0000000000 --- a/test/functional-portable/datastoresrp/noncloud/resources/testdata/datastoresrp-resources-sqldb-recipe.bicep +++ /dev/null @@ -1,94 +0,0 @@ -extension radius - -@description('Specifies the location for resources.') -param location string = 'global' - -@description('Specifies the image for the container resource.') -param magpieImage string - -@description('Specifies the port for the container resource.') -param magpiePort int = 3000 - -@description('Specifies the SQL username.') -param username string = 'sa' - -@description('Specifies the SQL password.') -@secure() -param password string = newGuid() - -param registry string - -param version string - -resource env 'Applications.Core/environments@2023-10-01-preview' = { - name: 'dsrp-resources-env-sql-recipe-env' - location: 'global' - properties: { - compute: { - kind: 'kubernetes' - resourceId: 'self' - namespace: 'dsrp-resources-env-sql-recipe-env' - } - recipes: { - 'Applications.Datastores/sqlDatabases': { - default: { - templateKind: 'bicep' - templatePath: '${registry}/test/testrecipes/test-bicep-recipes/sqldb-recipe:${version}' - parameters: { - username: username - password: password - } - } - } - } - } -} - -resource app 'Applications.Core/applications@2023-10-01-preview' = { - name: 'dsrp-resources-sqldb-recipe' - location: location - properties: { - environment: env.id - extensions: [ - { - kind: 'kubernetesNamespace' - namespace: 'dsrp-resources-sqldb-recipe-app' - } - ] - } -} - -resource webapp 'Applications.Core/containers@2023-10-01-preview' = { - name: 'sql-recipe-app-ctnr' - location: location - properties: { - application: app.id - connections: { - sql: { - source: db.id - } - } - container: { - image: magpieImage - env: { - CONNECTION_SQL_CONNECTIONSTRING: { - value: db.listSecrets().connectionString - } - } - readinessProbe: { - kind: 'httpGet' - containerPort: magpiePort - path: '/healthz' - } - } - } -} - -resource db 'Applications.Datastores/sqlDatabases@2023-10-01-preview' = { - name: 'sql-db-recipe' - location: location - properties: { - application: app.id - environment: env.id - } -}