Skip to content

Commit

Permalink
Revert "chore(cleanup): remove checkDependentOperators as duplicated …
Browse files Browse the repository at this point in the history
…logic (opendatahub-io#996)"

This reverts commit 55320b6.
  • Loading branch information
zdtsw committed Jul 9, 2024
1 parent 9dd3596 commit a68833a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
} else {
// Configure dependencies
if err := k.configureServerless(ctx, dscispec); err != nil {
if err := k.configureServerless(ctx, cli, dscispec); err != nil {
return err
}
if k.DevFlags != nil {
Expand Down
31 changes: 30 additions & 1 deletion components/kserve/kserve_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"errors"
"fmt"

"github.com/hashicorp/go-multierror"
operatorv1 "github.com/openshift/api/operator/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
)
Expand Down Expand Up @@ -115,7 +117,7 @@ func (k *Kserve) setDefaultDeploymentMode(ctx context.Context, cli client.Client
return nil
}

func (k *Kserve) configureServerless(ctx context.Context, instance *dsciv1.DSCInitializationSpec) error {
func (k *Kserve) configureServerless(ctx context.Context, cli client.Client, instance *dsciv1.DSCInitializationSpec) error {
switch k.Serving.ManagementState {
case operatorv1.Unmanaged: // Bring your own CR
fmt.Println("Serverless CR is not configured by the operator, we won't do anything")
Expand All @@ -132,6 +134,12 @@ func (k *Kserve) configureServerless(ctx context.Context, instance *dsciv1.DSCIn
return errors.New("ServiceMesh is need to set to 'Managed' in DSCI CR, it is required by KServe serving field")
}

// check on dependent operators if all installed in cluster
dependOpsErrors := checkDependentOperators(ctx, cli).ErrorOrNil()
if dependOpsErrors != nil {
return dependOpsErrors
}

serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance, k.configureServerlessFeatures())

if err := serverlessFeatures.Apply(ctx); err != nil {
Expand All @@ -146,3 +154,24 @@ func (k *Kserve) removeServerlessFeatures(ctx context.Context, instance *dsciv1.

return serverlessFeatures.Delete(ctx)
}

func checkDependentOperators(ctx context.Context, cli client.Client) *multierror.Error {
var multiErr *multierror.Error

if found, err := cluster.OperatorExists(ctx, cli, ServiceMeshOperator); err != nil {
multiErr = multierror.Append(multiErr, err)
} else if !found {
err = fmt.Errorf("operator %s not found. Please install the operator before enabling %s component",
ServiceMeshOperator, ComponentName)
multiErr = multierror.Append(multiErr, err)
}

if found, err := cluster.OperatorExists(ctx, cli, ServerlessOperator); err != nil {
multiErr = multierror.Append(multiErr, err)
} else if !found {
err = fmt.Errorf("operator %s not found. Please install the operator before enabling %s component",
ServerlessOperator, ComponentName)
multiErr = multierror.Append(multiErr, err)
}
return multiErr
}

0 comments on commit a68833a

Please sign in to comment.