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 <linbo.hlb@alibaba-inc.com>
  • Loading branch information
rambohe-ch committed Aug 15, 2023
1 parent 271f774 commit 243d7dc
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 268 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 @@ -51,7 +51,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 +102,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 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
17 changes: 8 additions & 9 deletions pkg/controller/raven/gateway/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ import (
"github.com/openyurtio/openyurt/pkg/controller/raven/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 = ravenv1alpha1.SchemeGroupVersion.WithKind("Gateway")
controllerResource = ravenv1alpha1.SchemeGroupVersion.WithResource("gateways")
)

func Format(format string, args ...interface{}) string {
Expand All @@ -59,14 +57,15 @@ func Format(format string, args ...interface{}) string {
// 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

Check warning on line 62 in pkg/controller/raven/gateway/gateway_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/raven/gateway/gateway_controller.go#L60-L62

Added lines #L60 - L62 were not covered by tests
}

// init global variables
cfg := c.ComponentConfig.Generic
ravenv1alpha1.ServiceNamespacedName.Namespace = cfg.WorkingNamespace
ravenv1alpha1.ServiceNamespacedName.Namespace = c.ComponentConfig.Generic.WorkingNamespace

Check warning on line 66 in pkg/controller/raven/gateway/gateway_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/raven/gateway/gateway_controller.go#L66

Added line #L66 was not covered by tests

klog.Infof("ravenl3-gateway-controller add controller %s", controllerKind.String())
klog.Infof("ravenl3-gateway-controller add controller %s", controllerResource.String())

Check warning on line 68 in pkg/controller/raven/gateway/gateway_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/raven/gateway/gateway_controller.go#L68

Added line #L68 was not covered by tests
return add(mgr, newReconciler(c, mgr))
}

Expand All @@ -83,7 +82,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.ControllerName),
Client: mgr.GetClient(),

Check warning on line 85 in pkg/controller/raven/gateway/gateway_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/raven/gateway/gateway_controller.go#L85

Added line #L85 was not covered by tests
scheme: mgr.GetScheme(),
recorder: mgr.GetEventRecorderFor(common.ControllerName),
Configration: c.ComponentConfig.GatewayController,
Expand Down
8 changes: 1 addition & 7 deletions pkg/controller/raven/service/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import (
ravenv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/raven/v1alpha1"
common "github.com/openyurtio/openyurt/pkg/controller/raven"
"github.com/openyurtio/openyurt/pkg/controller/raven/utils"
utilclient "github.com/openyurtio/openyurt/pkg/util/client"
utildiscovery "github.com/openyurtio/openyurt/pkg/util/discovery"
)

var (
Expand All @@ -57,10 +55,6 @@ func Format(format string, args ...interface{}) string {
// Add creates a new Service 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("ravenl3-service-controller add controller %s", controllerKind.String())
return add(mgr, newReconciler(c, mgr))
}
Expand All @@ -77,7 +71,7 @@ type ReconcileService struct {
// newReconciler returns a new reconcile.Reconciler
func newReconciler(c *appconfig.CompletedConfig, mgr manager.Manager) reconcile.Reconciler {
return &ReconcileService{
Client: utilclient.NewClientFromManager(mgr, common.ControllerName),
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
recorder: mgr.GetEventRecorderFor(common.ControllerName),
}
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

Check warning on line 78 in pkg/controller/yurtappdaemon/yurtappdaemon_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/yurtappdaemon/yurtappdaemon_controller.go#L76-L78

Added lines #L76 - L78 were not covered by tests
}

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

Check warning on line 81 in pkg/controller/yurtappdaemon/yurtappdaemon_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/yurtappdaemon/yurtappdaemon_controller.go#L81

Added line #L81 was not covered by tests
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

Check warning on line 79 in pkg/controller/yurtappset/yurtappset_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/yurtappset/yurtappset_controller.go#L77-L79

Added lines #L77 - L79 were not covered by tests
}

klog.Infof("yurtappset-controller add controller %s", controllerKind.String())
klog.Infof("yurtappset-controller add controller %s", controllerResource.String())

Check warning on line 82 in pkg/controller/yurtappset/yurtappset_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/yurtappset/yurtappset_controller.go#L82

Added line #L82 was not covered by tests
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
Loading

0 comments on commit 243d7dc

Please sign in to comment.