Skip to content

Commit

Permalink
Merge pull request #118 from gmfrasca/rm-secret-creation
Browse files Browse the repository at this point in the history
Remove External Connection Secrets from operator responsibilities
  • Loading branch information
openshift-merge-bot[bot] authored Nov 8, 2023
2 parents 6206cf2 + 4e4c3fa commit 40a8930
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 191 deletions.
6 changes: 6 additions & 0 deletions config/internal/apiserver/deployment.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ spec:
value: "ds-pipeline-visualizationserver"
- name: ML_PIPELINE_VISUALIZATIONSERVER_SERVICE_PORT
value: "8888"
- name: OBJECTSTORECONFIG_CREDENTIALSSECRET
value: "{{.ObjectStorageConnection.CredentialsSecret.SecretName}}"
- name: OBJECTSTORECONFIG_CREDENTIALSACCESSKEYKEY
value: "{{.ObjectStorageConnection.CredentialsSecret.AccessKey}}"
- name: OBJECTSTORECONFIG_CREDENTIALSSECRETKEYKEY
value: "{{.ObjectStorageConnection.CredentialsSecret.SecretKey}}"
- name: OBJECTSTORECONFIG_BUCKETNAME
value: "{{.ObjectStorageConnection.Bucket}}"
- name: OBJECTSTORECONFIG_ACCESSKEY
Expand Down
10 changes: 10 additions & 0 deletions config/internal/devtools/database.secret.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: "{{.DBConnection.CredentialsSecret.Name}}"
namespace: {{.Namespace}}
labels:
app: mariadb-{{.Name}}
component: data-science-pipelines
data:
password: {{.DBConnection.Password}}
15 changes: 15 additions & 0 deletions config/internal/devtools/storage.secret.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Secret
metadata:
name: "{{.ObjectStorageConnection.CredentialsSecret.SecretName}}"
namespace: {{.Namespace}}
labels:
app: minio-{{.Name}}
component: data-science-pipelines
stringData:
host: "{{.ObjectStorageConnection.Host}}"
port: "{{.ObjectStorageConnection.Port}}"
secure: "{{.ObjectStorageConnection.Secure}}"
data:
accesskey: "{{.ObjectStorageConnection.AccessKeyID}}"
secretkey: "{{.ObjectStorageConnection.SecretAccessKey}}"
2 changes: 1 addition & 1 deletion config/internal/mariadb/secret.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ metadata:
app: mariadb-{{.Name}}
component: data-science-pipelines
data:
password: {{.DBConnection.Password}}
{{.DBConnection.CredentialsSecret.Key}}: "{{.DBConnection.Password}}"
4 changes: 2 additions & 2 deletions config/internal/minio/secret.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ stringData:
port: "{{.ObjectStorageConnection.Port}}"
secure: "{{.ObjectStorageConnection.Secure}}"
data:
accesskey: "{{.ObjectStorageConnection.AccessKeyID}}"
secretkey: "{{.ObjectStorageConnection.SecretAccessKey}}"
{{.ObjectStorageConnection.CredentialsSecret.AccessKey}}: "{{.ObjectStorageConnection.AccessKeyID}}"
{{.ObjectStorageConnection.CredentialsSecret.SecretKey}}: "{{.ObjectStorageConnection.SecretAccessKey}}"
13 changes: 8 additions & 5 deletions controllers/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const (
ArtifactScriptConfigMapKey = "artifact_script"
DSPServicePrefix = "ds-pipeline"

DBSecretNamePrefix = "ds-pipeline-db-"
DBSecretKey = "password"
DefaultDBSecretNamePrefix = "ds-pipeline-db-"
DefaultDBSecretKey = "password"
GeneratedDBPasswordLength = 12

MariaDBName = "mlpipeline"
MariaDBHostPrefix = "mariadb"
Expand All @@ -47,9 +48,11 @@ const (
MinioDefaultBucket = "mlpipeline"
MinioPVCSize = "10Gi"

ObjectStorageSecretName = "mlpipeline-minio-artifact" // hardcoded in kfp-tekton
ObjectStorageAccessKey = "accesskey"
ObjectStorageSecretKey = "secretkey"
DefaultObjectStorageSecretNamePrefix = "ds-pipeline-s3-"
DefaultObjectStorageAccessKey = "accesskey"
DefaultObjectStorageSecretKey = "secretkey"
GeneratedObjectStorageAccessKeyLength = 16
GeneratedObjectStorageSecretKeyLength = 24

MlmdGrpcPort = "8080"
)
Expand Down
24 changes: 14 additions & 10 deletions controllers/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ 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"
)

const dbSecret = "mariadb/secret.yaml.tmpl"

var dbTemplates = []string{
var mariadbTemplates = []string{
"mariadb/deployment.yaml.tmpl",
"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,18 +100,22 @@ 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("Deploying external db secret.")
// If using external DB, we just need to create the secret
// for apiserver
err := r.Apply(dsp, params, dbSecret)
if err != nil {
return err
}
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 dbTemplates {
for _, template := range mariadbTemplates {
err := r.Apply(dsp, params, template)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 40a8930

Please sign in to comment.