mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-15 04:57:56 +00:00
nfd-master: implement controller for NodeFeatureRule CRs
Implement a simple controller stub that operates on NodeFeatureRule objects. The controller does not yet have any functionality other than logging changes in the (NodeFeatureRule) objecs it is watching. Also update the documentation on the -no-publish flag to match the new functionality.
This commit is contained in:
parent
237c4f7824
commit
e6e32a88c3
5 changed files with 108 additions and 4 deletions
|
@ -20,3 +20,11 @@ rules:
|
|||
- create
|
||||
- get
|
||||
- update
|
||||
- apiGroups:
|
||||
- nfd.k8s-sigs.io
|
||||
resources:
|
||||
- nodefeaturerules
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
|
|
|
@ -18,6 +18,14 @@ rules:
|
|||
- patch
|
||||
- update
|
||||
- list
|
||||
- apiGroups:
|
||||
- nfd.k8s-sigs.io
|
||||
resources:
|
||||
- nodefeaturerules
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
{{- if .Values.topologyUpdater.enable }}
|
||||
- apiGroups:
|
||||
- topology.node.k8s.io
|
||||
|
|
|
@ -139,10 +139,9 @@ nfd-master -verify-node-name -ca-file=/opt/nfd/ca.crt \
|
|||
|
||||
### -no-publish
|
||||
|
||||
The `-no-publish` flag disables all communication with the Kubernetes API
|
||||
server, making a "dry-run" flag for nfd-master. No Labels, Annotations or
|
||||
ExtendedResources (or any other properties of any Kubernetes API objects) are
|
||||
modified.
|
||||
The `-no-publish` flag disables updates to the Node objects in the Kubernetes
|
||||
API server, making a "dry-run" flag for nfd-master. No Labels, Annotations or
|
||||
ExtendedResources of nodes are updated.
|
||||
|
||||
Default: *false*
|
||||
|
||||
|
|
|
@ -104,6 +104,8 @@ type NfdMaster interface {
|
|||
}
|
||||
|
||||
type nfdMaster struct {
|
||||
*nfdController
|
||||
|
||||
args Args
|
||||
nodeName string
|
||||
annotationNs string
|
||||
|
@ -171,6 +173,12 @@ func (m *nfdMaster) Run() error {
|
|||
return m.prune()
|
||||
}
|
||||
|
||||
kubeconfig, err := m.getKubeconfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.nfdController = newNfdController(kubeconfig)
|
||||
|
||||
if !m.args.NoPublish {
|
||||
err := m.updateMasterNode()
|
||||
if err != nil {
|
||||
|
@ -241,6 +249,10 @@ func (m *nfdMaster) Run() error {
|
|||
func (m *nfdMaster) Stop() {
|
||||
m.server.Stop()
|
||||
|
||||
if m.nfdController != nil {
|
||||
m.nfdController.stop()
|
||||
}
|
||||
|
||||
select {
|
||||
case m.stop <- struct{}{}:
|
||||
default:
|
||||
|
|
77
pkg/nfd-master/nodefeaturerule-controller.go
Normal file
77
pkg/nfd-master/nodefeaturerule-controller.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Copyright 2021 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 (
|
||||
"time"
|
||||
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1"
|
||||
nfdclientset "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned"
|
||||
nfdscheme "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned/scheme"
|
||||
nfdinformers "sigs.k8s.io/node-feature-discovery/pkg/generated/informers/externalversions"
|
||||
nfdlisters "sigs.k8s.io/node-feature-discovery/pkg/generated/listers/nfd/v1alpha1"
|
||||
)
|
||||
|
||||
type nfdController struct {
|
||||
lister nfdlisters.NodeFeatureRuleLister
|
||||
|
||||
stopChan chan struct{}
|
||||
}
|
||||
|
||||
func newNfdController(config *restclient.Config) *nfdController {
|
||||
c := &nfdController{
|
||||
stopChan: make(chan struct{}, 1),
|
||||
}
|
||||
|
||||
nfdClient := nfdclientset.NewForConfigOrDie(config)
|
||||
|
||||
informerFactory := nfdinformers.NewSharedInformerFactory(nfdClient, 5*time.Minute)
|
||||
informer := informerFactory.Nfd().V1alpha1().NodeFeatureRules()
|
||||
informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(object interface{}) {
|
||||
key, _ := cache.MetaNamespaceKeyFunc(object)
|
||||
klog.V(2).Infof("LabelRule %v added", key)
|
||||
},
|
||||
UpdateFunc: func(oldObject, newObject interface{}) {
|
||||
key, _ := cache.MetaNamespaceKeyFunc(newObject)
|
||||
klog.V(2).Infof("LabelRule %v updated", key)
|
||||
},
|
||||
DeleteFunc: func(object interface{}) {
|
||||
key, _ := cache.MetaNamespaceKeyFunc(object)
|
||||
klog.V(2).Infof("LabelRule %v deleted", key)
|
||||
},
|
||||
})
|
||||
informerFactory.Start(c.stopChan)
|
||||
|
||||
utilruntime.Must(nfdv1alpha1.AddToScheme(nfdscheme.Scheme))
|
||||
|
||||
c.lister = informer.Lister()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *nfdController) stop() {
|
||||
select {
|
||||
case c.stopChan <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue