From 30380403d07a41dc45113c8f1cf59458296381ab Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Thu, 19 Jan 2023 12:42:09 -0800 Subject: [PATCH] cmd/k8s-operator: remove use of InjectClient (deprecated) The dependency injection functionality has been deprecated a while back and it'll be removed in the 0.15 release of Controller Runtime. This changeset sets the Client after creating the Manager, instead of using InjectClient. Signed-off-by: Vince Prignano --- cmd/k8s-operator/operator.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/cmd/k8s-operator/operator.go b/cmd/k8s-operator/operator.go index 26b32020f..8496558d4 100644 --- a/cmd/k8s-operator/operator.go +++ b/cmd/k8s-operator/operator.go @@ -164,14 +164,6 @@ waitOnline: time.Sleep(time.Second) } - sr := &ServiceReconciler{ - tsClient: tsClient, - defaultTags: strings.Split(tags, ","), - operatorNamespace: tsNamespace, - proxyImage: image, - logger: zlog.Named("service-reconciler"), - } - // For secrets and statefulsets, we only get permission to touch the objects // in the controller's own namespace. This cannot be expressed by // .Watches(...) below, instead you have to add a per-type field selector to @@ -193,6 +185,15 @@ waitOnline: startlog.Fatalf("could not create manager: %v", err) } + sr := &ServiceReconciler{ + Client: mgr.GetClient(), + tsClient: tsClient, + defaultTags: strings.Split(tags, ","), + operatorNamespace: tsNamespace, + proxyImage: image, + logger: zlog.Named("service-reconciler"), + } + reconcileFilter := handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { ls := o.GetLabels() if ls[LabelManaged] != "true" { @@ -591,11 +592,6 @@ func (a *ServiceReconciler) reconcileSTS(ctx context.Context, logger *zap.Sugare return createOrUpdate(ctx, a.Client, a.operatorNamespace, &ss, func(s *appsv1.StatefulSet) { s.Spec = ss.Spec }) } -func (a *ServiceReconciler) InjectClient(c client.Client) error { - a.Client = c - return nil -} - // ptrObject is a type constraint for pointer types that implement // client.Object. type ptrObject[T any] interface {