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.
@@ -164,14 +164,6 @@ func main() {
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 @@ func main() {
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 {
