From f1ca05c23143065f4efb8f306c1bb1a7f7735a9a Mon Sep 17 00:00:00 2001 From: Achyut Madhusudan Date: Tue, 4 Jul 2023 23:03:54 +0530 Subject: [PATCH] Infer secure based on the scheme provided. Signed-off-by: Achyut Madhusudan --- api/v1alpha1/dspipeline_types.go | 3 +-- ...ub.io_datasciencepipelinesapplications.yaml | 1 - controllers/dspipeline_params.go | 18 ++++++++++++++++-- controllers/util/util.go | 4 ++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/api/v1alpha1/dspipeline_types.go b/api/v1alpha1/dspipeline_types.go index 4bdfde796..44578faa7 100644 --- a/api/v1alpha1/dspipeline_types.go +++ b/api/v1alpha1/dspipeline_types.go @@ -215,9 +215,8 @@ type ExternalStorage struct { Bucket string `json:"bucket"` Scheme string `json:"scheme"` *S3CredentialSecret `json:"s3CredentialsSecret"` - // +kubebuilder:default:=true // +kubebuilder:validation:Optional - Secure bool `json:"secure"` + Secure *bool `json:"secure"` // +kubebuilder:validation:Optional Port string `json:"port"` } diff --git a/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml b/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml index b8d4db52f..33e312e40 100644 --- a/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml +++ b/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml @@ -457,7 +457,6 @@ spec: scheme: type: string secure: - default: true type: boolean required: - bucket diff --git a/controllers/dspipeline_params.go b/controllers/dspipeline_params.go index bac9946b3..e81373647 100644 --- a/controllers/dspipeline_params.go +++ b/controllers/dspipeline_params.go @@ -27,6 +27,7 @@ import ( mf "github.com/manifestival/manifestival" dspa "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1" "github.com/opendatahub-io/data-science-pipelines-operator/controllers/config" + "github.com/opendatahub-io/data-science-pipelines-operator/controllers/util" v1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" @@ -63,10 +64,10 @@ type DBConnection struct { type ObjectStorageConnection struct { Bucket string CredentialsSecret *dspa.S3CredentialSecret - Secure bool Host string Port string Scheme string + Secure *bool Endpoint string // scheme://host:port AccessKeyID string SecretAccessKey string @@ -235,7 +236,17 @@ func (p *DSPAParams) SetupObjectParams(ctx context.Context, dsp *dspa.DataScienc p.ObjectStorageConnection.Bucket = dsp.Spec.ObjectStorage.ExternalStorage.Bucket p.ObjectStorageConnection.Host = dsp.Spec.ObjectStorage.ExternalStorage.Host p.ObjectStorageConnection.Scheme = dsp.Spec.ObjectStorage.ExternalStorage.Scheme - p.ObjectStorageConnection.Secure = dsp.Spec.ObjectStorage.ExternalStorage.Secure + + if dsp.Spec.ObjectStorage.ExternalStorage.Secure == nil { + if p.ObjectStorageConnection.Scheme == "https" { + p.ObjectStorageConnection.Secure = util.BoolPointer(true) + } else { + p.ObjectStorageConnection.Secure = util.BoolPointer(false) + } + } else { + p.ObjectStorageConnection.Secure = dsp.Spec.ObjectStorage.ExternalStorage.Secure + } + // Port can be empty, which is fine. p.ObjectStorageConnection.Port = dsp.Spec.ObjectStorage.ExternalStorage.Port customCreds = dsp.Spec.ObjectStorage.ExternalStorage.S3CredentialSecret @@ -265,6 +276,8 @@ func (p *DSPAParams) SetupObjectParams(ctx context.Context, dsp *dspa.DataScienc ) p.ObjectStorageConnection.Port = config.MinioPort p.ObjectStorageConnection.Scheme = config.MinioScheme + p.ObjectStorageConnection.Secure = util.BoolPointer(false) + if p.Minio.S3CredentialSecret != nil { customCreds = p.Minio.S3CredentialSecret } @@ -343,6 +356,7 @@ func (p *DSPAParams) SetupObjectParams(ctx context.Context, dsp *dspa.DataScienc } return nil + } func (p *DSPAParams) SetupMLMD(ctx context.Context, dsp *dspa.DataSciencePipelinesApplication, client client.Client, log logr.Logger) error { diff --git a/controllers/util/util.go b/controllers/util/util.go index 7aef462ee..4e86338fc 100644 --- a/controllers/util/util.go +++ b/controllers/util/util.go @@ -40,3 +40,7 @@ func GetDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.Depl } return nil } + +func BoolPointer(b bool) *bool { + return &b +}