From 4917cbee6bd0a46e04801f81f9b52b0515a793db Mon Sep 17 00:00:00 2001 From: rambohe-ch Date: Mon, 14 Aug 2023 17:32:14 +0800 Subject: [PATCH] use dynamicinformerfactory to get nodepool and remove yurt-app-manager-api dependencies --- cmd/yurthub/app/config/config.go | 100 +-- cmd/yurthub/app/start.go | 2 +- go.mod | 1 - go.sum | 9 - .../apps/well_known_labels_annotations.go | 1 + pkg/util/kubeconfig/kubeconfig.go | 17 - pkg/util/kubeconfig/kubeconfig_test.go | 2 - .../kubeadm/app/util/apiclient/idempotency.go | 32 +- pkg/yurtadm/cmd/join/join.go | 12 +- pkg/yurthub/filter/initializer/initializer.go | 18 +- .../filter/initializer/initializer_test.go | 21 +- pkg/yurthub/filter/manager/manager.go | 10 +- pkg/yurthub/filter/manager/manager_test.go | 19 +- .../filter/nodeportisolation/filter.go | 2 +- pkg/yurthub/filter/servicetopology/filter.go | 42 +- .../filter/servicetopology/filter_test.go | 591 +++++++++--------- 16 files changed, 423 insertions(+), 456 deletions(-) diff --git a/cmd/yurthub/app/config/config.go b/cmd/yurthub/app/config/config.go index 06529a69fc5..22255987b70 100644 --- a/cmd/yurthub/app/config/config.go +++ b/cmd/yurthub/app/config/config.go @@ -28,15 +28,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/apimachinery/pkg/watch" apiserver "k8s.io/apiserver/pkg/server" "k8s.io/apiserver/pkg/server/dynamiccertificates" apiserveroptions "k8s.io/apiserver/pkg/server/options" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/informers" coreinformers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - core "k8s.io/client-go/testing" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/clientcmd" componentbaseconfig "k8s.io/component-base/config" @@ -47,18 +47,12 @@ import ( "github.com/openyurtio/openyurt/pkg/yurthub/cachemanager" "github.com/openyurtio/openyurt/pkg/yurthub/certificate" certificatemgr "github.com/openyurtio/openyurt/pkg/yurthub/certificate/manager" - "github.com/openyurtio/openyurt/pkg/yurthub/filter" "github.com/openyurtio/openyurt/pkg/yurthub/filter/manager" "github.com/openyurtio/openyurt/pkg/yurthub/kubernetes/meta" "github.com/openyurtio/openyurt/pkg/yurthub/kubernetes/serializer" "github.com/openyurtio/openyurt/pkg/yurthub/network" "github.com/openyurtio/openyurt/pkg/yurthub/storage/disk" "github.com/openyurtio/openyurt/pkg/yurthub/util" - yurtcorev1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1" - yurtclientset "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned" - "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned/fake" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" - yurtv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions/apps/v1alpha1" ) // YurtHubConfiguration represents configuration of yurthub @@ -77,7 +71,7 @@ type YurtHubConfiguration struct { SerializerManager *serializer.SerializerManager RESTMapperManager *meta.RESTMapperManager SharedFactory informers.SharedInformerFactory - YurtSharedFactory yurtinformers.SharedInformerFactory + NodePoolInformerFactory dynamicinformer.DynamicSharedInformerFactory WorkingMode util.WorkingMode KubeletHealthGracePeriod time.Duration FilterManager *manager.Manager @@ -132,13 +126,13 @@ func Complete(options *options.YurtHubOptions) (*YurtHubConfiguration, error) { } workingMode := util.WorkingMode(options.WorkingMode) - proxiedClient, sharedFactory, yurtSharedFactory, err := createClientAndSharedInformers(fmt.Sprintf("http://%s:%d", options.YurtHubProxyHost, options.YurtHubProxyPort), options.EnableNodePool) + proxiedClient, sharedFactory, dynamicSharedFactory, err := createClientAndSharedInformers(fmt.Sprintf("http://%s:%d", options.YurtHubProxyHost, options.YurtHubProxyPort), options.NodePoolName) if err != nil { return nil, err } tenantNs := util.ParseTenantNsFromOrgs(options.YurtHubCertOrganizations) - registerInformers(options, sharedFactory, yurtSharedFactory, workingMode, tenantNs) - filterManager, err := manager.NewFilterManager(options, sharedFactory, yurtSharedFactory, proxiedClient, serializerManager, us[0].Host) + registerInformers(options, sharedFactory, workingMode, tenantNs) + filterManager, err := manager.NewFilterManager(options, sharedFactory, dynamicSharedFactory, proxiedClient, serializerManager, us[0].Host) if err != nil { klog.Errorf("could not create filter manager, %v", err) return nil, err @@ -160,7 +154,7 @@ func Complete(options *options.YurtHubOptions) (*YurtHubConfiguration, error) { SerializerManager: serializerManager, RESTMapperManager: restMapperManager, SharedFactory: sharedFactory, - YurtSharedFactory: yurtSharedFactory, + NodePoolInformerFactory: dynamicSharedFactory, KubeletHealthGracePeriod: options.KubeletHealthGracePeriod, FilterManager: filterManager, MinRequestTimeout: options.MinRequestTimeout, @@ -241,9 +235,8 @@ func parseRemoteServers(serverAddr string) ([]*url.URL, error) { } // createClientAndSharedInformers create kubeclient and sharedInformers from the given proxyAddr. -func createClientAndSharedInformers(proxyAddr string, enableNodePool bool) (kubernetes.Interface, informers.SharedInformerFactory, yurtinformers.SharedInformerFactory, error) { +func createClientAndSharedInformers(proxyAddr string, nodePoolName string) (kubernetes.Interface, informers.SharedInformerFactory, dynamicinformer.DynamicSharedInformerFactory, error) { var kubeConfig *rest.Config - var yurtClient yurtclientset.Interface var err error kubeConfig, err = clientcmd.BuildConfigFromFlags(proxyAddr, "") if err != nil { @@ -255,53 +248,27 @@ func createClientAndSharedInformers(proxyAddr string, enableNodePool bool) (kube return nil, nil, nil, err } - fakeYurtClient := &fake.Clientset{} - fakeWatch := watch.NewFake() - fakeYurtClient.AddWatchReactor("nodepools", core.DefaultWatchReactor(fakeWatch, nil)) - // init yurtClient by fake client - yurtClient = fakeYurtClient - if enableNodePool { - yurtClient, err = yurtclientset.NewForConfig(kubeConfig) - if err != nil { - return nil, nil, nil, err - } + dynamicClient, err := dynamic.NewForConfig(kubeConfig) + if err != nil { + return nil, nil, nil, err } - return client, informers.NewSharedInformerFactory(client, 24*time.Hour), - yurtinformers.NewSharedInformerFactory(yurtClient, 24*time.Hour), nil + dynamicInformerFactory := dynamicinformer.NewDynamicSharedInformerFactory(dynamicClient, 24*time.Hour) + if len(nodePoolName) != 0 { + dynamicInformerFactory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynamicClient, 24*time.Hour, metav1.NamespaceAll, func(options *metav1.ListOptions) { + options.FieldSelector = fields.Set{"metadata.name": nodePoolName}.String() + }) + } + + return client, informers.NewSharedInformerFactory(client, 24*time.Hour), dynamicInformerFactory, nil } -// registerInformers reconstruct node/nodePool/configmap informers +// registerInformers reconstruct configmap/secret/pod informers func registerInformers(options *options.YurtHubOptions, informerFactory informers.SharedInformerFactory, - yurtInformerFactory yurtinformers.SharedInformerFactory, workingMode util.WorkingMode, tenantNs string) { - // skip construct node/nodePool informers if service topology filter disabled - serviceTopologyFilterEnabled := isServiceTopologyFilterEnabled(options) - if serviceTopologyFilterEnabled { - if workingMode == util.WorkingModeCloud { - newNodeInformer := func(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - tweakListOptions := func(ops *metav1.ListOptions) { - ops.FieldSelector = fields.Set{"metadata.name": options.NodeName}.String() - } - return coreinformers.NewFilteredNodeInformer(client, resyncPeriod, nil, tweakListOptions) - } - informerFactory.InformerFor(&corev1.Node{}, newNodeInformer) - } - - if len(options.NodePoolName) != 0 { - newNodePoolInformer := func(client yurtclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - tweakListOptions := func(ops *metav1.ListOptions) { - ops.FieldSelector = fields.Set{"metadata.name": options.NodePoolName}.String() - } - return yurtv1alpha1.NewFilteredNodePoolInformer(client, resyncPeriod, nil, tweakListOptions) - } - - yurtInformerFactory.InformerFor(&yurtcorev1alpha1.NodePool{}, newNodePoolInformer) - } - } - + // configmap informer is used by Yurthub filter approver newConfigmapInformer := func(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { tweakListOptions := func(options *metav1.ListOptions) { options.FieldSelector = fields.Set{"metadata.name": util.YurthubConfigMapName}.String() @@ -310,6 +277,7 @@ func registerInformers(options *options.YurtHubOptions, } informerFactory.InformerFor(&corev1.ConfigMap{}, newConfigmapInformer) + // secret informer is used by Tenant manager, this feature is not enabled in general. if tenantNs != "" { newSecretInformer := func(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { return coreinformers.NewFilteredSecretInformer(client, tenantNs, resyncPeriod, nil, nil) @@ -317,6 +285,7 @@ func registerInformers(options *options.YurtHubOptions, informerFactory.InformerFor(&corev1.Secret{}, newSecretInformer) } + // pod informer is used by OTA updater on cloud working mode if workingMode == util.WorkingModeCloud { newPodInformer := func(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { listOptions := func(ops *metav1.ListOptions) { @@ -328,29 +297,6 @@ func registerInformers(options *options.YurtHubOptions, } } -// isServiceTopologyFilterEnabled is used to verify the service topology filter should be enabled or not. -func isServiceTopologyFilterEnabled(options *options.YurtHubOptions) bool { - if !options.EnableResourceFilter { - return false - } - - for _, filterName := range options.DisabledResourceFilters { - if filterName == filter.ServiceTopologyFilterName { - return false - } - } - - if options.WorkingMode == string(util.WorkingModeCloud) { - for i := range filter.DisabledInCloudMode { - if filter.DisabledInCloudMode[i] == filter.ServiceTopologyFilterName { - return false - } - } - } - - return true -} - func prepareServerServing(options *options.YurtHubOptions, certMgr certificate.YurtCertificateManager, cfg *YurtHubConfiguration) error { if err := (&apiserveroptions.DeprecatedInsecureServingOptions{ BindAddress: net.ParseIP(options.YurtHubHost), diff --git a/cmd/yurthub/app/start.go b/cmd/yurthub/app/start.go index ba6b166ede8..14e101a2245 100644 --- a/cmd/yurthub/app/start.go +++ b/cmd/yurthub/app/start.go @@ -176,7 +176,7 @@ func Run(ctx context.Context, cfg *config.YurtHubConfiguration) error { // Start the informer factory if all informers have been registered cfg.SharedFactory.Start(ctx.Done()) - cfg.YurtSharedFactory.Start(ctx.Done()) + cfg.NodePoolInformerFactory.Start(ctx.Done()) klog.Infof("%d. new reverse proxy handler for remote servers", trace) yurtProxyHandler, err := proxy.NewYurtReverseProxyHandler( diff --git a/go.mod b/go.mod index 53dcd2e2ad0..b26335a009b 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/onsi/ginkgo/v2 v2.1.4 github.com/onsi/gomega v1.19.0 github.com/opencontainers/selinux v1.11.0 - github.com/openyurtio/yurt-app-manager-api v0.6.0 github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 github.com/projectcalico/api v0.0.0-20230222223746-44aa60c2201f diff --git a/go.sum b/go.sum index c77bd68f7d3..bf7f5a02e50 100644 --- a/go.sum +++ b/go.sum @@ -232,7 +232,6 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/zapr v0.4.0 h1:uc1uML3hRYL9/ZZPdgHS/n8Nzo+eaYL/Efxkkamf7OM= @@ -381,7 +380,6 @@ github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= @@ -524,7 +522,6 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= @@ -532,7 +529,6 @@ github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47 github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= @@ -557,8 +553,6 @@ github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b h1:Ff github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU= github.com/openyurtio/apiserver-network-proxy v0.1.0 h1:uJI6LeAHmkQL0zV1+NIbgRsx2ayzsPfMA2bd1gROypc= github.com/openyurtio/apiserver-network-proxy v0.1.0/go.mod h1:X5Au3jBNIgYL2uK0IHeNGnZqlUlVSCFQhi/npPgkKRg= -github.com/openyurtio/yurt-app-manager-api v0.6.0 h1:GoayIUkdITBufJirU94dvyknFFG4On1T7XcDvsqCWaQ= -github.com/openyurtio/yurt-app-manager-api v0.6.0/go.mod h1:Ql/n89HmezW7s0d2Cyq9P3hl2MEvvjjv3xxPkLVzz10= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= @@ -1188,7 +1182,6 @@ k8s.io/csi-translation-lib v0.22.3/go.mod h1:YkdI+scWhZJQeA26iNg9XrKO3LhLz6dAcRK k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= -k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM= k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec= k8s.io/kube-aggregator v0.22.3/go.mod h1:TIpLq1HvR/S4y75i3y+4q9ik3ZvgyaDz72CBfDS0A6E= @@ -1208,7 +1201,6 @@ k8s.io/pod-security-admission v0.22.3/go.mod h1:xtkf/UhVWICokQLSDvD+8plfGkTQW4VT k8s.io/sample-apiserver v0.22.3/go.mod h1:HuEOdD/pT5R7gKNr2REb62uabZaJuFZyY3wUd86nFCA= k8s.io/system-validators v1.5.0/go.mod h1:bPldcLgkIUK22ALflnsXk8pvkTEndYdNuaHH6gRrl0Q= k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20210527160623-6fdb442a123b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b h1:wxEMGetGMur3J1xuGLQY7GEQYg9bZxKn3tKo5k/eYcs= @@ -1224,7 +1216,6 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22 h1:fmRfl9WJ4ApJn7LxNuED4m0t18qivVQOxP6aAYG9J6c= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= -sigs.k8s.io/controller-runtime v0.9.0/go.mod h1:TgkfvrhhEw3PlI0BRL/5xM+89y3/yc0ZDfdbTl84si8= sigs.k8s.io/controller-runtime v0.10.3 h1:s5Ttmw/B4AuIbwrXD3sfBkXwnPMMWrqpVj4WRt1dano= sigs.k8s.io/controller-runtime v0.10.3/go.mod h1:CQp8eyUQZ/Q7PJvnIrB6/hgfTC1kBkGylwsLgOQi1WY= sigs.k8s.io/kustomize/api v0.8.11 h1:LzQzlq6Z023b+mBtc6v72N2mSHYmN8x7ssgbf/hv0H8= diff --git a/pkg/apis/apps/well_known_labels_annotations.go b/pkg/apis/apps/well_known_labels_annotations.go index a712a7b6676..7118efd71d4 100644 --- a/pkg/apis/apps/well_known_labels_annotations.go +++ b/pkg/apis/apps/well_known_labels_annotations.go @@ -40,6 +40,7 @@ const ( // LabelCurrentNodePool indicates which nodepool the node is currently // belonging to LabelCurrentNodePool = "apps.openyurt.io/nodepool" + NodePoolLabel = "apps.openyurt.io/nodepool" AnnotationPrevAttrs = "nodepool.openyurt.io/previous-attributes" diff --git a/pkg/util/kubeconfig/kubeconfig.go b/pkg/util/kubeconfig/kubeconfig.go index ca713622390..9625d2d3351 100644 --- a/pkg/util/kubeconfig/kubeconfig.go +++ b/pkg/util/kubeconfig/kubeconfig.go @@ -24,8 +24,6 @@ import ( clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" - - yurtclientset "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned" ) // CreateBasic creates a basic, general KubeConfig object that then can be extended @@ -127,18 +125,3 @@ func GetAuthInfoFromKubeConfig(config *clientcmdapi.Config) *clientcmdapi.AuthIn } return nil } - -// ToYurtClientSet converts a KubeConfig object to a yurtClient -func ToYurtClientSet(config *clientcmdapi.Config) (yurtclientset.Interface, error) { - overrides := clientcmd.ConfigOverrides{Timeout: "10s"} - clientConfig, err := clientcmd.NewDefaultClientConfig(*config, &overrides).ClientConfig() - if err != nil { - return nil, errors.Wrap(err, "failed to create yurt client configuration from kubeconfig") - } - - client, err := yurtclientset.NewForConfig(clientConfig) - if err != nil { - return nil, errors.Wrap(err, "failed to create yurt client") - } - return client, nil -} diff --git a/pkg/util/kubeconfig/kubeconfig_test.go b/pkg/util/kubeconfig/kubeconfig_test.go index 11d1a075e65..b1cce66144a 100644 --- a/pkg/util/kubeconfig/kubeconfig_test.go +++ b/pkg/util/kubeconfig/kubeconfig_test.go @@ -183,8 +183,6 @@ func TestWriteKubeconfigToDisk(t *testing.T) { newFile, ) } - client, err := ToYurtClientSet(c) - t.Log(client, err) }) } } diff --git a/pkg/util/kubernetes/kubeadm/app/util/apiclient/idempotency.go b/pkg/util/kubernetes/kubeadm/app/util/apiclient/idempotency.go index e8d85e2372e..4fecdde5bb7 100644 --- a/pkg/util/kubernetes/kubeadm/app/util/apiclient/idempotency.go +++ b/pkg/util/kubernetes/kubeadm/app/util/apiclient/idempotency.go @@ -24,13 +24,17 @@ import ( rbac "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/dynamic" clientset "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/clientcmd" + clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientsetretry "k8s.io/client-go/util/retry" + "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" "github.com/openyurtio/openyurt/pkg/util/kubernetes/kubeadm/app/constants" - nodepoolv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1" - yurtclientset "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned" ) // ConfigMapMutator is a function that mutates the given ConfigMap and optionally returns an error @@ -134,12 +138,24 @@ func GetConfigMapWithRetry(client clientset.Interface, namespace, name string) ( return nil, lastError } -func GetNodePoolInfoWithRetry(client yurtclientset.Interface, name string) (*nodepoolv1alpha1.NodePool, error) { - var np *nodepoolv1alpha1.NodePool +func GetNodePoolInfoWithRetry(cfg *clientcmdapi.Config, name string) (*v1beta1.NodePool, error) { + gvr := v1beta1.GroupVersion.WithResource("nodepools") + + clientConfig := clientcmd.NewDefaultClientConfig(*cfg, &clientcmd.ConfigOverrides{}) + restConfig, err := clientConfig.ClientConfig() + if err != nil { + return nil, err + } + dynamicClient, err := dynamic.NewForConfig(restConfig) + if err != nil { + return nil, err + } + + var obj *unstructured.Unstructured var lastError error - err := wait.ExponentialBackoff(clientsetretry.DefaultBackoff, func() (bool, error) { + err = wait.ExponentialBackoff(clientsetretry.DefaultBackoff, func() (bool, error) { var err error - np, err = client.AppsV1alpha1().NodePools().Get(context.TODO(), name, metav1.GetOptions{}) + obj, err = dynamicClient.Resource(gvr).Get(context.TODO(), name, metav1.GetOptions{}) if err == nil { return true, nil } @@ -150,6 +166,10 @@ func GetNodePoolInfoWithRetry(client yurtclientset.Interface, name string) (*nod return false, nil }) if err == nil { + np := new(v1beta1.NodePool) + if err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), np); err != nil { + return nil, err + } return np, nil } return nil, lastError diff --git a/pkg/yurtadm/cmd/join/join.go b/pkg/yurtadm/cmd/join/join.go index ee81077a6be..1406c75b88d 100644 --- a/pkg/yurtadm/cmd/join/join.go +++ b/pkg/yurtadm/cmd/join/join.go @@ -30,6 +30,7 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "k8s.io/klog/v2" + "github.com/openyurtio/openyurt/pkg/apis/apps" "github.com/openyurtio/openyurt/pkg/controller/yurtstaticset/util" kubeconfigutil "github.com/openyurtio/openyurt/pkg/util/kubeconfig" "github.com/openyurtio/openyurt/pkg/util/kubernetes/kubeadm/app/util/apiclient" @@ -39,7 +40,6 @@ import ( "github.com/openyurtio/openyurt/pkg/yurtadm/util/edgenode" yurtadmutil "github.com/openyurtio/openyurt/pkg/yurtadm/util/kubernetes" "github.com/openyurtio/openyurt/pkg/yurtadm/util/yurthub" - nodepoolv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1" ) type joinOptions struct { @@ -345,19 +345,13 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) { // check whether specified nodePool exists if len(opt.nodePoolName) != 0 { - yurtClient, err := kubeconfigutil.ToYurtClientSet(cfg) - if err != nil { - klog.Errorf("failed to create yurt client, %v", err) - return nil, err - } - - np, err := apiclient.GetNodePoolInfoWithRetry(yurtClient, opt.nodePoolName) + np, err := apiclient.GetNodePoolInfoWithRetry(cfg, opt.nodePoolName) if err != nil || np == nil { // the specified nodePool not exist, return return nil, errors.Errorf("when --nodepool-name is specified, the specified nodePool should be exist.") } // add nodePool label for node by kubelet - data.nodeLabels[nodepoolv1alpha1.LabelDesiredNodePool] = opt.nodePoolName + data.nodeLabels[apps.NodePoolLabel] = opt.nodePoolName } // check static pods has value and yurtstaticset is already exist diff --git a/pkg/yurthub/filter/initializer/initializer.go b/pkg/yurthub/filter/initializer/initializer.go index 87d0d982185..6049372c4ad 100644 --- a/pkg/yurthub/filter/initializer/initializer.go +++ b/pkg/yurthub/filter/initializer/initializer.go @@ -17,11 +17,11 @@ limitations under the License. package initializer import ( + "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" "github.com/openyurtio/openyurt/pkg/yurthub/filter" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" ) // WantsSharedInformerFactory is an interface for setting SharedInformerFactory @@ -29,9 +29,9 @@ type WantsSharedInformerFactory interface { SetSharedInformerFactory(factory informers.SharedInformerFactory) error } -// WantsYurtSharedInformerFactory is an interface for setting Yurt-App-Manager SharedInformerFactory -type WantsYurtSharedInformerFactory interface { - SetYurtSharedInformerFactory(yurtFactory yurtinformers.SharedInformerFactory) error +// WantsNodePoolInformerFactory is an interface for setting NodePool CRD SharedInformerFactory +type WantsNodePoolInformerFactory interface { + SetNodePoolInformerFactory(factory dynamicinformer.DynamicSharedInformerFactory) error } // WantsNodeName is an interface for setting node name @@ -58,7 +58,7 @@ type WantsKubeClient interface { // genericFilterInitializer is responsible for initializing generic filter type genericFilterInitializer struct { factory informers.SharedInformerFactory - yurtFactory yurtinformers.SharedInformerFactory + nodePoolFactory dynamicinformer.DynamicSharedInformerFactory nodeName string nodePoolName string masterServiceHost string @@ -68,12 +68,12 @@ type genericFilterInitializer struct { // New creates an filterInitializer object func New(factory informers.SharedInformerFactory, - yurtFactory yurtinformers.SharedInformerFactory, + nodePoolFactory dynamicinformer.DynamicSharedInformerFactory, kubeClient kubernetes.Interface, nodeName, nodePoolName, masterServiceHost, masterServicePort string) filter.Initializer { return &genericFilterInitializer{ factory: factory, - yurtFactory: yurtFactory, + nodePoolFactory: nodePoolFactory, nodeName: nodeName, nodePoolName: nodePoolName, masterServiceHost: masterServiceHost, @@ -112,8 +112,8 @@ func (fi *genericFilterInitializer) Initialize(ins filter.ObjectFilter) error { } } - if wants, ok := ins.(WantsYurtSharedInformerFactory); ok { - if err := wants.SetYurtSharedInformerFactory(fi.yurtFactory); err != nil { + if wants, ok := ins.(WantsNodePoolInformerFactory); ok { + if err := wants.SetNodePoolInformerFactory(fi.nodePoolFactory); err != nil { return err } } diff --git a/pkg/yurthub/filter/initializer/initializer_test.go b/pkg/yurthub/filter/initializer/initializer_test.go index efda901fb1d..74c1d26f69c 100644 --- a/pkg/yurthub/filter/initializer/initializer_test.go +++ b/pkg/yurthub/filter/initializer/initializer_test.go @@ -24,6 +24,8 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/dynamic/dynamicinformer" + dynamicfake "k8s.io/client-go/dynamic/fake" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" @@ -33,21 +35,22 @@ import ( "github.com/openyurtio/openyurt/pkg/yurthub/filter/masterservice" "github.com/openyurtio/openyurt/pkg/yurthub/filter/nodeportisolation" "github.com/openyurtio/openyurt/pkg/yurthub/filter/servicetopology" - yurtfake "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned/fake" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" ) func TestNew(t *testing.T) { fakeClient := &fake.Clientset{} - fakeYurtClient := &yurtfake.Clientset{} sharedFactory := informers.NewSharedInformerFactory(fakeClient, 24*time.Hour) - yurtSharedFactory := yurtinformers.NewSharedInformerFactory(fakeYurtClient, 24*time.Hour) + + scheme := runtime.NewScheme() + fakeDynamicClient := dynamicfake.NewSimpleDynamicClient(scheme) + nodePoolFactory := dynamicinformer.NewDynamicSharedInformerFactory(fakeDynamicClient, 24*time.Hour) + nodeName := "foo" nodePoolName := "foo-pool" masterServiceHost := "127.0.0.1" masterServicePort := "8080" - obj := New(sharedFactory, yurtSharedFactory, fakeClient, nodeName, nodePoolName, masterServiceHost, masterServicePort) + obj := New(sharedFactory, nodePoolFactory, fakeClient, nodeName, nodePoolName, masterServiceHost, masterServicePort) _, ok := obj.(filter.Initializer) if !ok { t.Errorf("expect a filter Initializer object, but got %v", reflect.TypeOf(obj)) @@ -85,15 +88,17 @@ func TestInitialize(t *testing.T) { }, } fakeClient := &fake.Clientset{} - fakeYurtClient := &yurtfake.Clientset{} sharedFactory := informers.NewSharedInformerFactory(fakeClient, 24*time.Hour) - yurtSharedFactory := yurtinformers.NewSharedInformerFactory(fakeYurtClient, 24*time.Hour) + + scheme := runtime.NewScheme() + fakeDynamicClient := dynamicfake.NewSimpleDynamicClient(scheme) + nodePoolFactory := dynamicinformer.NewDynamicSharedInformerFactory(fakeDynamicClient, 24*time.Hour) nodeName := "foo" nodePoolName := "foo-pool" masterServiceHost := "127.0.0.1" masterServicePort := "8080" - obj := New(sharedFactory, yurtSharedFactory, fakeClient, nodeName, nodePoolName, masterServiceHost, masterServicePort) + obj := New(sharedFactory, nodePoolFactory, fakeClient, nodeName, nodePoolName, masterServiceHost, masterServicePort) for k, tc := range testcases { t.Run(k, func(t *testing.T) { diff --git a/pkg/yurthub/filter/manager/manager.go b/pkg/yurthub/filter/manager/manager.go index bc3d5f5dd91..b50dc3037b8 100644 --- a/pkg/yurthub/filter/manager/manager.go +++ b/pkg/yurthub/filter/manager/manager.go @@ -22,6 +22,7 @@ import ( "strconv" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" @@ -35,7 +36,6 @@ import ( "github.com/openyurtio/openyurt/pkg/yurthub/filter/servicetopology" "github.com/openyurtio/openyurt/pkg/yurthub/kubernetes/serializer" "github.com/openyurtio/openyurt/pkg/yurthub/util" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" ) type Manager struct { @@ -46,7 +46,7 @@ type Manager struct { func NewFilterManager(options *options.YurtHubOptions, sharedFactory informers.SharedInformerFactory, - yurtSharedFactory yurtinformers.SharedInformerFactory, + nodePoolFactory dynamicinformer.DynamicSharedInformerFactory, proxiedClient kubernetes.Interface, serializerManager *serializer.SerializerManager, apiserverAddr string) (*Manager, error) { @@ -70,7 +70,7 @@ func NewFilterManager(options *options.YurtHubOptions, } } - objFilters, err := createObjectFilters(filters, sharedFactory, yurtSharedFactory, proxiedClient, options.NodeName, options.NodePoolName, mutatedMasterServiceHost, mutatedMasterServicePort) + objFilters, err := createObjectFilters(filters, sharedFactory, nodePoolFactory, proxiedClient, options.NodeName, options.NodePoolName, mutatedMasterServiceHost, mutatedMasterServicePort) if err != nil { return nil, err } @@ -113,14 +113,14 @@ func (m *Manager) FindResponseFilter(req *http.Request) (filter.ResponseFilter, // createObjectFilters return all object filters that initializations completed. func createObjectFilters(filters *filter.Filters, sharedFactory informers.SharedInformerFactory, - yurtSharedFactory yurtinformers.SharedInformerFactory, + nodePoolFactory dynamicinformer.DynamicSharedInformerFactory, proxiedClient kubernetes.Interface, nodeName, nodePoolName, mutatedMasterServiceHost, mutatedMasterServicePort string) ([]filter.ObjectFilter, error) { if filters == nil { return nil, nil } - genericInitializer := initializer.New(sharedFactory, yurtSharedFactory, proxiedClient, nodeName, nodePoolName, mutatedMasterServiceHost, mutatedMasterServicePort) + genericInitializer := initializer.New(sharedFactory, nodePoolFactory, proxiedClient, nodeName, nodePoolName, mutatedMasterServiceHost, mutatedMasterServicePort) initializerChain := filter.Initializers{} initializerChain = append(initializerChain, genericInitializer) return filters.NewFromFilters(initializerChain) diff --git a/pkg/yurthub/filter/manager/manager_test.go b/pkg/yurthub/filter/manager/manager_test.go index e702b7cd1b9..9c4e6d31159 100644 --- a/pkg/yurthub/filter/manager/manager_test.go +++ b/pkg/yurthub/filter/manager/manager_test.go @@ -23,23 +23,27 @@ import ( "testing" "time" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/endpoints/filters" "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/client-go/dynamic/dynamicinformer" + dynamicfake "k8s.io/client-go/dynamic/fake" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" "github.com/openyurtio/openyurt/cmd/yurthub/app/options" + "github.com/openyurtio/openyurt/pkg/apis" "github.com/openyurtio/openyurt/pkg/yurthub/filter" "github.com/openyurtio/openyurt/pkg/yurthub/kubernetes/serializer" "github.com/openyurtio/openyurt/pkg/yurthub/proxy/util" - yurtfake "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned/fake" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" ) func TestFindResponseFilter(t *testing.T) { fakeClient := &fake.Clientset{} - fakeYurtClient := &yurtfake.Clientset{} + scheme := runtime.NewScheme() + apis.AddToScheme(scheme) + fakeDynamicClient := dynamicfake.NewSimpleDynamicClient(scheme) serializerManager := serializer.NewSerializerManager() apiserverAddr := "127.0.0.1:6443" @@ -128,18 +132,19 @@ func TestFindResponseFilter(t *testing.T) { } options.DisabledResourceFilters = append(options.DisabledResourceFilters, tt.disabledResourceFilters...) - sharedFactory, yurtSharedFactory := informers.NewSharedInformerFactory(fakeClient, 24*time.Hour), - yurtinformers.NewSharedInformerFactory(fakeYurtClient, 24*time.Hour) + sharedFactory, nodePoolFactory := informers.NewSharedInformerFactory(fakeClient, 24*time.Hour), + dynamicinformer.NewDynamicSharedInformerFactory(fakeDynamicClient, 24*time.Hour) + stopper := make(chan struct{}) defer close(stopper) - mgr, _ := NewFilterManager(options, sharedFactory, yurtSharedFactory, fakeClient, serializerManager, apiserverAddr) + mgr, _ := NewFilterManager(options, sharedFactory, nodePoolFactory, fakeClient, serializerManager, apiserverAddr) if tt.mgrIsNil && mgr == nil { return } sharedFactory.Start(stopper) - yurtSharedFactory.Start(stopper) + nodePoolFactory.Start(stopper) req, err := http.NewRequest(tt.verb, tt.path, nil) if err != nil { diff --git a/pkg/yurthub/filter/nodeportisolation/filter.go b/pkg/yurthub/filter/nodeportisolation/filter.go index d21171f0f20..8ab3f428943 100644 --- a/pkg/yurthub/filter/nodeportisolation/filter.go +++ b/pkg/yurthub/filter/nodeportisolation/filter.go @@ -130,7 +130,7 @@ func (nif *nodePortIsolationFilter) resolveNodePoolName() string { klog.Warningf("skip isolateNodePortService filter, failed to get node(%s), %v", nif.nodeName, err) return nif.nodePoolName } - nif.nodePoolName = node.Labels[apps.LabelDesiredNodePool] + nif.nodePoolName = node.Labels[apps.NodePoolLabel] return nif.nodePoolName } diff --git a/pkg/yurthub/filter/servicetopology/filter.go b/pkg/yurthub/filter/servicetopology/filter.go index 209c1f47610..4e4cf7af76a 100644 --- a/pkg/yurthub/filter/servicetopology/filter.go +++ b/pkg/yurthub/filter/servicetopology/filter.go @@ -23,18 +23,19 @@ import ( discovery "k8s.io/api/discovery/v1" discoveryV1beta1 "k8s.io/api/discovery/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" + "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" "github.com/openyurtio/openyurt/pkg/yurthub/filter" - nodepoolv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" - appslisters "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/listers/apps/v1alpha1" ) const ( @@ -62,7 +63,7 @@ func NewServiceTopologyFilter() (filter.ObjectFilter, error) { type serviceTopologyFilter struct { serviceLister listers.ServiceLister serviceSynced cache.InformerSynced - nodePoolLister appslisters.NodePoolLister + nodePoolLister cache.GenericLister nodePoolSynced cache.InformerSynced nodePoolName string nodeName string @@ -87,9 +88,10 @@ func (stf *serviceTopologyFilter) SetSharedInformerFactory(factory informers.Sha return nil } -func (stf *serviceTopologyFilter) SetYurtSharedInformerFactory(yurtFactory yurtinformers.SharedInformerFactory) error { - stf.nodePoolLister = yurtFactory.Apps().V1alpha1().NodePools().Lister() - stf.nodePoolSynced = yurtFactory.Apps().V1alpha1().NodePools().Informer().HasSynced +func (stf *serviceTopologyFilter) SetNodePoolInformerFactory(dynamicInformerFactory dynamicinformer.DynamicSharedInformerFactory) error { + gvr := v1beta1.GroupVersion.WithResource("nodepools") + stf.nodePoolLister = dynamicInformerFactory.ForResource(gvr).Lister() + stf.nodePoolSynced = dynamicInformerFactory.ForResource(gvr).Informer().HasSynced return nil } @@ -120,7 +122,7 @@ func (stf *serviceTopologyFilter) resolveNodePoolName() string { klog.Warningf("failed to get node(%s) in serviceTopologyFilter filter, %v", stf.nodeName, err) return stf.nodePoolName } - stf.nodePoolName = node.Labels[nodepoolv1alpha1.LabelDesiredNodePool] + stf.nodePoolName = node.Labels[apps.NodePoolLabel] return stf.nodePoolName } @@ -228,11 +230,25 @@ func (stf *serviceTopologyFilter) nodePoolTopologyHandler(obj runtime.Object) ru return stf.nodeTopologyHandler(obj) } - nodePool, err := stf.nodePoolLister.Get(nodePoolName) + runtimeObj, err := stf.nodePoolLister.Get(nodePoolName) if err != nil { klog.Warningf("serviceTopologyFilterHandler: failed to get nodepool %s, err: %v", nodePoolName, err) return obj } + var nodePool *v1beta1.NodePool + switch poolObj := runtimeObj.(type) { + case *v1beta1.NodePool: + nodePool = poolObj + case *unstructured.Unstructured: + nodePool = new(v1beta1.NodePool) + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(poolObj.UnstructuredContent(), nodePool); err != nil { + klog.Warningf("object(%#+v) is not a v1beta1.NodePool", poolObj) + return obj + } + default: + klog.Warningf("object(%#+v) is not a unknown type", poolObj) + return obj + } switch v := obj.(type) { case *discoveryV1beta1.EndpointSlice: @@ -247,7 +263,7 @@ func (stf *serviceTopologyFilter) nodePoolTopologyHandler(obj runtime.Object) ru } // reassembleV1beta1EndpointSlice will discard endpoints that are not on the same node/nodePool for v1beta1.EndpointSlice -func reassembleV1beta1EndpointSlice(endpointSlice *discoveryV1beta1.EndpointSlice, nodeName string, nodePool *nodepoolv1alpha1.NodePool) *discoveryV1beta1.EndpointSlice { +func reassembleV1beta1EndpointSlice(endpointSlice *discoveryV1beta1.EndpointSlice, nodeName string, nodePool *v1beta1.NodePool) *discoveryV1beta1.EndpointSlice { if len(nodeName) != 0 && nodePool != nil { klog.Warningf("reassembleV1beta1EndpointSlice: nodeName(%s) and nodePool can not be set at the same time", nodeName) return endpointSlice @@ -274,7 +290,7 @@ func reassembleV1beta1EndpointSlice(endpointSlice *discoveryV1beta1.EndpointSlic } // reassembleEndpointSlice will discard endpoints that are not on the same node/nodePool for v1.EndpointSlice -func reassembleEndpointSlice(endpointSlice *discovery.EndpointSlice, nodeName string, nodePool *nodepoolv1alpha1.NodePool) *discovery.EndpointSlice { +func reassembleEndpointSlice(endpointSlice *discovery.EndpointSlice, nodeName string, nodePool *v1beta1.NodePool) *discovery.EndpointSlice { if len(nodeName) != 0 && nodePool != nil { klog.Warningf("reassembleEndpointSlice: nodeName(%s) and nodePool can not be set at the same time", nodeName) return endpointSlice @@ -301,7 +317,7 @@ func reassembleEndpointSlice(endpointSlice *discovery.EndpointSlice, nodeName st } // reassembleEndpoints will discard subset that are not on the same node/nodePool for v1.Endpoints -func reassembleEndpoints(endpoints *v1.Endpoints, nodeName string, nodePool *nodepoolv1alpha1.NodePool) *v1.Endpoints { +func reassembleEndpoints(endpoints *v1.Endpoints, nodeName string, nodePool *v1beta1.NodePool) *v1.Endpoints { if len(nodeName) != 0 && nodePool != nil { klog.Warningf("reassembleEndpoints: nodeName(%s) and nodePool can not be set at the same time", nodeName) return endpoints @@ -329,7 +345,7 @@ func reassembleEndpoints(endpoints *v1.Endpoints, nodeName string, nodePool *nod return endpoints } -func filterValidEndpointsAddr(addresses []v1.EndpointAddress, nodeName string, nodePool *nodepoolv1alpha1.NodePool) []v1.EndpointAddress { +func filterValidEndpointsAddr(addresses []v1.EndpointAddress, nodeName string, nodePool *v1beta1.NodePool) []v1.EndpointAddress { var newEpAddresses []v1.EndpointAddress for i := range addresses { if addresses[i].NodeName == nil { diff --git a/pkg/yurthub/filter/servicetopology/filter_test.go b/pkg/yurthub/filter/servicetopology/filter_test.go index 3e234d92abf..01538a86b22 100644 --- a/pkg/yurthub/filter/servicetopology/filter_test.go +++ b/pkg/yurthub/filter/servicetopology/filter_test.go @@ -26,15 +26,18 @@ import ( discoveryV1beta1 "k8s.io/api/discovery/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/dynamic/dynamicinformer" + "k8s.io/client-go/dynamic/fake" "k8s.io/client-go/informers" k8sfake "k8s.io/client-go/kubernetes/fake" + "github.com/openyurtio/openyurt/pkg/apis" + "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" "github.com/openyurtio/openyurt/pkg/util" "github.com/openyurtio/openyurt/pkg/yurthub/filter" - nodepoolv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1" - yurtfake "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned/fake" - yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions" ) func TestName(t *testing.T) { @@ -63,6 +66,11 @@ func TestSupportedResourceAndVerbs(t *testing.T) { } func TestFilter(t *testing.T) { + scheme := runtime.NewScheme() + apis.AddToScheme(scheme) + gvrToListKind := map[schema.GroupVersionResource]string{ + {Group: "apps.openyurt.io", Version: "v1beta1", Resource: "nodepools"}: "NodePoolList", + } currentNodeName := "node1" nodeName2 := "node2" nodeName3 := "node3" @@ -72,7 +80,7 @@ func TestFilter(t *testing.T) { nodeName string responseObject runtime.Object kubeClient *k8sfake.Clientset - yurtClient *yurtfake.Clientset + yurtClient *fake.FakeDynamicClient expectObject runtime.Object }{ "v1beta1.EndpointSliceList: topologyKeys is kubernetes.io/hostname": { @@ -129,7 +137,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -137,7 +145,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -145,7 +153,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -159,29 +167,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -274,7 +282,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -282,7 +290,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -290,7 +298,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -304,29 +312,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -426,7 +434,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -434,7 +442,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -442,7 +450,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -456,29 +464,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -578,7 +586,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -586,7 +594,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -594,7 +602,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -606,29 +614,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -742,7 +750,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -750,7 +758,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -764,28 +772,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -877,7 +885,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -885,7 +893,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -893,7 +901,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -907,29 +915,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -1003,7 +1011,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1011,7 +1019,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1019,7 +1027,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1033,29 +1041,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, @@ -1126,7 +1134,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1134,7 +1142,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1142,7 +1150,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1156,29 +1164,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, @@ -1275,7 +1283,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1283,7 +1291,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1291,7 +1299,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1305,29 +1313,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -1407,7 +1415,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1415,7 +1423,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1423,7 +1431,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1437,29 +1445,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -1545,7 +1553,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1553,7 +1561,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1561,7 +1569,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1575,29 +1583,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -1683,7 +1691,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1691,7 +1699,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1699,7 +1707,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1711,29 +1719,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -1831,7 +1839,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1839,7 +1847,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1853,28 +1861,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -1942,7 +1950,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -1950,7 +1958,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1958,7 +1966,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -1972,28 +1980,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", @@ -2048,7 +2056,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2056,7 +2064,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2064,7 +2072,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2078,28 +2086,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", @@ -2163,7 +2171,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2171,7 +2179,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2179,7 +2187,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2193,29 +2201,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -2293,7 +2301,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2301,7 +2309,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2309,7 +2317,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2323,29 +2331,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -2427,7 +2435,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2435,7 +2443,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2443,7 +2451,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2457,29 +2465,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -2561,7 +2569,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2569,7 +2577,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2577,7 +2585,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2589,29 +2597,29 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -2703,7 +2711,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2711,7 +2719,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2725,28 +2733,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node3", }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", }, @@ -2816,7 +2824,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2824,7 +2832,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2832,7 +2840,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2846,28 +2854,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", @@ -2924,7 +2932,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -2932,7 +2940,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2940,7 +2948,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -2954,28 +2962,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", @@ -3032,7 +3040,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -3040,7 +3048,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -3048,7 +3056,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -3062,28 +3070,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", @@ -3132,7 +3140,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "hangzhou", + apps.NodePoolLabel: "hangzhou", }, }, }, @@ -3140,7 +3148,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -3148,7 +3156,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - nodepoolv1alpha1.LabelDesiredNodePool: "shanghai", + apps.NodePoolLabel: "shanghai", }, }, }, @@ -3162,28 +3170,28 @@ func TestFilter(t *testing.T) { }, }, ), - yurtClient: yurtfake.NewSimpleClientset( - &nodepoolv1alpha1.NodePool{ + yurtClient: fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "hangzhou", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ currentNodeName, }, }, }, - &nodepoolv1alpha1.NodePool{ + &v1beta1.NodePool{ ObjectMeta: metav1.ObjectMeta{ Name: "shanghai", }, - Spec: nodepoolv1alpha1.NodePoolSpec{ - Type: nodepoolv1alpha1.Edge, + Spec: v1beta1.NodePoolSpec{ + Type: v1beta1.Edge, }, - Status: nodepoolv1alpha1.NodePoolStatus{ + Status: v1beta1.NodePoolStatus{ Nodes: []string{ "node2", "node3", @@ -3213,8 +3221,9 @@ func TestFilter(t *testing.T) { factory.Start(stopper) factory.WaitForCacheSync(stopper) - yurtFactory := yurtinformers.NewSharedInformerFactory(tt.yurtClient, 24*time.Hour) - nodePoolInformer := yurtFactory.Apps().V1alpha1().NodePools() + gvr := v1beta1.GroupVersion.WithResource("nodepools") + yurtFactory := dynamicinformer.NewDynamicSharedInformerFactory(tt.yurtClient, 24*time.Hour) + nodePoolInformer := yurtFactory.ForResource(gvr) nodePoolLister := nodePoolInformer.Lister() nodePoolSynced := nodePoolInformer.Informer().HasSynced