1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Rename nfd-topology-gc to nfd-gc

This is preparation for making it a generic garbage collector for all
nfd-managed api objects.
This commit is contained in:
Markus Lehtonen 2023-08-17 16:53:06 +03:00
parent e0c477090b
commit 01c08d67b6
5 changed files with 26 additions and 26 deletions

View file

@ -24,13 +24,13 @@ import (
"k8s.io/klog/v2"
nfdtopologygarbagecollector "sigs.k8s.io/node-feature-discovery/pkg/nfd-topology-gc"
nfdgarbagecollector "sigs.k8s.io/node-feature-discovery/pkg/nfd-gc"
"sigs.k8s.io/node-feature-discovery/pkg/version"
)
const (
// ProgramName is the canonical name of this program
ProgramName = "nfd-topology-gc"
ProgramName = "nfd-gc"
)
func main() {
@ -50,10 +50,10 @@ func main() {
klog.InfoS("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.")
}
// Get new TopologyGC instance
gc, err := nfdtopologygarbagecollector.New(args)
// Get new garbage collector instance
gc, err := nfdgarbagecollector.New(args)
if err != nil {
klog.ErrorS(err, "failed to initialize topology garbage collector instance")
klog.ErrorS(err, "failed to initialize nfd garbage collector instance")
os.Exit(1)
}
@ -63,7 +63,7 @@ func main() {
}
}
func parseArgs(flags *flag.FlagSet, osArgs ...string) *nfdtopologygarbagecollector.Args {
func parseArgs(flags *flag.FlagSet, osArgs ...string) *nfdgarbagecollector.Args {
args := initFlags(flags)
_ = flags.Parse(osArgs)
@ -76,11 +76,11 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) *nfdtopologygarbagecollect
return args
}
func initFlags(flagset *flag.FlagSet) *nfdtopologygarbagecollector.Args {
args := &nfdtopologygarbagecollector.Args{}
func initFlags(flagset *flag.FlagSet) *nfdgarbagecollector.Args {
args := &nfdgarbagecollector.Args{}
flagset.DurationVar(&args.GCPeriod, "gc-interval", time.Duration(1)*time.Hour,
"Interval between which Garbage Collector will try to cleanup any missed but already obsolete NodeResourceTopology. [Default: 1h]")
"interval between cleanup of obsolete api objects")
flagset.StringVar(&args.Kubeconfig, "kubeconfig", "",
"Kubeconfig to use")

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package nfdtopologygarbagecollector
package nfdgarbagecollector
import (
"context"
@ -42,19 +42,19 @@ type Args struct {
Kubeconfig string
}
type TopologyGC interface {
type NfdGarbageCollector interface {
Run() error
Stop()
}
type topologyGC struct {
type nfdGarbageCollector struct {
stopChan chan struct{}
topoClient topologyclientset.Interface
gcPeriod time.Duration
factory informers.SharedInformerFactory
}
func New(args *Args) (TopologyGC, error) {
func New(args *Args) (NfdGarbageCollector, error) {
kubeconfig, err := apihelper.GetKubeconfig(args.Kubeconfig)
if err != nil {
return nil, err
@ -62,10 +62,10 @@ func New(args *Args) (TopologyGC, error) {
stop := make(chan struct{})
return newTopologyGC(kubeconfig, stop, args.GCPeriod)
return newNfdGarbageCollector(kubeconfig, stop, args.GCPeriod)
}
func newTopologyGC(config *restclient.Config, stop chan struct{}, gcPeriod time.Duration) (*topologyGC, error) {
func newNfdGarbageCollector(config *restclient.Config, stop chan struct{}, gcPeriod time.Duration) (*nfdGarbageCollector, error) {
helper := apihelper.K8sHelpers{Kubeconfig: config}
cli, err := helper.GetTopologyClient()
if err != nil {
@ -75,7 +75,7 @@ func newTopologyGC(config *restclient.Config, stop chan struct{}, gcPeriod time.
clientset := kubernetes.NewForConfigOrDie(config)
factory := informers.NewSharedInformerFactory(clientset, 5*time.Minute)
return &topologyGC{
return &nfdGarbageCollector{
topoClient: cli,
stopChan: stop,
gcPeriod: gcPeriod,
@ -83,7 +83,7 @@ func newTopologyGC(config *restclient.Config, stop chan struct{}, gcPeriod time.
}, nil
}
func (n *topologyGC) deleteNRT(nodeName string) {
func (n *nfdGarbageCollector) deleteNRT(nodeName string) {
if err := n.topoClient.TopologyV1alpha2().NodeResourceTopologies().Delete(context.TODO(), nodeName, metav1.DeleteOptions{}); err != nil {
if errors.IsNotFound(err) {
klog.V(2).InfoS("NodeResourceTopology not found, omitting deletion", "nodeName", nodeName)
@ -96,7 +96,7 @@ func (n *topologyGC) deleteNRT(nodeName string) {
klog.InfoS("NodeResourceTopology object has been deleted", "nodeName", nodeName)
}
func (n *topologyGC) deleteNodeHandler(object interface{}) {
func (n *nfdGarbageCollector) deleteNodeHandler(object interface{}) {
// handle a case when we are starting up and need to clear stale NRT resources
obj := object
if deletedFinalStateUnknown, ok := object.(cache.DeletedFinalStateUnknown); ok {
@ -114,7 +114,7 @@ func (n *topologyGC) deleteNodeHandler(object interface{}) {
}
// garbageCollect removes all stale API objects
func (n *topologyGC) garbageCollect() {
func (n *nfdGarbageCollector) garbageCollect() {
klog.InfoS("performing garbage collection")
nodes, err := n.factory.Core().V1().Nodes().Lister().List(labels.Everything())
if err != nil {
@ -145,7 +145,7 @@ func (n *topologyGC) garbageCollect() {
}
// periodicGC runs garbage collector at every gcPeriod to make sure we haven't missed any node
func (n *topologyGC) periodicGC(gcPeriod time.Duration) {
func (n *nfdGarbageCollector) periodicGC(gcPeriod time.Duration) {
// Do initial round of garbage collection at startup time
n.garbageCollect()
@ -162,7 +162,7 @@ func (n *topologyGC) periodicGC(gcPeriod time.Duration) {
}
}
func (n *topologyGC) startNodeInformer() error {
func (n *nfdGarbageCollector) startNodeInformer() error {
nodeInformer := n.factory.Core().V1().Nodes().Informer()
if _, err := nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
@ -179,7 +179,7 @@ func (n *topologyGC) startNodeInformer() error {
}
// Run is a blocking function that removes stale NRT objects when Node is deleted and runs periodic GC to make sure any obsolete objects are removed
func (n *topologyGC) Run() error {
func (n *nfdGarbageCollector) Run() error {
if err := n.startNodeInformer(); err != nil {
return err
}
@ -189,6 +189,6 @@ func (n *topologyGC) Run() error {
return nil
}
func (n *topologyGC) Stop() {
func (n *nfdGarbageCollector) Stop() {
close(n.stopChan)
}

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package nfdtopologygarbagecollector
package nfdgarbagecollector
import (
"context"
@ -93,7 +93,7 @@ func TestNRTGC(t *testing.T) {
func newMockGC(nodes, nrts []string) *mockGC {
k8sClient := fakek8sclientset.NewSimpleClientset(createFakeNodes(nodes...)...)
return &mockGC{
topologyGC: topologyGC{
nfdGarbageCollector: nfdGarbageCollector{
factory: informers.NewSharedInformerFactory(k8sClient, 5*time.Minute),
topoClient: faketopologyv1alpha2.NewSimpleClientset(createFakeNRTs(nrts...)...),
stopChan: make(chan struct{}, 1),
@ -126,7 +126,7 @@ func createFakeNRTs(names ...string) []runtime.Object {
}
type mockGC struct {
topologyGC
nfdGarbageCollector
k8sClient k8sclientset.Interface
}