-
Notifications
You must be signed in to change notification settings - Fork 278
export swap behavior via label #2192
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
base: master
Are you sure you want to change the base?
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,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: nfd-worker | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: ["pods"] | ||
verbs: ["get"] | ||
- apiGroups: [""] | ||
resources: ["nodes/proxy"] | ||
verbs: ["get"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: nfd-worker | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: nfd-worker | ||
subjects: | ||
- kind: ServiceAccount | ||
name: nfd-worker | ||
namespace: default |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ rules: | |
resources: | ||
- pods | ||
verbs: | ||
- get | ||
- get |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,8 +38,10 @@ import ( | |||||||||||||||||
"k8s.io/apimachinery/pkg/util/validation" | ||||||||||||||||||
k8sclient "k8s.io/client-go/kubernetes" | ||||||||||||||||||
"k8s.io/klog/v2" | ||||||||||||||||||
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1" | ||||||||||||||||||
"k8s.io/utils/ptr" | ||||||||||||||||||
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog" | ||||||||||||||||||
"sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf" | ||||||||||||||||||
"sigs.k8s.io/yaml" | ||||||||||||||||||
|
||||||||||||||||||
apiequality "k8s.io/apimachinery/pkg/api/equality" | ||||||||||||||||||
|
@@ -56,7 +58,7 @@ import ( | |||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/fake" | ||||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/kernel" | ||||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/local" | ||||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/memory" | ||||||||||||||||||
memory "sigs.k8s.io/node-feature-discovery/source/memory" | ||||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/network" | ||||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/pci" | ||||||||||||||||||
_ "sigs.k8s.io/node-feature-discovery/source/storage" | ||||||||||||||||||
|
@@ -94,13 +96,16 @@ type Labels map[string]string | |||||||||||||||||
|
||||||||||||||||||
// Args are the command line arguments of NfdWorker. | ||||||||||||||||||
type Args struct { | ||||||||||||||||||
ConfigFile string | ||||||||||||||||||
Klog map[string]*utils.KlogFlagVal | ||||||||||||||||||
Kubeconfig string | ||||||||||||||||||
Oneshot bool | ||||||||||||||||||
Options string | ||||||||||||||||||
Port int | ||||||||||||||||||
NoOwnerRefs bool | ||||||||||||||||||
ConfigFile string | ||||||||||||||||||
Klog map[string]*utils.KlogFlagVal | ||||||||||||||||||
Kubeconfig string | ||||||||||||||||||
Oneshot bool | ||||||||||||||||||
Options string | ||||||||||||||||||
Port int | ||||||||||||||||||
NoOwnerRefs bool | ||||||||||||||||||
KubeletConfigPath string | ||||||||||||||||||
KubeletConfigURI string | ||||||||||||||||||
APIAuthTokenFile string | ||||||||||||||||||
|
||||||||||||||||||
Overrides ConfigOverrideArgs | ||||||||||||||||||
} | ||||||||||||||||||
|
@@ -124,6 +129,7 @@ type nfdWorker struct { | |||||||||||||||||
featureSources []source.FeatureSource | ||||||||||||||||||
labelSources []source.LabelSource | ||||||||||||||||||
ownerReference []metav1.OwnerReference | ||||||||||||||||||
kubeletConfigFunc func() (*kubeletconfigv1beta1.KubeletConfiguration, error) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// This ticker can represent infinite and normal intervals. | ||||||||||||||||||
|
@@ -169,12 +175,25 @@ func NewNfdWorker(opts ...NfdWorkerOption) (NfdWorker, error) { | |||||||||||||||||
stop: make(chan struct{}), | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
if nfd.args.ConfigFile != "" { | ||||||||||||||||||
nfd.configFilePath = filepath.Clean(nfd.args.ConfigFile) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
for _, o := range opts { | ||||||||||||||||||
o.apply(nfd) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
if nfd.args.ConfigFile != "" { | ||||||||||||||||||
nfd.configFilePath = filepath.Clean(nfd.args.ConfigFile) | ||||||||||||||||||
kubeletConfigFunc, err := kubeconf.GetKubeletConfigFunc(nfd.args.KubeletConfigURI, nfd.args.APIAuthTokenFile) | ||||||||||||||||||
if err != nil { | ||||||||||||||||||
return nil, err | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
nfd = &nfdWorker{ | ||||||||||||||||||
kubeletConfigFunc: kubeletConfigFunc, | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
for _, o := range opts { | ||||||||||||||||||
o.apply(nfd) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
Comment on lines
+191
to
198
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. The nfd variable is being reassigned to a new nfdWorker struct, which discards all the previous initialization including the stop channel and other fields set earlier in the function. This will cause the worker to lose its previous configuration.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||
// k8sClient might've been set via opts by tests | ||||||||||||||||||
|
@@ -312,6 +331,12 @@ func (w *nfdWorker) Run() error { | |||||||||||||||||
httpMux.Handle("/metrics", promhttp.HandlerFor(promRegistry, promhttp.HandlerOpts{})) | ||||||||||||||||||
registerVersion(version.Get()) | ||||||||||||||||||
|
||||||||||||||||||
klConfig, err := w.kubeletConfigFunc() | ||||||||||||||||||
if err != nil { | ||||||||||||||||||
return err | ||||||||||||||||||
} | ||||||||||||||||||
memory.SetSwapMode(klConfig.MemorySwap.SwapBehavior) | ||||||||||||||||||
|
||||||||||||||||||
err = w.runFeatureDiscovery() | ||||||||||||||||||
if err != nil { | ||||||||||||||||||
return err | ||||||||||||||||||
|
@@ -624,7 +649,7 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error { | |||||||||||||||||
return err | ||||||||||||||||||
} | ||||||||||||||||||
nodename := utils.NodeName() | ||||||||||||||||||
namespace := m.kubernetesNamespace | ||||||||||||||||||
namespace := os.Getenv("POD_NAMESPACE") | ||||||||||||||||||
|
||||||||||||||||||
features := source.GetAllFeatures() | ||||||||||||||||||
|
||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.