Skip to content

Commit

Permalink
chore: removes a need for passing scheme instance
Browse files Browse the repository at this point in the history
When constructing a manager the defined scheme instance is passed to
manager's client. Therefore calling manager.GetClient().Scheme(), or in
fact client.Scheme() on injected one, makes passing scheme to
reconcilers redundant.

This simplifies the code by removing explicit coupling with the
scheme instance.

Signed-off-by: bartoszmajsak <[email protected]>
  • Loading branch information
bartoszmajsak committed Apr 3, 2024
1 parent a2a0dcd commit 1ab78df
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 113 deletions.
11 changes: 4 additions & 7 deletions controllers/inferenceservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
networkingv1 "k8s.io/api/networking/v1"
authv1 "k8s.io/api/rbac/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -41,23 +40,21 @@ import (
// OpenshiftInferenceServiceReconciler holds the controller configuration.
type OpenshiftInferenceServiceReconciler struct {
client client.Client
scheme *runtime.Scheme
log logr.Logger
MeshDisabled bool
mmISVCReconciler *reconcilers.ModelMeshInferenceServiceReconciler
kserveServerlessISVCReconciler *reconcilers.KserveServerlessInferenceServiceReconciler
kserveRawISVCReconciler *reconcilers.KserveRawInferenceServiceReconciler
}

