-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] feat: configure CR restrictions #1540
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
noPublish: false | ||
autoDefaultNs: true | ||
extraLabelNs: ["added.ns.io","added.kubernets.io"] | ||
denyLabelNs: ["denied.ns.io","denied.kubernetes.io"] | ||
resourceLabels: ["vendor-1.com/feature-1","vendor-2.io/feature-2"] | ||
enableTaints: false | ||
labelWhiteList: "" | ||
resyncPeriod: "2h" | ||
restrictions: | ||
allowedNamespaces: ["default"] | ||
denyNodeFeatureLabels: true | ||
klog: | ||
addDirHeader: false | ||
alsologtostderr: false | ||
logBacktraceAt: | ||
logtostderr: true | ||
skipHeaders: false | ||
stderrthreshold: 2 | ||
v: 0 | ||
vmodule: | ||
logDir: | ||
logFile: | ||
logFileMaxSize: 1800 | ||
skipLogHeaders: false | ||
leaderElection: | ||
leaseDuration: 15s | ||
renewDeadline: 10s | ||
retryPeriod: 2s | ||
nfdApiParallelism: 10 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,9 @@ | |
) | ||
|
||
type nfdController struct { | ||
featureLister nfdlisters.NodeFeatureLister | ||
ruleLister nfdlisters.NodeFeatureRuleLister | ||
featureLister nfdlisters.NodeFeatureLister | ||
ruleLister nfdlisters.NodeFeatureRuleLister | ||
allowedNamespaces []string | ||
|
||
stopChan chan struct{} | ||
|
||
|
@@ -47,13 +48,15 @@ | |
type nfdApiControllerOptions struct { | ||
DisableNodeFeature bool | ||
ResyncPeriod time.Duration | ||
AllowedNamespaces []string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, looking at this now I think we could do better (more k8s-like). Could we use metav1.LabelSelector directly. It would make it very flexible to pick up the namespaces to watch. The name of the config option would be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I got this correctly, users would need to pass a map (instead of an array) to specify selectors, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or even use the metav1.LabelSelector type directly? |
||
} | ||
|
||
func newNfdController(config *restclient.Config, nfdApiControllerOptions nfdApiControllerOptions) (*nfdController, error) { | ||
c := &nfdController{ | ||
stopChan: make(chan struct{}, 1), | ||
updateAllNodesChan: make(chan struct{}, 1), | ||
updateOneNodeChan: make(chan string), | ||
allowedNamespaces: nfdApiControllerOptions.AllowedNamespaces, | ||
} | ||
|
||
nfdClient := nfdclientset.NewForConfigOrDie(config) | ||
|
@@ -68,17 +71,23 @@ | |
AddFunc: func(obj interface{}) { | ||
nfr := obj.(*nfdv1alpha1.NodeFeature) | ||
klog.V(2).InfoS("NodeFeature added", "nodefeature", klog.KObj(nfr)) | ||
c.updateOneNode("NodeFeature", nfr) | ||
if c.isNamespaceAllowed(nfr.Namespace) { | ||
c.updateOneNode("NodeFeature", nfr) | ||
} | ||
}, | ||
UpdateFunc: func(oldObj, newObj interface{}) { | ||
nfr := newObj.(*nfdv1alpha1.NodeFeature) | ||
klog.V(2).InfoS("NodeFeature updated", "nodefeature", klog.KObj(nfr)) | ||
c.updateOneNode("NodeFeature", nfr) | ||
if c.isNamespaceAllowed(nfr.Namespace) { | ||
c.updateOneNode("NodeFeature", nfr) | ||
} | ||
}, | ||
DeleteFunc: func(obj interface{}) { | ||
nfr := obj.(*nfdv1alpha1.NodeFeature) | ||
klog.V(2).InfoS("NodeFeature deleted", "nodefeature", klog.KObj(nfr)) | ||
c.updateOneNode("NodeFeature", nfr) | ||
if c.isNamespaceAllowed(nfr.Namespace) { | ||
c.updateOneNode("NodeFeature", nfr) | ||
} | ||
}, | ||
}); err != nil { | ||
return nil, err | ||
|
@@ -129,6 +138,16 @@ | |
} | ||
} | ||
|
||
func (c *nfdController) isNamespaceAllowed(namespace string) bool { | ||
for _, ns := range c.allowedNamespaces { | ||
if ns == namespace { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (c *nfdController) updateOneNode(typ string, obj metav1.Object) { | ||
nodeName, err := getNodeNameForObj(obj) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could have these as config file options only, if you want to keep things simple. E.g. the leader election parameters are config-file-only so this is asymmetric, already. WDYT?