diff --git a/go.mod b/go.mod index 303fc11..e1c0444 100644 --- a/go.mod +++ b/go.mod @@ -67,5 +67,5 @@ replace ( k8s.io/api => github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf k8s.io/apimachinery => github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf k8s.io/client-go => github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf - sigs.k8s.io/controller-runtime => github.com/kcp-dev/controller-runtime v0.11.3-0.20220525203614-3f3188c144db + sigs.k8s.io/controller-runtime => github.com/kcp-dev/controller-runtime v0.11.3-0.20220526160644-dde7624d3976 ) diff --git a/go.sum b/go.sum index 575600d..25d460e 100644 --- a/go.sum +++ b/go.sum @@ -294,8 +294,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55 h1:nwrXHxVkTQ9BI6slgqWgg8CVC+7AbJR02byYq+iBOUg= github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55/go.mod h1:FIzhTU6DM3HYZhGv8w/1S/mbmSv1HzulZpjr/1/6i/I= -github.com/kcp-dev/controller-runtime v0.11.3-0.20220525203614-3f3188c144db h1:MLND8RHST1F2JN7xC7l76YW66WlCz0RV0DPNe1UqoNg= -github.com/kcp-dev/controller-runtime v0.11.3-0.20220525203614-3f3188c144db/go.mod h1:7iVCCTX1SSLJl8cR7UQcwgQsZezCW+wv8VxeoYUGAX0= +github.com/kcp-dev/controller-runtime v0.11.3-0.20220526160644-dde7624d3976 h1:pjIWLTdYEZqpbFCNNEqna78X6KYsjrb+7BmJecIeX6k= +github.com/kcp-dev/controller-runtime v0.11.3-0.20220526160644-dde7624d3976/go.mod h1:7iVCCTX1SSLJl8cR7UQcwgQsZezCW+wv8VxeoYUGAX0= github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf h1:b3UxxmQEB0ZGXGmlGOhFPElpaLPoEEjNneH6ipn4WdE= github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:YaTOAfRXJ+yMgQtYx2JxXdxGGoAonb1tg1rTLU0IT54= github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf h1:BiQgcrehqYiTG507kL3GFJtR5ni/fztwll9VodvlEd4= diff --git a/main.go b/main.go index 99beb50..88b61a1 100644 --- a/main.go +++ b/main.go @@ -20,22 +20,16 @@ import ( "flag" "os" - kcpcache "github.com/kcp-dev/apimachinery/pkg/cache" - kcpclient "github.com/kcp-dev/apimachinery/pkg/client" "github.com/kcp-dev/controller-runtime-example/controllers" - "github.com/kcp-dev/logicalcluster" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "sigs.k8s.io/controller-runtime/pkg/client/config" + "sigs.k8s.io/controller-runtime/pkg/kcp" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/cache" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/cluster" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -62,29 +56,9 @@ func main() { os.Exit(1) } - httpClient, err := rest.HTTPClientFor(cfg) - if err != nil { - setupLog.Error(err, "unable to build http client") - os.Exit(1) - } - - httpClient.Transport = kcpclient.NewClusterRoundTripper(httpClient.Transport) - - mgr, err := ctrl.NewManager(cfg, ctrl.Options{ + mgr, err := kcp.NewClusterAwareManager(cfg, ctrl.Options{ Scheme: scheme, LeaderElection: false, - // LeaderElectionNamespace: "default", - // LeaderElectionID: "kcp-example", - NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) { - c := rest.CopyConfig(config) - c.Host += "/clusters/*" - opts.KeyFunction = kcpcache.ClusterAwareKeyFunc - return cache.New(c, opts) - }, - NewClient: func(cache cache.Cache, config *rest.Config, opts client.Options, uncachedObjects ...client.Object) (client.Client, error) { - opts.HTTPClient = httpClient - return cluster.DefaultNewClient(cache, config, opts, uncachedObjects...) - }, }) if err != nil { setupLog.Error(err, "unable to start manager") @@ -99,7 +73,7 @@ func main() { } setupLog.Info("starting manager") - if err := mgr.Start(kcpclient.WithCluster(ctrl.SetupSignalHandler(), logicalcluster.Wildcard)); err != nil { + if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") os.Exit(1) }