diff --git a/controllers/inferenceservice_controller.go b/controllers/inferenceservice_controller.go index de6d8c4a..e251408a 100644 --- a/controllers/inferenceservice_controller.go +++ b/controllers/inferenceservice_controller.go @@ -24,8 +24,6 @@ import ( kservev1beta1 "github.com/kserve/modelmesh-serving/apis/serving/v1beta1" routev1 "github.com/openshift/api/route/v1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - istiosecv1beta1 "istio.io/client-go/pkg/apis/security/v1beta1" - telemetryv1alpha1 "istio.io/client-go/pkg/apis/telemetry/v1alpha1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" authv1 "k8s.io/api/rbac/v1" @@ -116,11 +114,9 @@ func (r *OpenshiftInferenceServiceReconciler) SetupWithManager(mgr ctrl.Manager) Owns(&corev1.Service{}). Owns(&corev1.Secret{}). Owns(&authv1.ClusterRoleBinding{}). - Owns(&istiosecv1beta1.PeerAuthentication{}). Owns(&networkingv1.NetworkPolicy{}). Owns(&monitoringv1.ServiceMonitor{}). Owns(&monitoringv1.PodMonitor{}). - Owns(&telemetryv1alpha1.Telemetry{}). Watches(&source.Kind{Type: &predictorv1.ServingRuntime{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { r.Log.Info("Reconcile event triggered by serving runtime: " + o.GetName()) diff --git a/controllers/kserve_inferenceservice_controller.go b/controllers/kserve_inferenceservice_controller.go index 815c92d4..cc37bbef 100644 --- a/controllers/kserve_inferenceservice_controller.go +++ b/controllers/kserve_inferenceservice_controller.go @@ -28,6 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" k8srbacv1 "k8s.io/api/rbac/v1" + apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -50,8 +51,37 @@ const ( clusterPrometheusAccessRoleBinding = "kserve-prometheus-k8s" clusterPrometheusAccessRole = "kserve-prometheus-k8s" InferenceSercviceLabelName = "serving.kserve.io/inferenceservice" + TelemetryCRD = "telemetries.telemetry.istio.io" + PeerAuthCRD = "peerauthentications.security.istio.io" ) +func (r *OpenshiftInferenceServiceReconciler) foundKserveDependenyCRDs(ctx context.Context) bool { + + allCRDsFound := true + // Check if CRD for Telemetry is installed + crd := &apiextv1.CustomResourceDefinition{} + err := r.Client.Get(ctx, client.ObjectKey{Name: TelemetryCRD}, crd) + if err != nil { + if apierrs.IsNotFound(err) { + allCRDsFound = false + } else { + allCRDsFound = false + } + } + + // Check if CRD for PeerAuthentication is installed + err = r.Client.Get(ctx, client.ObjectKey{Name: PeerAuthCRD}, crd) + if err != nil { + if apierrs.IsNotFound(err) { + allCRDsFound = false + } else { + allCRDsFound = false + } + } + + return allCRDsFound +} + func (r *OpenshiftInferenceServiceReconciler) ensurePrometheusRoleBinding(ctx context.Context, req ctrl.Request, ns string) error { // Initialize logger format log := r.Log.WithValues("namespace", ns) @@ -470,6 +500,12 @@ func (r *OpenshiftInferenceServiceReconciler) DeleteKserveMetricsResourcesIfNoKs // Initialize logger format log := r.Log.WithValues("namespace", ns) + //Check if the dependent CRDs for Kserve are installed + if !r.foundKserveDependenyCRDs(ctx) { + log.Info("Missing Istio CRDs") + return nil + } + inferenceServiceList := &kservev1beta1.InferenceServiceList{} err := r.List(ctx, inferenceServiceList, client.InNamespace(req.Namespace)) if err != nil { @@ -588,8 +624,13 @@ func (r *OpenshiftInferenceServiceReconciler) ReconcileKserveInference(ctx conte // Initialize logger format log := r.Log.WithValues("InferenceService", inferenceService.Name, "namespace", inferenceService.Namespace) - //Also create the metrics service and servicemonitor with OwnerReferences, as these are not common namespace-scope resources - //Create the metrics service and servicemonitor first, then ensure all namespace-scoped resources exist. + //Check if the dependent CRDs for Kserve are installed + if !r.foundKserveDependenyCRDs(ctx) { + log.Info("Missing Istio CRDs") + return nil + } + + //Create the metrics service and servicemonitor with OwnerReferences, as these are not common namespace-scope resources log.Info("Reconciling Metrics Service for InferenceSercvice") err := r.createOrUpdateMetricsService(ctx, req, inferenceService) if err != nil { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 5e8e254e..746e665e 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -25,10 +25,8 @@ import ( inferenceservicev1 "github.com/kserve/modelmesh-serving/apis/serving/v1beta1" mf "github.com/manifestival/manifestival" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - corev1 "k8s.io/api/core/v1" - k8srbacv1 "k8s.io/api/rbac/v1" - "go.uber.org/zap/zapcore" + k8srbacv1 "k8s.io/api/rbac/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" ctrl "sigs.k8s.io/controller-runtime"