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)" (opendatahub-io#1107)

This reverts commit 55320b6.
  • Loading branch information
zdtsw authored and openshift-merge-bot[bot] committed Jul 24, 2024
1 parent 873fd5f commit 0600527
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 @@ -113,7 +113,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
} else {
// Configure dependencies
if err := k.configureServerless(dscispec); err != nil {
if err := k.configureServerless(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(instance *dsciv1.DSCInitializationSpec) error {
func (k *Kserve) configureServerless(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(instance *dsciv1.DSCInitializationSpec) err
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(cli).ErrorOrNil()
if dependOpsErrors != nil {
return dependOpsErrors
}

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

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

return serverlessFeatures.Delete()
}

func checkDependentOperators(cli client.Client) *multierror.Error {
var multiErr *multierror.Error

if found, err := cluster.OperatorExists(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(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 0600527

Please sign in to comment.