Skip to content

Commit

Permalink
nfd-master: parse kubeconfig even with NoPublish set
Browse files Browse the repository at this point in the history
Don't try to be too smart when kubeconfig is needed. In practice, the
nfd-master really doesn't work anymore (with the NodeFeature API
enabled) without a kubeconfig set. This patch fixes crashes happening
when NoPublish is enabled, e.g. in listing all nodes in the nfd api
handler and in getting single node objects in the node updater pool.
  • Loading branch information
marquiz committed Apr 4, 2024
1 parent 0ebc0db commit 1ed50d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 2 additions & 0 deletions pkg/nfd-master/nfd-master-internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ func TestConfigParse(t *testing.T) {
So(err, ShouldBeNil)
master := m.(*nfdMaster)
overrides := `{"noPublish": true, "enableTaints": true, "extraLabelNs": ["added.ns.io","added.kubernetes.io"], "denyLabelNs": ["denied.ns.io","denied.kubernetes.io"], "resourceLabels": ["vendor-1.com/feature-1","vendor-2.io/feature-2"], "labelWhiteList": "foo"}`
// Set fake (and invalid) apiserver address so that configuration doesn't fail in parsing the kubeconfig
os.Setenv("KUBERNETES_MASTER", ".")

Convey("and no core cmdline flags have been specified", func() {
So(master.configure("non-existing-file", overrides), ShouldBeNil)
Expand Down
27 changes: 13 additions & 14 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,6 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(node *corev1.Node) error {
return objs[i].Namespace < objs[j].Namespace
})

if m.config.NoPublish {
return nil
}

klog.V(1).InfoS("processing of node initiated by NodeFeature API", "nodeName", node.Name)

features := nfdv1alpha1.NewNodeFeatureSpec()
Expand Down Expand Up @@ -854,6 +850,11 @@ func (m *nfdMaster) refreshNodeFeatures(node *corev1.Node, labels map[string]str
taints = filterTaints(crTaints)
}

if m.config.NoPublish {
klog.V(1).InfoS("node update skipped, NoPublish=true", "nodeName", node.Name)
return nil
}

Check warning on line 856 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L854-L856

Added lines #L854 - L856 were not covered by tests

err := m.updateNodeObject(node, labels, annotations, extendedResources, taints)
if err != nil {
klog.ErrorS(err, "failed to update node", "nodeName", node.Name)
Expand Down Expand Up @@ -1229,17 +1230,15 @@ func (m *nfdMaster) configure(filepath string, overrides string) error {
return err
}

if !c.NoPublish {
kubeconfig, err := utils.GetKubeconfig(m.args.Kubeconfig)
if err != nil {
return err
}
cli, err := k8sclient.NewForConfig(kubeconfig)
if err != nil {
return err
}
m.k8sClient = cli
kubeconfig, err := utils.GetKubeconfig(m.args.Kubeconfig)
if err != nil {
return err
}

Check warning on line 1236 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L1235-L1236

Added lines #L1235 - L1236 were not covered by tests
cli, err := k8sclient.NewForConfig(kubeconfig)
if err != nil {
return err

Check warning on line 1239 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L1239

Added line #L1239 was not covered by tests
}
m.k8sClient = cli

// Pre-process DenyLabelNS into 2 lists: one for normal ns, and the other for wildcard ns
normalDeniedNs, wildcardDeniedNs := preProcessDeniedNamespaces(c.DenyLabelNs)
Expand Down
2 changes: 2 additions & 0 deletions pkg/nfd-worker/nfd-worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func setupTest(args *master.Args) testContext {

// Run nfd-master instance, intended to be used as the server counterpart
go func() {
// Set fake (and invalid) apiserver address so that nfd-master configuration doesn't fail in parsing the kubeconfig
os.Setenv("KUBERNETES_MASTER", ".")
ctx.errs <- ctx.master.Run()
close(ctx.errs)
}()
Expand Down

0 comments on commit 1ed50d2

Please sign in to comment.