Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated handling of dspa tls config #620

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading