diff --git a/components/kserve/kserve.go b/components/kserve/kserve.go index ace508b8074..72fb0b1e9fa 100644 --- a/components/kserve/kserve.go +++ b/components/kserve/kserve.go @@ -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 { diff --git a/components/kserve/kserve_config_handler.go b/components/kserve/kserve_config_handler.go index 06f23611587..c92bf11c30d 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(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") @@ -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 { @@ -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 +}