Skip to content

Commit

Permalink
Only use managed DB/Storage Secret if not specified in DSPA
Browse files Browse the repository at this point in the history
  • Loading branch information
gmfrasca committed Nov 7, 2023
1 parent be46a1b commit c8835b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion controllers/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"database/sql"
b64 "encoding/base64"
"fmt"

_ "github.com/go-sql-driver/mysql"
dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1"
"github.com/opendatahub-io/data-science-pipelines-operator/controllers/config"
Expand All @@ -32,7 +33,6 @@ var mariadbTemplates = []string{
"mariadb/pvc.yaml.tmpl",
"mariadb/service.yaml.tmpl",
"mariadb/mariadb-sa.yaml.tmpl",
dbSecret,
}

// extract to var for mocking in testing
Expand Down Expand Up @@ -100,10 +100,20 @@ func (r *DSPAReconciler) ReconcileDatabase(ctx context.Context, dsp *dspav1alpha
// Default DB is currently MariaDB as well, but storing these bools seperately in case that changes
deployDefaultDB := !databaseSpecified || defaultDBRequired

externalDBCredentialsProvided := externalDBSpecified && (dsp.Spec.Database.ExternalDB.PasswordSecret != nil)
mariaDBCredentialsProvided := mariaDBSpecified && (dsp.Spec.Database.MariaDB.PasswordSecret != nil)
databaseCredentialsProvided := externalDBCredentialsProvided || mariaDBCredentialsProvided

// If external db is specified, it takes precedence
if externalDBSpecified {
log.Info("Using externalDB, bypassing database deployment.")
} else if deployMariaDB || deployDefaultDB {
if !databaseCredentialsProvided {
err := r.Apply(dsp, params, dbSecret)
if err != nil {
return err
}
}
log.Info("Applying mariaDB resources.")
for _, template := range mariadbTemplates {
err := r.Apply(dsp, params, template)
Expand Down
14 changes: 13 additions & 1 deletion controllers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"encoding/base64"
"errors"
"fmt"
"net/http"

Check failure on line 25 in controllers/storage.go

View workflow job for this annotation

GitHub Actions / functest

other declaration of http

Check failure on line 25 in controllers/storage.go

View workflow job for this annotation

GitHub Actions / unittest

other declaration of http

"github.com/go-logr/logr"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
Expand All @@ -38,7 +40,6 @@ var minioTemplates = []string{
"minio/pvc.yaml.tmpl",
"minio/service.yaml.tmpl",
"minio/minio-sa.yaml.tmpl",
storageSecret,
}

func joinHostPort(host, port string) (string, error) {
Expand Down Expand Up @@ -195,10 +196,21 @@ func (r *DSPAReconciler) ReconcileStorage(ctx context.Context, dsp *dspav1alpha1
minioSpecified := !storageSpecified || dsp.Spec.ObjectStorage.Minio != nil
deployMinio := !storageSpecified || (minioSpecified && dsp.Spec.ObjectStorage.Minio.Deploy)

externalStorageCredentialsProvided := externalStorageSpecified && (dsp.Spec.ObjectStorage.ExternalStorage.S3CredentialSecret != nil)
minioCredentialsProvided := minioSpecified && (dsp.Spec.ObjectStorage.Minio.S3CredentialSecret != nil)
storageCredentialsProvided := externalStorageCredentialsProvided || minioCredentialsProvided

// If external storage is specified, it takes precedence
if externalStorageSpecified {
log.Info("Using externalStorage, bypassing object storage deployment.")
} else if deployMinio {
log.Info("No S3 storage credential reference provided, so using managed secret")
if !storageCredentialsProvided {
err := r.Apply(dsp, params, storageSecret)
if err != nil {
return err
}
}
log.Info("Applying object storage resources.")
for _, template := range minioTemplates {
err := r.Apply(dsp, params, template)
Expand Down

0 comments on commit c8835b8

Please sign in to comment.