1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00
node-feature-discovery/pkg/nfd-master/updater-pool_test.go
Carlos Eduardo Arango Gutierrez 47c054e1db
Add NodeFeatureGroup CRD
The NodeFeatureGroup is an NFD-specific custom resource that is designed for
grouping nodes based on their features. NFD-Master watches for NodeFeatureGroup
objects in the cluster and updates the status of the NodeFeatureGroup object
with the list of nodes that match the feature group rules. The NodeFeatureGroup
rules follow the same syntax as the NodeFeatureRule rules.

Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
2024-05-23 16:34:08 +02:00

102 lines
3.1 KiB
Go

/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package nfdmaster
import (
"sync"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
fakek8sclient "k8s.io/client-go/kubernetes/fake"
fakenfdclient "sigs.k8s.io/node-feature-discovery/api/generated/clientset/versioned/fake"
)
func newFakeupdaterPool(nfdMaster *nfdMaster) *updaterPool {
return &updaterPool{
nfdMaster: nfdMaster,
wg: sync.WaitGroup{},
}
}
func TestUpdaterStart(t *testing.T) {
fakeMaster := newFakeMaster()
updaterPool := newFakeupdaterPool(fakeMaster)
Convey("When starting the node updater pool", t, func() {
updaterPool.start(10)
q := updaterPool.queue
Convey("Node updater pool queue properties should change", func() {
So(q, ShouldNotBeNil)
So(q.ShuttingDown(), ShouldBeFalse)
})
updaterPool.start(10)
Convey("Node updater pool queue should not change", func() {
So(updaterPool.queue, ShouldEqual, q)
})
})
}
func TestNodeUpdaterStop(t *testing.T) {
fakeMaster := newFakeMaster()
updaterPool := newFakeupdaterPool(fakeMaster)
updaterPool.start(10)
Convey("When stoping the node updater pool", t, func() {
updaterPool.stop()
Convey("Node updater pool queue should be removed", func() {
// Wait for the wg.Done()
So(func() interface{} {
return updaterPool.queue.ShuttingDown()
}, withTimeout, 2*time.Second, ShouldBeTrue)
})
})
}
func TestRunNodeUpdater(t *testing.T) {
fakeMaster := newFakeMaster(WithKubernetesClient(fakek8sclient.NewSimpleClientset()))
fakeMaster.nfdController = newFakeNfdAPIController(fakenfdclient.NewSimpleClientset())
updaterPool := newFakeupdaterPool(fakeMaster)
updaterPool.start(10)
Convey("Queue has no element", t, func() {
So(updaterPool.queue.Len(), ShouldEqual, 0)
})
updaterPool.queue.Add(testNodeName)
Convey("Added element to the queue should be removed", t, func() {
So(func() interface{} { return updaterPool.queue.Len() },
withTimeout, 2*time.Second, ShouldEqual, 0)
})
}
func TestRunNodeFeatureGroupUpdater(t *testing.T) {
fakeMaster := newFakeMaster(WithKubernetesClient(fakek8sclient.NewSimpleClientset()))
fakeMaster.nfdController = newFakeNfdAPIController(fakenfdclient.NewSimpleClientset())
updaterPool := newFakeupdaterPool(fakeMaster)
updaterPool.start(10)
Convey("Queue has no element", t, func() {
So(updaterPool.nfgQueue.Len(), ShouldEqual, 0)
})
updaterPool.nfgQueue.Add(testNodeName)
Convey("Added element to the queue should be removed", t, func() {
So(func() interface{} { return updaterPool.queue.Len() },
withTimeout, 2*time.Second, ShouldEqual, 0)
})
}