From 2d6f1123ffa3026719886c3b8cded752ef46ad61 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Mon, 27 Jan 2025 22:44:41 +0100 Subject: [PATCH] It takes more than 10 minutes for kserve-controller to be created during 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 48341ffdc20606a517f65502662d39515716737e) Co-authored-by: Luca Burgazzoli --- .../components/kserve/kserve_controller.go | 9 ++++++- .../predicates/resources/resources.go | 25 +++++++++++++++++++ pkg/feature/servicemesh/conditions.go | 15 ++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/controllers/components/kserve/kserve_controller.go b/controllers/components/kserve/kserve_controller.go index 6c0b2bcf0a7..79cf801b932 100644 --- a/controllers/components/kserve/kserve_controller.go +++ b/controllers/components/kserve/kserve_controller.go @@ -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" @@ -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" @@ -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 diff --git a/pkg/controller/predicates/resources/resources.go b/pkg/controller/predicates/resources/resources.go index 1ff5c8734b0..bbb48296467 100644 --- a/pkg/controller/predicates/resources/resources.go +++ b/pkg/controller/predicates/resources/resources.go @@ -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{} @@ -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 + }, +} diff --git a/pkg/feature/servicemesh/conditions.go b/pkg/feature/servicemesh/conditions.go index 6926a5dfe3f..2920f09f8a6 100644 --- a/pkg/feature/servicemesh/conditions.go +++ b/pkg/feature/servicemesh/conditions.go @@ -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 }) } @@ -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