Skip to content

Commit

Permalink
apis/nfd: Add Status to NodeFeature CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
  • Loading branch information
ozhuraki committed Apr 26, 2024
1 parent a7c58b1 commit 078619c
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/nfd/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type NodeFeature struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeFeatureSpec `json:"spec"`
Status NodeFeatureStatus `json:"status"`
}

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

// Status of a NodeFeature object.
type NodeFeatureStatus struct {
// UTC time when the NodeFeature object was last updated.
// +optional
LastAppliedAt metav1.Time `json:"lastAppliedAt,omitempty"`
// +optional
// Number of features discovered.
NumberOfFeatures int `json:"numberOfFeatures,omitempty"`
// +optional
// Number of errors during last feature discovery.
NumberOfFeatureErrors int `json:"numberOfFeatureErrors,omitempty"`
// +optional
// Number of labels created.
NumberOfLabels int `json:"numberOfLabels,omitempty"`
}

// Features is the collection of all discovered features.
//
// +protobuf=true
Expand Down
18 changes: 18 additions & 0 deletions api/nfd/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions deployment/base/nfd-crds/nfd-api-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,26 @@ spec:
be created.
type: object
type: object
status:
description: Status of a NodeFeature object.
properties:
lastAppliedAt:
description: UTC time when the NodeFeature object was last updated.
format: date-time
type: string
numberOfFeatureErrors:
description: Number of errors during last feature discovery.
type: integer
numberOfFeatures:
description: Number of features discovered.
type: integer
numberOfLabels:
description: Number of labels created.
type: integer
type: object
required:
- spec
- status
type: object
served: true
storage: true
Expand Down
18 changes: 18 additions & 0 deletions deployment/helm/node-feature-discovery/crds/nfd-api-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,26 @@ spec:
be created.
type: object
type: object
status:
description: Status of a NodeFeature object.
properties:
lastAppliedAt:
description: UTC time when the NodeFeature object was last updated.
format: date-time
type: string
numberOfFeatureErrors:
description: Number of errors during last feature discovery.
type: integer
numberOfFeatures:
description: Number of features discovered.
type: integer
numberOfLabels:
description: Number of labels created.
type: integer
type: object
required:
- spec
- status
type: object
served: true
storage: true
Expand Down
40 changes: 27 additions & 13 deletions pkg/nfd-worker/nfd-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,19 @@ type ConfigOverrideArgs struct {
}

type nfdWorker struct {
args Args
certWatch *utils.FsWatcher
clientConn *grpc.ClientConn
configFilePath string
config *NFDConfig
kubernetesNamespace string
grpcClient pb.LabelerClient
healthServer *grpc.Server
nfdClient *nfdclient.Clientset
stop chan struct{} // channel for signaling stop
featureSources []source.FeatureSource
labelSources []source.LabelSource
args Args
certWatch *utils.FsWatcher
clientConn *grpc.ClientConn
configFilePath string
config *NFDConfig
kubernetesNamespace string
grpcClient pb.LabelerClient
healthServer *grpc.Server
nfdClient *nfdclient.Clientset
stop chan struct{} // channel for signaling stop
featureSources []source.FeatureSource
numberOfFeatureSourceErrors int
labelSources []source.LabelSource
}

// This ticker can represent infinite and normal intervals.
Expand Down Expand Up @@ -218,9 +219,11 @@ func (w *nfdWorker) startGrpcHealthServer(errChan chan<- error) error {
// Run feature discovery.
func (w *nfdWorker) runFeatureDiscovery() error {
discoveryStart := time.Now()
w.numberOfFeatureSourceErrors = 0
for _, s := range w.featureSources {
currentSourceStart := time.Now()
if err := s.Discover(); err != nil {
w.numberOfFeatureSourceErrors++
klog.ErrorS(err, "feature discovery failed", "source", s.Name())
}
klog.V(3).InfoS("feature discovery completed", "featureSource", s.Name(), "duration", time.Since(currentSourceStart))
Expand Down Expand Up @@ -747,6 +750,12 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
Labels: labels,
},
}
nfr.Status = nfdv1alpha1.NodeFeatureStatus{
LastAppliedAt: metav1.Time{Time: time.Now().UTC()},
NumberOfFeatures: len(m.featureSources),
NumberOfFeatureErrors: m.numberOfFeatureSourceErrors,
NumberOfLabels: len(m.labelSources),
}

nfrCreated, err := cli.NfdV1alpha1().NodeFeatures(namespace).Create(context.TODO(), nfr, metav1.CreateOptions{})
if err != nil {
Expand All @@ -765,7 +774,12 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
Features: *features,
Labels: labels,
}

nfrUpdated.Status = nfdv1alpha1.NodeFeatureStatus{
LastAppliedAt: metav1.Time{Time: time.Now().UTC()},
NumberOfFeatures: len(m.featureSources),
NumberOfFeatureErrors: m.numberOfFeatureSourceErrors,
NumberOfLabels: len(m.labelSources),
}
if !apiequality.Semantic.DeepEqual(nfr, nfrUpdated) {
klog.InfoS("updating NodeFeature object", "nodefeature", klog.KObj(nfr))
nfrUpdated, err = cli.NfdV1alpha1().NodeFeatures(namespace).Update(context.TODO(), nfrUpdated, metav1.UpdateOptions{})
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/node_feature_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,19 @@ var _ = NFDDescribe(Label("nfd-master"), func() {
}
eventuallyNonControlPlaneNodes(ctx, f.ClientSet).Should(MatchLabels(expectedLabels, nodes))

By("Verifying the CRD status")
nf, err := nfdClient.NfdV1alpha1().NodeFeatures(f.Namespace.Name).Get(ctx, targetNodeName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred(), "Error getting NodeFeature object: %q", err)

expectedStatus := nfdv1alpha1.NodeFeatureStatus{
LastAppliedAt: nf.Status.LastAppliedAt,
NumberOfFeatures: nf.Status.NumberOfFeatures,
NumberOfFeatureErrors: 0,
NumberOfLabels: len(expectedLabels[targetNodeName]) - 1,
}
isEqual := (expectedStatus == nf.Status)
Expect(isEqual).To(BeTrue())

By("Deleting nfd-worker daemonset")
err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Delete(ctx, workerDS.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 078619c

Please sign in to comment.