Skip to content

Commit

Permalink
It takes more than 10 minutes for kserve-controller to be created dur…
Browse files Browse the repository at this point in the history
…ing 2.17 installation (#1564) (#1572)

* It takes more than 10 minutes for kserve-controller to be created during 2.17 installation

* cleanup

(cherry picked from commit 48341ff)

Co-authored-by: Luca Burgazzoli <[email protected]>
  • Loading branch information
zdtsw and lburgazzoli authored Jan 27, 2025
1 parent 8925154 commit 2d6f112
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
9 changes: 8 additions & 1 deletion controllers/components/kserve/kserve_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featuresv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
Expand All @@ -43,6 +44,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/clusterrole"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/component"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/generation"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/hash"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/resources"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/reconciler"
Expand Down Expand Up @@ -113,7 +115,12 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
},
)),
).

// resource
Watches(
&dsciv1.DSCInitialization{},
reconciler.WithEventHandler(handlers.ToNamed(componentApi.KserveInstanceName)),
reconciler.WithPredicates(predicate.Or(generation.New(), resources.DSCIReadiness)),
).
// operands - dynamically watched
//
// A watch will be created dynamically for these kinds, if they exist on the cluster
Expand Down
25 changes: 25 additions & 0 deletions pkg/controller/predicates/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
)

var _ predicate.Predicate = DeploymentPredicate{}
Expand Down Expand Up @@ -117,3 +118,27 @@ var DSCComponentUpdatePredicate = predicate.Funcs{
return false
},
}

var DSCIReadiness = predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldObj, ok := e.ObjectOld.(*dsciv1.DSCInitialization)
if !ok {
return false
}
newObj, ok := e.ObjectNew.(*dsciv1.DSCInitialization)
if !ok {
return false
}

return oldObj.Status.Phase != newObj.Status.Phase
},
CreateFunc: func(e event.CreateEvent) bool {
return false
},
DeleteFunc: func(e event.DeleteEvent) bool {
return false
},
GenericFunc: func(e event.GenericEvent) bool {
return false
},
}
15 changes: 12 additions & 3 deletions pkg/feature/servicemesh/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ func WaitForControlPlaneToBeReady(ctx context.Context, cli client.Client, f *fea

return wait.PollUntilContextTimeout(ctx, interval, duration, false, func(ctx context.Context) (bool, error) {
ready, err := CheckControlPlaneComponentReadiness(ctx, cli, smcp, smcpNs)
if err != nil {
return false, err
}

if ready {
f.Log.Info("done waiting for control plane components to be ready", "control-plane", smcp, "namespace", smcpNs)
}

return ready, err
return ready, nil
})
}

Expand All @@ -107,14 +110,20 @@ func CheckControlPlaneComponentReadiness(ctx context.Context, c client.Client, s
Name: smcpName,
}, smcpObj)

if err != nil {
switch {
case k8serr.IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("failed to find Service Mesh Control Plane: %w", err)
}

components, found, err := unstructured.NestedMap(smcpObj.Object, "status", "readiness", "components")
if err != nil || !found {
if err != nil {
return false, fmt.Errorf("status conditions not found or error in parsing of Service Mesh Control Plane: %w", err)
}
if !found {
return false, nil
}

readyComponents := len(components["ready"].([]interface{})) //nolint:forcetypeassert,errcheck
pendingComponents := len(components["pending"].([]interface{})) //nolint:forcetypeassert,errcheck
Expand Down

0 comments on commit 2d6f112

Please sign in to comment.