func NewOpenshiftInferenceServiceReconciler(client client.Client, scheme *runtime.Scheme, log logr.Logger, meshDisabled bool) *OpenshiftInferenceServiceReconciler {
func NewOpenshiftInferenceServiceReconciler(client client.Client, log logr.Logger, meshDisabled bool) *OpenshiftInferenceServiceReconciler {
return &OpenshiftInferenceServiceReconciler{
client: client,
scheme: scheme,
log: log,
MeshDisabled: meshDisabled,
mmISVCReconciler: reconcilers.NewModelMeshInferenceServiceReconciler(client, scheme),
kserveServerlessISVCReconciler: reconcilers.NewKServeServerlessInferenceServiceReconciler(client, scheme),
kserveRawISVCReconciler: reconcilers.NewKServeRawInferenceServiceReconciler(client, scheme),
mmISVCReconciler: reconcilers.NewModelMeshInferenceServiceReconciler(client),
kserveServerlessISVCReconciler: reconcilers.NewKServeServerlessInferenceServiceReconciler(client),
kserveRawISVCReconciler: reconcilers.NewKServeRawInferenceServiceReconciler(client),
}
}

Expand Down
4 changes: 1 addition & 3 deletions controllers/kserve_customcacert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -41,8 +40,7 @@ const (

type KServeCustomCACertReconciler struct {
client.Client
Scheme *runtime.Scheme
Log logr.Logger
Log logr.Logger
}

// reconcileConfigMap watch odh global ca cert and it will create/update/delete kserve custom cert configmap
Expand Down
2 changes: 0 additions & 2 deletions controllers/monitoring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
k8srbacv1 "k8s.io/api/rbac/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"reflect"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -43,7 +42,6 @@ const (

type MonitoringReconciler struct {
client.Client
Scheme *runtime.Scheme
Log logr.Logger
MonitoringNS string
}
Expand Down
5 changes: 1 addition & 4 deletions controllers/mr_inferenceservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"google.golang.org/grpc/credentials/insecure"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand All @@ -29,15 +28,13 @@ const modelRegistryFinalizer = "modelregistry.opendatahub.io/finalizer"
// ModelRegistryInferenceServiceReconciler holds the controller configuration.
type ModelRegistryInferenceServiceReconciler struct {
client client.Client
scheme *runtime.Scheme
log logr.Logger
deltaProcessor processors.DeltaProcessor
}

func NewModelRegistryInferenceServiceReconciler(client client.Client, scheme *runtime.Scheme, log logr.Logger) *ModelRegistryInferenceServiceReconciler {
func NewModelRegistryInferenceServiceReconciler(client client.Client, log logr.Logger) *ModelRegistryInferenceServiceReconciler {
return &ModelRegistryInferenceServiceReconciler{
client: client,
scheme: scheme,
log: log,
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
7 changes: 2 additions & 5 deletions controllers/reconcilers/kserve_authconfig_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/processors"
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
k8serror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -37,18 +36,16 @@ var _ SubResourceReconciler = (*KserveAuthConfigReconciler)(nil)

type KserveAuthConfigReconciler struct {
client client.Client
scheme *runtime.Scheme
deltaProcessor processors.DeltaProcessor
detector resources.AuthTypeDetector
store resources.AuthConfigStore
templateLoader resources.AuthConfigTemplateLoader
hostExtractor resources.InferenceServiceHostExtractor
}

func NewKserveAuthConfigReconciler(client client.Client, scheme *runtime.Scheme) *KserveAuthConfigReconciler {
func NewKserveAuthConfigReconciler(client client.Client) *KserveAuthConfigReconciler {
return &KserveAuthConfigReconciler{
client: client,
scheme: scheme,
deltaProcessor: processors.NewDeltaProcessor(),
detector: resources.NewKServeAuthTypeDetector(client),
store: resources.NewClientAuthConfigStore(client),
Expand Down Expand Up @@ -119,7 +116,7 @@ func (r *KserveAuthConfigReconciler) createDesiredResource(ctx context.Context,
}
template.Labels[constants.LabelAuthGroup] = "default"

ctrl.SetControllerReference(isvc, &template, r.scheme)
ctrl.SetControllerReference(isvc, &template, r.client.Scheme())

return &template, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
istiotypes "istio.io/api/type/v1beta1"
istiosecv1beta1 "istio.io/client-go/pkg/apis/security/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -40,15 +39,13 @@ var _ SubResourceReconciler = (*KserveIstioPeerAuthenticationReconciler)(nil)
type KserveIstioPeerAuthenticationReconciler struct {
SingleResourcePerNamespace
client client.Client
scheme *runtime.Scheme
peerAuthenticationHandler resources.PeerAuthenticationHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeIstioPeerAuthenticationReconciler(client client.Client, scheme *runtime.Scheme) *KserveIstioPeerAuthenticationReconciler {
func NewKServeIstioPeerAuthenticationReconciler(client client.Client) *KserveIstioPeerAuthenticationReconciler {
return &KserveIstioPeerAuthenticationReconciler{
client: client,
scheme: scheme,
peerAuthenticationHandler: resources.NewPeerAuthenticationHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -38,15 +37,13 @@ var _ SubResourceReconciler = (*KserveIstioPodMonitorReconciler)(nil)
type KserveIstioPodMonitorReconciler struct {
SingleResourcePerNamespace
client client.Client
scheme *runtime.Scheme
podMonitorHandler resources.PodMonitorHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeIstioPodMonitorReconciler(client client.Client, scheme *runtime.Scheme) *KserveIstioPodMonitorReconciler {
func NewKServeIstioPodMonitorReconciler(client client.Client) *KserveIstioPodMonitorReconciler {
return &KserveIstioPodMonitorReconciler{
client: client,
scheme: scheme,
podMonitorHandler: resources.NewPodMonitorHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -37,15 +36,13 @@ var _ SubResourceReconciler = (*KserveIstioServiceMonitorReconciler)(nil)

type KserveIstioServiceMonitorReconciler struct {
client client.Client
scheme *runtime.Scheme
serviceMonitorHandler resources.ServiceMonitorHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeIstioServiceMonitorReconciler(client client.Client, scheme *runtime.Scheme) *KserveIstioServiceMonitorReconciler {
func NewKServeIstioServiceMonitorReconciler(client client.Client) *KserveIstioServiceMonitorReconciler {
return &KserveIstioServiceMonitorReconciler{
client: client,
scheme: scheme,
serviceMonitorHandler: resources.NewServiceMonitorHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
5 changes: 1 addition & 4 deletions controllers/reconcilers/kserve_istio_smmr_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/processors"
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
v1 "maistra.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -35,15 +34,13 @@ var _ SubResourceReconciler = (*KserveIstioSMMRReconciler)(nil)
type KserveIstioSMMRReconciler struct {
SingleResourcePerNamespace
client client.Client
scheme *runtime.Scheme
smmrHandler resources.ServiceMeshMemberRollHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeIstioSMMRReconciler(client client.Client, scheme *runtime.Scheme) *KserveIstioSMMRReconciler {
func NewKServeIstioSMMRReconciler(client client.Client) *KserveIstioSMMRReconciler {
return &KserveIstioSMMRReconciler{
client: client,
scheme: scheme,
smmrHandler: resources.NewServiceMeshMemberRole(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
5 changes: 1 addition & 4 deletions controllers/reconcilers/kserve_istio_telemetry_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
istiotypes "istio.io/api/type/v1beta1"
telemetryv1alpha1 "istio.io/client-go/pkg/apis/telemetry/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -40,15 +39,13 @@ var _ SubResourceReconciler = (*KserveIstioTelemetryReconciler)(nil)
type KserveIstioTelemetryReconciler struct {
SingleResourcePerNamespace
client client.Client
scheme *runtime.Scheme
telemetryHandler resources.TelemetryHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeIstioTelemetryReconciler(client client.Client, scheme *runtime.Scheme) *KserveIstioTelemetryReconciler {
func NewKServeIstioTelemetryReconciler(client client.Client) *KserveIstioTelemetryReconciler {
return &KserveIstioTelemetryReconciler{
client: client,
scheme: scheme,
telemetryHandler: resources.NewTelemetryHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
7 changes: 2 additions & 5 deletions controllers/reconcilers/kserve_metrics_service_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -40,15 +39,13 @@ var _ SubResourceReconciler = (*KserveMetricsServiceReconciler)(nil)
type KserveMetricsServiceReconciler struct {
NoResourceRemoval
client client.Client
scheme *runtime.Scheme
serviceHandler resources.ServiceHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeMetricsServiceReconciler(client client.Client, scheme *runtime.Scheme) *KserveMetricsServiceReconciler {
func NewKServeMetricsServiceReconciler(client client.Client) *KserveMetricsServiceReconciler {
return &KserveMetricsServiceReconciler{
client: client,
scheme: scheme,
serviceHandler: resources.NewServiceHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down Expand Up @@ -106,7 +103,7 @@ func (r *KserveMetricsServiceReconciler) createDesiredResource(log logr.Logger,
},
},
}
if err := ctrl.SetControllerReference(isvc, metricsService, r.scheme); err != nil {
if err := ctrl.SetControllerReference(isvc, metricsService, r.client.Scheme()); err != nil {
log.Error(err, "Unable to add OwnerReference to the Metrics Service")
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -35,15 +34,13 @@ var _ SubResourceReconciler = (*KserveMetricsServiceMonitorReconciler)(nil)
type KserveMetricsServiceMonitorReconciler struct {
NoResourceRemoval
client client.Client
scheme *runtime.Scheme
serviceMonitorHandler resources.ServiceMonitorHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeMetricsServiceMonitorReconciler(client client.Client, scheme *runtime.Scheme) *KserveMetricsServiceMonitorReconciler {
func NewKServeMetricsServiceMonitorReconciler(client client.Client) *KserveMetricsServiceMonitorReconciler {
return &KserveMetricsServiceMonitorReconciler{
client: client,
scheme: scheme,
serviceMonitorHandler: resources.NewServiceMonitorHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down Expand Up @@ -96,7 +93,7 @@ func (r *KserveMetricsServiceMonitorReconciler) createDesiredResource(isvc *kser
},
},
}
if err := ctrl.SetControllerReference(isvc, desiredServiceMonitor, r.scheme); err != nil {
if err := ctrl.SetControllerReference(isvc, desiredServiceMonitor, r.client.Scheme()); err != nil {
return nil, err
}
return desiredServiceMonitor, nil
Expand Down
5 changes: 1 addition & 4 deletions controllers/reconcilers/kserve_networkpolicy_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
"k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -43,15 +42,13 @@ var _ SubResourceReconciler = (*KserveNetworkPolicyReconciler)(nil)
type KserveNetworkPolicyReconciler struct {
SingleResourcePerNamespace
client client.Client
scheme *runtime.Scheme
networkPolicyHandler resources.NetworkPolicyHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServeNetworkPolicyReconciler(client client.Client, scheme *runtime.Scheme) *KserveNetworkPolicyReconciler {
func NewKServeNetworkPolicyReconciler(client client.Client) *KserveNetworkPolicyReconciler {
return &KserveNetworkPolicyReconciler{
client: client,
scheme: scheme,
networkPolicyHandler: resources.NewNetworkPolicyHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
v1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -38,15 +37,13 @@ var _ SubResourceReconciler = (*KservePrometheusRoleBindingReconciler)(nil)
type KservePrometheusRoleBindingReconciler struct {
SingleResourcePerNamespace
client client.Client
scheme *runtime.Scheme
roleBindingHandler resources.RoleBindingHandler
deltaProcessor processors.DeltaProcessor
}

func NewKServePrometheusRoleBindingReconciler(client client.Client, scheme *runtime.Scheme) *KservePrometheusRoleBindingReconciler {
func NewKServePrometheusRoleBindingReconciler(client client.Client) *KservePrometheusRoleBindingReconciler {
return &KservePrometheusRoleBindingReconciler{
client: client,
scheme: scheme,
roleBindingHandler: resources.NewRoleBindingHandler(client),
deltaProcessor: processors.NewDeltaProcessor(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/go-logr/logr"
kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -30,7 +29,7 @@ type KserveRawInferenceServiceReconciler struct {
client client.Client
}

func NewKServeRawInferenceServiceReconciler(client client.Client, scheme *runtime.Scheme) *KserveRawInferenceServiceReconciler {
func NewKServeRawInferenceServiceReconciler(client client.Client) *KserveRawInferenceServiceReconciler {
return &KserveRawInferenceServiceReconciler{
client: client,
}
Expand Down
Loading

0 comments on commit 1ab78df

Please sign in to comment.