Skip to content

Commit

Permalink
Leverage DB/ObjStore Routes for Prereq Health Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
VaniHaripriya committed Dec 18, 2023
1 parent 3678752 commit 098c2d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config/samples/dspa_simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ spec:
# This is NOT supported and should be used for dev testing/experimentation only.
# See dspa_simple_external_storage.yaml for an example with external connection.
objectStorage:
disableHealthCheck: false
enableExternalRoute: true
minio:
# Image field is required
image: 'quay.io/opendatahub/minio:RELEASE.2019-08-14T20-37-41Z-license-compliance'
Expand Down
37 changes: 36 additions & 1 deletion controllers/dspipeline_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
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"
routev1 "github.com/openshift/api/route/v1"
v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -77,6 +78,7 @@ type ObjectStorageConnection struct {
Endpoint string // scheme://host:port
AccessKeyID string
SecretAccessKey string
ExternalRouteURL string
}

// UsingExternalDB will return true if an external Database is specified in the CR, otherwise false.
Expand Down Expand Up @@ -111,6 +113,14 @@ func (p *DSPAParams) ObjectStorageHealthCheckDisabled(dsp *dspa.DataSciencePipel
return false
}

// ExternalRouteEnabled will return true if an external route is enabled in the CR, otherwise false.
func (p *DSPAParams) ExternalRouteEnabled(dsp *dspa.DataSciencePipelinesApplication) bool {
if dsp.Spec.ObjectStorage != nil {
return dsp.Spec.ObjectStorage.EnableExternalRoute
}
return false
}

func (p *DSPAParams) UsingMLMD(dsp *dspa.DataSciencePipelinesApplication) bool {
if dsp.Spec.MLMD != nil {
return dsp.Spec.MLMD.Deploy
Expand Down Expand Up @@ -176,6 +186,19 @@ func (p *DSPAParams) RetrieveOrCreateObjectStoreSecret(ctx context.Context, clie
return accessKey, secretKey, nil
}

func (p *DSPAParams) RetrieveExternalRoute(ctx context.Context, client client.Client, log logr.Logger) (string, error) {
route := &routev1.Route{}
namespacedName := types.NamespacedName{
Name: "minio-" + p.Name,
Namespace: p.Namespace,
}
if err := client.Get(ctx, namespacedName, route); err != nil {
log.V(1).Info("Unable to retrieve route", "error", err)
return "", err
}
return route.Spec.Host, nil
}

// SetupDBParams Populates the DB connection Parameters.
// If an external secret is specified, SetupDBParams will retrieve DB credentials from it.
// If DSPO is managing a dynamically created secret, then SetupDBParams generates the creds.
Expand Down Expand Up @@ -333,8 +356,20 @@ func (p *DSPAParams) SetupObjectParams(ctx context.Context, dsp *dspa.DataScienc
}
p.ObjectStorageConnection.AccessKeyID = accessKey
p.ObjectStorageConnection.SecretAccessKey = secretKey
}

if dsp.Spec.ObjectStorage.EnableExternalRoute {
host, err := p.RetrieveExternalRoute(ctx, client, log)
if err != nil {
log.Error(err, "Failed to retrieve external route")
return err
}
externalRoute := fmt.Sprintf("%s", host)
p.ObjectStorageConnection.ExternalRouteURL = externalRoute
p.ObjectStorageConnection.Secure = util.BoolPointer(true)
p.ObjectStorageConnection.Host = externalRoute
p.ObjectStorageConnection.Scheme = "https"
}
}
endpoint := fmt.Sprintf(
"%s://%s",
p.ObjectStorageConnection.Scheme,
Expand Down
16 changes: 11 additions & 5 deletions controllers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,17 @@ func (r *DSPAReconciler) isObjectStorageAccessible(ctx context.Context, dsp *dsp

log.Info("Performing Object Storage Health Check")

endpoint, err := joinHostPort(params.ObjectStorageConnection.Host, params.ObjectStorageConnection.Port)
if err != nil {
errorMessage := "Could not determine Object Storage Endpoint"
log.Error(err, errorMessage)
return false, errors.New(errorMessage)
var endpoint string
if params.ExternalRouteEnabled(dsp) {
endpoint = params.ObjectStorageConnection.ExternalRouteURL
} else {
var err error
endpoint, err = joinHostPort(params.ObjectStorageConnection.Host, params.ObjectStorageConnection.Port)
if err != nil {
errorMessage := "Could not determine Object Storage Endpoint"
log.Error(err, errorMessage)
return false, errors.New(errorMessage)
}
}

accesskey, err := base64.StdEncoding.DecodeString(params.ObjectStorageConnection.AccessKeyID)
Expand Down

0 comments on commit 098c2d0

Please sign in to comment.