From 0600527a4d3a614fca3fa0def84e22ee1cdeaa31 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Wed, 10 Jul 2024 10:30:51 +0200 Subject: [PATCH] Revert "chore(cleanup): remove checkDependentOperators as duplicated logic (#996)" (#1107) This reverts commit 55320b6606d26046beaffd91132f54ecf1762e97. --- components/kserve/kserve.go | 2 +- components/kserve/kserve_config_handler.go | 31 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/components/kserve/kserve.go b/components/kserve/kserve.go index e3b2ceffcaf..d840284dfa1 100644 --- a/components/kserve/kserve.go +++ b/components/kserve/kserve.go @@ -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 { diff --git a/components/kserve/kserve_config_handler.go b/components/kserve/kserve_config_handler.go index 7907d760a30..6fd4a52e18c 100644 --- a/components/kserve/kserve_config_handler.go +++ b/components/kserve/kserve_config_handler.go @@ -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" ) @@ -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") @@ -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 { @@ -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 +}