Skip to content

Commit 078619c

Browse files
committed
apis/nfd: Add Status to NodeFeature CRD
Signed-off-by: Oleg Zhurakivskyy <[email protected]>
1 parent a7c58b1 commit 078619c

File tree

8 files changed

+140
-13
lines changed

8 files changed

+140
-13
lines changed

api/generated/clientset/versioned/typed/nfd/v1alpha1/fake/fake_nodefeature.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/generated/clientset/versioned/typed/nfd/v1alpha1/nodefeature.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/nfd/v1alpha1/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type NodeFeature struct {
4141
metav1.ObjectMeta `json:"metadata,omitempty"`
4242

4343
Spec NodeFeatureSpec `json:"spec"`
44+
Status NodeFeatureStatus `json:"status"`
4445
}
4546

4647
// NodeFeatureSpec describes a NodeFeature object.
@@ -53,6 +54,22 @@ type NodeFeatureSpec struct {
5354
Labels map[string]string `json:"labels"`
5455
}
5556

57+
// Status of a NodeFeature object.
58+
type NodeFeatureStatus struct {
59+
// UTC time when the NodeFeature object was last updated.
60+
// +optional
61+
LastAppliedAt metav1.Time `json:"lastAppliedAt,omitempty"`
62+
// +optional
63+
// Number of features discovered.
64+
NumberOfFeatures int `json:"numberOfFeatures,omitempty"`
65+
// +optional
66+
// Number of errors during last feature discovery.
67+
NumberOfFeatureErrors int `json:"numberOfFeatureErrors,omitempty"`
68+
// +optional
69+
// Number of labels created.
70+
NumberOfLabels int `json:"numberOfLabels,omitempty"`
71+
}
72+
5673
// Features is the collection of all discovered features.
5774
//
5875
// +protobuf=true

api/nfd/v1alpha1/zz_generated.deepcopy.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployment/base/nfd-crds/nfd-api-crds.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,26 @@ spec:
109109
be created.
110110
type: object
111111
type: object
112+
status:
113+
description: Status of a NodeFeature object.
114+
properties:
115+
lastAppliedAt:
116+
description: UTC time when the NodeFeature object was last updated.
117+
format: date-time
118+
type: string
119+
numberOfFeatureErrors:
120+
description: Number of errors during last feature discovery.
121+
type: integer
122+
numberOfFeatures:
123+
description: Number of features discovered.
124+
type: integer
125+
numberOfLabels:
126+
description: Number of labels created.
127+
type: integer
128+
type: object
112129
required:
113130
- spec
131+
- status
114132
type: object
115133
served: true
116134
storage: true

deployment/helm/node-feature-discovery/crds/nfd-api-crds.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,26 @@ spec:
109109
be created.
110110
type: object
111111
type: object
112+
status:
113+
description: Status of a NodeFeature object.
114+
properties:
115+
lastAppliedAt:
116+
description: UTC time when the NodeFeature object was last updated.
117+
format: date-time
118+
type: string
119+
numberOfFeatureErrors:
120+
description: Number of errors during last feature discovery.
121+
type: integer
122+
numberOfFeatures:
123+
description: Number of features discovered.
124+
type: integer
125+
numberOfLabels:
126+
description: Number of labels created.
127+
type: integer
128+
type: object
112129
required:
113130
- spec
131+
- status
114132
type: object
115133
served: true
116134
storage: true

pkg/nfd-worker/nfd-worker.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ type ConfigOverrideArgs struct {
121121
}
122122

123123
type nfdWorker struct {
124-
args Args
125-
certWatch *utils.FsWatcher
126-
clientConn *grpc.ClientConn
127-
configFilePath string
128-
config *NFDConfig
129-
kubernetesNamespace string
130-
grpcClient pb.LabelerClient
131-
healthServer *grpc.Server
132-
nfdClient *nfdclient.Clientset
133-
stop chan struct{} // channel for signaling stop
134-
featureSources []source.FeatureSource
135-
labelSources []source.LabelSource
124+
args Args
125+
certWatch *utils.FsWatcher
126+
clientConn *grpc.ClientConn
127+
configFilePath string
128+
config *NFDConfig
129+
kubernetesNamespace string
130+
grpcClient pb.LabelerClient
131+
healthServer *grpc.Server
132+
nfdClient *nfdclient.Clientset
133+
stop chan struct{} // channel for signaling stop
134+
featureSources []source.FeatureSource
135+
numberOfFeatureSourceErrors int
136+
labelSources []source.LabelSource
136137
}
137138

