Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Use helper methods from kcp controller-runtime to build manager #5

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
32 changes: 3 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
Expand All @@ -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)
}
Expand Down