From d1904ca0c10b1e15fce0fc326df4918f5fe5dbf1 Mon Sep 17 00:00:00 2001 From: Arvind Thirumurugan Date: Thu, 26 Sep 2024 23:44:03 -0700 Subject: [PATCH] fix: Enable v1beta1 MC controller when v1beta1 API exists (#200) --- cmd/hub-net-controller-manager/main.go | 25 ++++++++++++++++--------- go.mod | 6 ++++++ go.sum | 4 ++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/cmd/hub-net-controller-manager/main.go b/cmd/hub-net-controller-manager/main.go index 23daa5c8..2627e9f5 100644 --- a/cmd/hub-net-controller-manager/main.go +++ b/cmd/hub-net-controller-manager/main.go @@ -17,6 +17,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/rand" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/client-go/discovery" clientgoscheme "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth" "k8s.io/klog/v2" @@ -27,6 +28,7 @@ import ( //+kubebuilder:scaffold:imports clusterv1beta1 "go.goms.io/fleet/apis/cluster/v1beta1" + "go.goms.io/fleet/pkg/utils" fleetnetv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1" "go.goms.io/fleet-networking/pkg/controllers/hub/endpointsliceexport" @@ -80,7 +82,8 @@ func main() { klog.InfoS("flag:", "name", f.Name, "value", f.Value) }) - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + hubConfig := ctrl.GetConfigOrDie() + mgr, err := ctrl.NewManager(hubConfig, ctrl.Options{ Scheme: scheme, Metrics: metricsserver.Options{ BindAddress: *metricsAddr, @@ -145,14 +148,18 @@ func main() { exitWithErrorFunc() } - klog.V(1).InfoS("Start to setup MemberCluster controller") - if err := (&membercluster.Reconciler{ - Client: mgr.GetClient(), - Recorder: mgr.GetEventRecorderFor(membercluster.ControllerName), - ForceDeleteWaitTime: *forceDeleteWaitTime, - }).SetupWithManager(mgr); err != nil { - klog.ErrorS(err, "Unable to create MemberCluster controller") - exitWithErrorFunc() + discoverClient := discovery.NewDiscoveryClientForConfigOrDie(hubConfig) + gvk := clusterv1beta1.GroupVersion.WithKind(clusterv1beta1.MemberClusterKind) + if utils.CheckCRDInstalled(discoverClient, gvk) == nil { + klog.V(1).InfoS("Start to setup MemberCluster controller") + if err := (&membercluster.Reconciler{ + Client: mgr.GetClient(), + Recorder: mgr.GetEventRecorderFor(membercluster.ControllerName), + ForceDeleteWaitTime: *forceDeleteWaitTime, + }).SetupWithManager(mgr); err != nil { + klog.ErrorS(err, "Unable to create MemberCluster controller") + exitWithErrorFunc() + } } klog.V(1).InfoS("Starting ServiceExportImport controller manager") diff --git a/go.mod b/go.mod index 90b7ccdc..25c06299 100644 --- a/go.mod +++ b/go.mod @@ -73,7 +73,13 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.30.2 // indirect k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b // indirect + k8s.io/metrics v0.25.2 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect + sigs.k8s.io/work-api v0.0.0-20220407021756-586d707fdb2c // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +// Fleet repo is using a custom version of work-api. +// Without the replace the compile will fail. +replace sigs.k8s.io/work-api => github.com/Azure/k8s-work-api v0.5.0 diff --git a/go.sum b/go.sum index 522759cb..987d2a39 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xP github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager v1.3.0 h1:e3kTG23M5ps+DjvPolK4dcgohDY8sHsXU7zrdHj1WzY= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager v1.3.0/go.mod h1:Os5dq8Cvvz97rJauZhZJAfKHN+OEvF/0nVmHzF4aVys= +github.com/Azure/k8s-work-api v0.5.0 h1:DVOBt68NFTEVVV+vzz82WdTm4lroXuMd9ktfrfb/kU0= +github.com/Azure/k8s-work-api v0.5.0/go.mod h1:CQiDOlNvMeKvGVer80PtvbW9X1cXq7EID9aMXyxkqPU= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -189,6 +191,8 @@ k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b h1:Q9xmGWBvOGd8UJyccgpYlLosk/JlfP3xQLNkQlHJeXw= k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b/go.mod h1:UxDHUPsUwTOOxSU+oXURfFBcAS6JwiRXTYqYwfuGowc= +k8s.io/metrics v0.25.2 h1:105TuPaIFfr4EHzN56WwZJO7r1UesuDytNTzeMqGySo= +k8s.io/metrics v0.25.2/go.mod h1:4NDAauOuEJ+NWO2+hWkhFE4rWBx/plLWJOYU3vGl0sA= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw=