Skip to content

Commit

Permalink
Merge pull request #620 from VaniHaripriya/RHOAIENG-4384-New
Browse files Browse the repository at this point in the history
Updated handling of dspa tls config
  • Loading branch information
HumairAK authored Apr 15, 2024
2 parents d4d9cd6 + 2fbdbf1 commit d5deacd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 13 additions & 1 deletion controllers/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ limitations under the License.
package config

import (
"encoding/json"
"fmt"
"time"

"github.com/go-logr/logr"
dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1"
"github.com/spf13/viper"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -53,7 +55,6 @@ const (

DefaultDBSecretNamePrefix = "ds-pipeline-db-"
DefaultDBSecretKey = "password"
DBDefaultExtraParams = "{\"tls\":\"%t\"}"
GeneratedDBPasswordLength = 12

MariaDBName = "mlpipeline"
Expand Down Expand Up @@ -188,6 +189,8 @@ var (
MlmdWriterResourceRequirements = createResourceRequirement(resource.MustParse("100m"), resource.MustParse("256Mi"), resource.MustParse("100m"), resource.MustParse("256Mi"))
)

type DBExtraParams map[string]string

func createResourceRequirement(RequestsCPU resource.Quantity, RequestsMemory resource.Quantity, LimitsCPU resource.Quantity, LimitsMemory resource.Quantity) dspav1alpha1.ResourceRequirements {
return dspav1alpha1.ResourceRequirements{
Requests: &dspav1alpha1.Resources{
Expand Down Expand Up @@ -223,3 +226,12 @@ func GetDurationConfigWithDefault(configName string, value time.Duration) time.D
func GetCABundleFileMountPath() string {
return fmt.Sprintf("%s/%s", CustomCABundleRootMountPath, CustomDSPTrustedCAConfigMapKey)
}

func GetDefaultDBExtraParams(params DBExtraParams, log logr.Logger) (string, error) {
extraParamsJson, err := json.Marshal(params)
if err != nil {
log.Info(fmt.Sprintf("Error marshaling TLS configuration to JSON: %v", err))
return "", err
}
return string(extraParamsJson), nil
}
23 changes: 19 additions & 4 deletions controllers/dspipeline_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"math/rand"
"strings"
"time"

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

"github.com/go-logr/logr"
mf "github.com/manifestival/manifestival"
Expand Down Expand Up @@ -89,7 +89,6 @@ type DBConnection struct {
Password string
ExtraParams string
}

type ObjectStorageConnection struct {
Bucket string
CredentialsSecret *dspa.S3CredentialSecret
Expand Down Expand Up @@ -260,7 +259,15 @@ func (p *DSPAParams) SetupDBParams(ctx context.Context, dsp *dspa.DataSciencePip

// Assume default external connection is tls enabled
// user can override this via CustomExtraParams field
p.DBConnection.ExtraParams = fmt.Sprintf(config.DBDefaultExtraParams, true)
tlsParams := config.DBExtraParams{
"tls": "true",
}
dbExtraParams, err := config.GetDefaultDBExtraParams(tlsParams, log)
if err != nil {
log.Error(err, "Unexpected error encountered while retrieving DBExtraparams")
return err
}
p.DBConnection.ExtraParams = dbExtraParams

// Retreive DB Password from specified secret. Ignore error if the secret simply doesn't exist (will be created later)
password, err := p.RetrieveSecret(ctx, client, p.DBConnection.CredentialsSecret.Name, p.DBConnection.CredentialsSecret.Key, log)
Expand Down Expand Up @@ -301,7 +308,15 @@ func (p *DSPAParams) SetupDBParams(ctx context.Context, dsp *dspa.DataSciencePip
p.DBConnection.Username = p.MariaDB.Username
p.DBConnection.DBName = p.MariaDB.DBName
// By Default OOB mariadb is not tls enabled
p.DBConnection.ExtraParams = fmt.Sprintf(config.DBDefaultExtraParams, false)
tlsParams := config.DBExtraParams{
"tls": "false",
}
dbExtraParams, err := config.GetDefaultDBExtraParams(tlsParams, log)
if err != nil {
log.Error(err, "Unexpected error encountered while retrieving DBExtraparams")
return err
}
p.DBConnection.ExtraParams = dbExtraParams

// If custom DB Secret provided, use its values. Otherwise generate a default
if p.MariaDB.PasswordSecret != nil {
Expand Down

0 comments on commit d5deacd

Please sign in to comment.