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

Commit 7b0e9cd

Browse files
authored
Merge pull request #5 from fabianvf/simplify-main
Use helper methods from kcp controller-runtime to build manager
2 parents 8393be8 + 41ceef9 commit 7b0e9cd

File tree

3 files changed

+6
-32
lines changed

3 files changed

+6
-32
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ replace (
6767
k8s.io/api => github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf
6868
k8s.io/apimachinery => github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf
6969
k8s.io/client-go => github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf
70-
sigs.k8s.io/controller-runtime => github.com/kcp-dev/controller-runtime v0.11.3-0.20220525203614-3f3188c144db
70+
sigs.k8s.io/controller-runtime => github.com/kcp-dev/controller-runtime v0.11.3-0.20220526160644-dde7624d3976
7171
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
294294
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
295295
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55 h1:nwrXHxVkTQ9BI6slgqWgg8CVC+7AbJR02byYq+iBOUg=
296296
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55/go.mod h1:FIzhTU6DM3HYZhGv8w/1S/mbmSv1HzulZpjr/1/6i/I=
297-
github.com/kcp-dev/controller-runtime v0.11.3-0.20220525203614-3f3188c144db h1:MLND8RHST1F2JN7xC7l76YW66WlCz0RV0DPNe1UqoNg=
298-
github.com/kcp-dev/controller-runtime v0.11.3-0.20220525203614-3f3188c144db/go.mod h1:7iVCCTX1SSLJl8cR7UQcwgQsZezCW+wv8VxeoYUGAX0=
297+
github.com/kcp-dev/controller-runtime v0.11.3-0.20220526160644-dde7624d3976 h1:pjIWLTdYEZqpbFCNNEqna78X6KYsjrb+7BmJecIeX6k=
298+
github.com/kcp-dev/controller-runtime v0.11.3-0.20220526160644-dde7624d3976/go.mod h1:7iVCCTX1SSLJl8cR7UQcwgQsZezCW+wv8VxeoYUGAX0=
299299
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf h1:b3UxxmQEB0ZGXGmlGOhFPElpaLPoEEjNneH6ipn4WdE=
300300
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:YaTOAfRXJ+yMgQtYx2JxXdxGGoAonb1tg1rTLU0IT54=
301301
github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf h1:BiQgcrehqYiTG507kL3GFJtR5ni/fztwll9VodvlEd4=

main.go

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,16 @@ import (
2020
"flag"
2121
"os"
2222

23-
kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
24-
kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
2523
"github.com/kcp-dev/controller-runtime-example/controllers"
26-
"github.com/kcp-dev/logicalcluster"
2724
corev1 "k8s.io/api/core/v1"
2825
"k8s.io/apimachinery/pkg/runtime"
2926
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3027
"sigs.k8s.io/controller-runtime/pkg/client/config"
28+
"sigs.k8s.io/controller-runtime/pkg/kcp"
3129

3230
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
33-
"k8s.io/client-go/rest"
3431
ctrl "sigs.k8s.io/controller-runtime"
3532

36-
"sigs.k8s.io/controller-runtime/pkg/cache"
37-
"sigs.k8s.io/controller-runtime/pkg/client"
38-
"sigs.k8s.io/controller-runtime/pkg/cluster"
3933
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4034
)
4135

@@ -62,29 +56,9 @@ func main() {
6256
os.Exit(1)
6357
}
6458

65-
httpClient, err := rest.HTTPClientFor(cfg)
66-
if err != nil {
67-
setupLog.Error(err, "unable to build http client")
68-
os.Exit(1)
69-
}
70-
71-
httpClient.Transport = kcpclient.NewClusterRoundTripper(httpClient.Transport)
72-
73-
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
59+
mgr, err := kcp.NewClusterAwareManager(cfg, ctrl.Options{
7460
Scheme: scheme,
7561
LeaderElection: false,
76-
// LeaderElectionNamespace: "default",
77-
// LeaderElectionID: "kcp-example",
78-
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
79-
c := rest.CopyConfig(config)
80-
c.Host += "/clusters/*"
81-
opts.KeyFunction = kcpcache.ClusterAwareKeyFunc
82-
return cache.New(c, opts)
83-
},
84-
NewClient: func(cache cache.Cache, config *rest.Config, opts client.Options, uncachedObjects ...client.Object) (client.Client, error) {
85-
opts.HTTPClient = httpClient
86-
return cluster.DefaultNewClient(cache, config, opts, uncachedObjects...)
87-
},
8862
})
8963
if err != nil {
9064
setupLog.Error(err, "unable to start manager")
@@ -99,7 +73,7 @@ func main() {
9973
}
10074

10175
setupLog.Info("starting manager")
102-
if err := mgr.Start(kcpclient.WithCluster(ctrl.SetupSignalHandler(), logicalcluster.Wildcard)); err != nil {
76+
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
10377
setupLog.Error(err, "problem running manager")
10478
os.Exit(1)
10579
}

0 commit comments

Comments
 (0)