Skip to content

Commit

Permalink
fix: Enable v1beta1 MC controller when v1beta1 API exists (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru authored Sep 27, 2024
1 parent b4ff5d7 commit d1904ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
25 changes: 16 additions & 9 deletions cmd/hub-net-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down

0 comments on commit d1904ca

Please sign in to comment.