Skip to content

Commit

Permalink
remove some client global vars
Browse files Browse the repository at this point in the history
Signed-off-by: rambohe-ch <[email protected]>
  • Loading branch information
rambohe-ch committed Aug 16, 2023
1 parent 96c32a7 commit 9692582
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 310 deletions.
9 changes: 0 additions & 9 deletions cmd/yurt-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
"github.com/openyurtio/openyurt/cmd/yurt-manager/app/options"
"github.com/openyurtio/openyurt/pkg/apis"
extclient "github.com/openyurtio/openyurt/pkg/client"
"github.com/openyurtio/openyurt/pkg/controller"
"github.com/openyurtio/openyurt/pkg/profile"
"github.com/openyurtio/openyurt/pkg/projectinfo"
Expand Down Expand Up @@ -151,16 +150,8 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {

ctx := ctrl.SetupSignalHandler()
cfg := ctrl.GetConfigOrDie()

setRestConfig(cfg, c)

setupLog.Info("new clientset registry")
err := extclient.NewRegistry(cfg)
if err != nil {
setupLog.Error(err, "unable to init yurt-manager clientset and informer")
os.Exit(1)
}

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: c.ComponentConfig.Generic.MetricsAddr,
Expand Down
57 changes: 0 additions & 57 deletions pkg/client/generic_client.go

This file was deleted.

56 changes: 0 additions & 56 deletions pkg/client/registry.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import (

appconfig "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
k8sutil "github.com/openyurtio/openyurt/pkg/controller/daemonpodupdater/kubernetes"
utilclient "github.com/openyurtio/openyurt/pkg/util/client"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

func init() {
Expand Down Expand Up @@ -103,9 +101,6 @@ func Format(format string, args ...interface{}) string {
// Add creates a new Daemonpodupdater Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *appconfig.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
return nil
}
klog.Infof("daemonupdater-controller add controller %s", controllerKind.String())
return add(mgr, newReconciler(c, mgr))
}
Expand All @@ -123,7 +118,7 @@ type ReconcileDaemonpodupdater struct {
// newReconciler returns a new reconcile.Reconciler
func newReconciler(_ *appconfig.CompletedConfig, mgr manager.Manager) reconcile.Reconciler {
return &ReconcileDaemonpodupdater{
Client: utilclient.NewClientFromManager(mgr, ControllerName),
Client: mgr.GetClient(),
expectations: k8sutil.NewControllerExpectations(),
recorder: mgr.GetEventRecorderFor(ControllerName),
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/platformadmin/platformadmin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import (
iotv1alpha2 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha2"
"github.com/openyurtio/openyurt/pkg/controller/platformadmin/config"
util "github.com/openyurtio/openyurt/pkg/controller/platformadmin/utils"
utilclient "github.com/openyurtio/openyurt/pkg/util/client"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

func init() {
Expand All @@ -64,7 +62,7 @@ func Format(format string, args ...interface{}) string {

var (
concurrentReconciles = 3
controllerKind = iotv1alpha2.SchemeGroupVersion.WithKind("PlatformAdmin")
controllerResource = iotv1alpha2.SchemeGroupVersion.WithResource("platformadmins")
)

const (
Expand Down Expand Up @@ -121,18 +119,19 @@ var _ reconcile.Reconciler = &ReconcilePlatformAdmin{}
// Add creates a new PlatformAdmin Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *appconfig.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
return nil
if _, err := mgr.GetRESTMapper().KindFor(controllerResource); err != nil {
klog.Infof("resource %s doesn't exist", controllerResource.String())
return err
}

klog.Infof("platformadmin-controller add controller %s", controllerKind.String())
klog.Infof("platformadmin-controller add controller %s", controllerResource.String())
return add(mgr, newReconciler(c, mgr))
}

// newReconciler returns a new reconcile.Reconciler
func newReconciler(c *appconfig.CompletedConfig, mgr manager.Manager) reconcile.Reconciler {
return &ReconcilePlatformAdmin{
Client: utilclient.NewClientFromManager(mgr, ControllerName),
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
recorder: mgr.GetEventRecorderFor(ControllerName),
yamlSerializer: kjson.NewSerializerWithOptions(kjson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, kjson.SerializerOptions{Yaml: true, Pretty: true}),
Expand Down
15 changes: 7 additions & 8 deletions pkg/controller/raven/gatewaypickup/gateway_pickup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ import (
"github.com/openyurtio/openyurt/pkg/controller/raven/gatewaypickup/config"
"github.com/openyurtio/openyurt/pkg/controller/raven/utils"
nodeutil "github.com/openyurtio/openyurt/pkg/controller/util/node"
utilclient "github.com/openyurtio/openyurt/pkg/util/client"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

var (
controllerKind = ravenv1beta1.SchemeGroupVersion.WithKind("Gateway")
controllerResource = ravenv1beta1.SchemeGroupVersion.WithResource("gateways")
)

func Format(format string, args ...interface{}) string {
Expand All @@ -68,10 +66,11 @@ const (
// Add creates a new Gateway Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *appconfig.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
return nil
if _, err := mgr.GetRESTMapper().KindFor(controllerResource); err != nil {
klog.Infof("resource %s doesn't exist", controllerResource.String())
return err
}
klog.Infof("raven-gateway-controller add controller %s", controllerKind.String())
klog.Infof("raven-gateway-controller add controller %s", controllerResource.String())
return add(mgr, newReconciler(c, mgr))
}

Expand All @@ -88,7 +87,7 @@ type ReconcileGateway struct {
// newReconciler returns a new reconcile.Reconciler
func newReconciler(c *appconfig.CompletedConfig, mgr manager.Manager) reconcile.Reconciler {
return &ReconcileGateway{
Client: utilclient.NewClientFromManager(mgr, common.GatewayPickupControllerName),
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
recorder: mgr.GetEventRecorderFor(common.GatewayPickupControllerName),
Configration: c.ComponentConfig.GatewayPickupController,
Expand Down Expand Up @@ -117,7 +116,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

err = c.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &EnqueueGatewayForRavenConfig{client: utilclient.NewClientFromManager(mgr, "raven-config")}, predicate.NewPredicateFuncs(
err = c.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &EnqueueGatewayForRavenConfig{client: mgr.GetClient()}, predicate.NewPredicateFuncs(
func(object client.Object) bool {
cm, ok := object.(*corev1.ConfigMap)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
appconfig "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
common "github.com/openyurtio/openyurt/pkg/controller/servicetopology"
"github.com/openyurtio/openyurt/pkg/controller/servicetopology/adapter"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

func init() {
Expand All @@ -53,10 +52,6 @@ func Format(format string, args ...interface{}) string {
// Add creates a new Servicetopology endpoints Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *appconfig.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
return nil
}

klog.Infof("servicetopology-endpoints-controller add controller %s", controllerKind.String())
return add(mgr, newReconciler(c, mgr))
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/yurtappdaemon/yurtappdaemon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ import (
unitv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
"github.com/openyurtio/openyurt/pkg/controller/util"
"github.com/openyurtio/openyurt/pkg/controller/yurtappdaemon/workloadcontroller"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

var (
concurrentReconciles = 3
controllerKind = unitv1alpha1.SchemeGroupVersion.WithKind("YurtAppDaemon")
controllerResource = unitv1alpha1.SchemeGroupVersion.WithResource("yurtappdaemons")
)

const (
Expand Down Expand Up @@ -74,12 +73,12 @@ func Format(format string, args ...interface{}) string {
// The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *config.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
klog.Errorf(Format("DiscoverGVK error"))
return nil
if _, err := mgr.GetRESTMapper().KindFor(controllerResource); err != nil {
klog.Infof("resource %s doesn't exist", controllerResource.String())
return err
}

klog.Infof("yurtappdaemon-controller add controller %s", controllerKind.String())
klog.Infof("yurtappdaemon-controller add controller %s", controllerResource.String())
return add(mgr, newReconciler(mgr))
}

Expand Down
13 changes: 5 additions & 8 deletions pkg/controller/yurtappset/yurtappset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
unitv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
"github.com/openyurtio/openyurt/pkg/controller/yurtappset/adapter"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

func init() {
Expand All @@ -52,7 +51,7 @@ func init() {

var (
concurrentReconciles = 3
controllerKind = unitv1alpha1.SchemeGroupVersion.WithKind("YurtAppSet")
controllerResource = unitv1alpha1.SchemeGroupVersion.WithResource("yurtappsets")
)

const (
Expand All @@ -75,19 +74,17 @@ func Format(format string, args ...interface{}) string {
// Add creates a new YurtAppSet Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *config.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
klog.Errorf(Format("DiscoverGVK error"))
return nil
if _, err := mgr.GetRESTMapper().KindFor(controllerResource); err != nil {
klog.Infof("resource %s doesn't exist", controllerResource.String())
return err
}

klog.Infof("yurtappset-controller add controller %s", controllerKind.String())
klog.Infof("yurtappset-controller add controller %s", controllerResource.String())
return add(mgr, newReconciler(c, mgr))
}

// newReconciler returns a new reconcile.Reconciler
func newReconciler(c *config.CompletedConfig, mgr manager.Manager) reconcile.Reconciler {
klog.Infof("yurtappset-controller newReconciler %s", controllerKind.String())

return &ReconcileYurtAppSet{
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/yurtstaticset/yurtstaticset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import (
"github.com/openyurtio/openyurt/pkg/controller/yurtstaticset/config"
"github.com/openyurtio/openyurt/pkg/controller/yurtstaticset/upgradeinfo"
"github.com/openyurtio/openyurt/pkg/controller/yurtstaticset/util"
utilclient "github.com/openyurtio/openyurt/pkg/util/client"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

func init() {
Expand All @@ -55,7 +53,7 @@ func init() {

var (
concurrentReconciles = 3
controllerKind = appsv1alpha1.SchemeGroupVersion.WithKind("YurtStaticSet")
controllerResource = appsv1alpha1.SchemeGroupVersion.WithResource("yurtstaticsets")
True = true
)

Expand Down Expand Up @@ -128,11 +126,12 @@ func Format(format string, args ...interface{}) string {
// Add creates a new YurtStaticSet Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(c *appconfig.CompletedConfig, mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) {
return nil
if _, err := mgr.GetRESTMapper().KindFor(controllerResource); err != nil {
klog.Infof("resource %s doesn't exist", controllerResource.String())
return err
}

klog.Infof("yurtstaticset-controller add controller %s", controllerKind.String())
klog.Infof("yurtstaticset-controller add controller %s", controllerResource.String())
return add(mgr, newReconciler(c, mgr))
}

Expand All @@ -149,7 +148,7 @@ type ReconcileYurtStaticSet struct {
// newReconciler returns a new reconcile.Reconciler
func newReconciler(c *appconfig.CompletedConfig, mgr manager.Manager) reconcile.Reconciler {
return &ReconcileYurtStaticSet{
Client: utilclient.NewClientFromManager(mgr, ControllerName),
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
recorder: mgr.GetEventRecorderFor(ControllerName),
Configuration: c.ComponentConfig.YurtStaticSetController,
Expand Down
Loading

0 comments on commit 9692582

Please sign in to comment.