Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kserve): check on multiple depends operators if all pre-installed #744

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/hashicorp/go-multierror"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -98,28 +99,16 @@ func (k *Kserve) ReconcileComponent(cli client.Client, owner metav1.Object, dsci
if err := k.removeServerlessFeatures(dscispec); err != nil {
return err
}
}

if enabled {
} else {
// Download manifests and update paths
if err = k.OverrideManifests(string(platform)); err != nil {
return err
}

// check on dependent operators
if found, err := deploy.OperatorExists(cli, ServiceMeshOperator); err != nil {
return err
} else if !found {
return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component",
ServiceMeshOperator, ComponentName)
}

// check on dependent operators might be in multiple namespaces
if found, err := deploy.OperatorExists(cli, ServerlessOperator); err != nil {
return err
} else if !found {
return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component",
ServerlessOperator, ComponentName)
// check on dependent operators if all installed in cluster
dependOpsErrors := checkDepedentOps(cli).ErrorOrNil()
if dependOpsErrors != nil {
return dependOpsErrors
Comment on lines +108 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// check on dependent operators if all installed in cluster
dependOpsErrors := checkDepedentOps(cli).ErrorOrNil()
if dependOpsErrors != nil {
return dependOpsErrors
if err := checkRequiredOperatorsInstalled(cli); err != nil {
return err

}

if err := k.configureServerless(dscispec); err != nil {
Expand Down Expand Up @@ -169,7 +158,7 @@ func (k *Kserve) Cleanup(_ client.Client, instance *dsciv1.DSCInitializationSpec
func (k *Kserve) configureServerless(instance *dsciv1.DSCInitializationSpec) error {
if k.Serving.ManagementState == operatorv1.Managed {
if instance.ServiceMesh.ManagementState != operatorv1.Managed {
return fmt.Errorf("service mesh is not configure in DataScienceInitialization cluster but required by KServe serving")
return fmt.Errorf("serviceMesh is not configured as Managaed in DSCI instance but required by KServe serving")
}

serverlessInitializer := feature.NewFeaturesInitializer(instance, k.configureServerlessFeatures)
Expand Down Expand Up @@ -198,3 +187,24 @@ func (k *Kserve) removeServerlessFeatures(instance *dsciv1.DSCInitializationSpec
}
return nil
}

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

if found, err := deploy.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 := deploy.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
}
Comment on lines +191 to +210
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning an error is enough here. I added a bit extra :)

Suggested change
func checkDepedentOps(cli client.Client) *multierror.Error {
var multiErr *multierror.Error
if found, err := deploy.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 := deploy.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
}
func checkRequiredOperatorsInstalled(cli client.Client) error {
var multiErr *multierror.Error
checkAndAppendError := func(operatorName string) {
if found, err := deploy.OperatorExists(cli, operatorName); 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",
operatorName, ComponentName)
multiErr = multierror.Append(multiErr, err)
}
}
checkAndAppendError(ServiceMeshOperator)
checkAndAppendError(ServerlessOperator)
return multiErr.ErrorOrNil()
}

3 changes: 1 addition & 2 deletions pkg/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ func (f *Feature) Cleanup() error {
func (f *Feature) applyManifests() error {
var applyErrors *multierror.Error
for _, m := range f.manifests {
err := f.apply(m)
applyErrors = multierror.Append(applyErrors, err)
applyErrors = multierror.Append(applyErrors, f.apply(m))
}

return applyErrors.ErrorOrNil()
Expand Down
3 changes: 1 addition & 2 deletions pkg/feature/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func (s *FeaturesInitializer) Apply() error {
var applyErrors *multierror.Error

for _, f := range s.Features {
err := f.Apply()
applyErrors = multierror.Append(applyErrors, err)
applyErrors = multierror.Append(applyErrors, f.Apply())
}

return applyErrors.ErrorOrNil()
Expand Down
Loading