138139
// This ticker can represent infinite and normal intervals.
@@ -218,9 +219,11 @@ func (w *nfdWorker) startGrpcHealthServer(errChan chan<- error) error {
218219
// Run feature discovery.
219220
func (w *nfdWorker) runFeatureDiscovery() error {
220221
discoveryStart := time.Now()
222+
w.numberOfFeatureSourceErrors = 0
221223
for _, s := range w.featureSources {
222224
currentSourceStart := time.Now()
223225
if err := s.Discover(); err != nil {
226+
w.numberOfFeatureSourceErrors++
224227
klog.ErrorS(err, "feature discovery failed", "source", s.Name())
225228
}
226229
klog.V(3).InfoS("feature discovery completed", "featureSource", s.Name(), "duration", time.Since(currentSourceStart))
@@ -747,6 +750,12 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
747750
Labels: labels,
748751
},
749752
}
753+
nfr.Status = nfdv1alpha1.NodeFeatureStatus{
754+
LastAppliedAt: metav1.Time{Time: time.Now().UTC()},
755+
NumberOfFeatures: len(m.featureSources),
756+
NumberOfFeatureErrors: m.numberOfFeatureSourceErrors,
757+
NumberOfLabels: len(m.labelSources),
758+
}
750759

751760
nfrCreated, err := cli.NfdV1alpha1().NodeFeatures(namespace).Create(context.TODO(), nfr, metav1.CreateOptions{})
752761
if err != nil {
@@ -765,7 +774,12 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
765774
Features: *features,
766775
Labels: labels,
767776
}
768-
777+
nfrUpdated.Status = nfdv1alpha1.NodeFeatureStatus{
778+
LastAppliedAt: metav1.Time{Time: time.Now().UTC()},
779+
NumberOfFeatures: len(m.featureSources),
780+
NumberOfFeatureErrors: m.numberOfFeatureSourceErrors,
781+
NumberOfLabels: len(m.labelSources),
782+
}
769783
if !apiequality.Semantic.DeepEqual(nfr, nfrUpdated) {
770784
klog.InfoS("updating NodeFeature object", "nodefeature", klog.KObj(nfr))
771785
nfrUpdated, err = cli.NfdV1alpha1().NodeFeatures(namespace).Update(context.TODO(), nfrUpdated, metav1.UpdateOptions{})

test/e2e/node_feature_discovery_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,19 @@ var _ = NFDDescribe(Label("nfd-master"), func() {
500500
}
501501
eventuallyNonControlPlaneNodes(ctx, f.ClientSet).Should(MatchLabels(expectedLabels, nodes))
502502

503+
By("Verifying the CRD status")
504+
nf, err := nfdClient.NfdV1alpha1().NodeFeatures(f.Namespace.Name).Get(ctx, targetNodeName, metav1.GetOptions{})
505+
Expect(err).NotTo(HaveOccurred(), "Error getting NodeFeature object: %q", err)
506+
507+
expectedStatus := nfdv1alpha1.NodeFeatureStatus{
508+
LastAppliedAt: nf.Status.LastAppliedAt,
509+
NumberOfFeatures: nf.Status.NumberOfFeatures,
510+
NumberOfFeatureErrors: 0,
511+
NumberOfLabels: len(expectedLabels[targetNodeName]) - 1,
512+
}
513+
isEqual := (expectedStatus == nf.Status)
514+
Expect(isEqual).To(BeTrue())
515+
503516
By("Deleting nfd-worker daemonset")
504517
err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Delete(ctx, workerDS.Name, metav1.DeleteOptions{})
505518
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)