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 <[email protected]>
  • Loading branch information
ozhuraki committed Apr 17, 2024
1 parent a7c58b1 commit 48417ef
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.

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.

8 changes: 8 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,13 @@ type NodeFeatureSpec struct {
Labels map[string]string `json:"labels"`
}

// Status of a NodeFeature object.
type NodeFeatureStatus struct {
// Status of CRD.
// +optional
Status []string `json:"items"`
}

// Features is the collection of all discovered features.
//
// +protobuf=true
Expand Down
21 changes: 21 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.

10 changes: 10 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,18 @@ spec:
be created.
type: object
type: object
status:
description: Status of a NodeFeature object.
properties:
items:
description: Status of CRD.
items:
type: string
type: array
type: object
required:
- spec
- status
type: object
served: true
storage: true
Expand Down
10 changes: 10 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,18 @@ spec:
be created.
type: object
type: object
status:
description: Status of a NodeFeature object.
properties:
items:
description: Status of CRD.
items:
type: string
type: array
type: object
required:
- spec
- status
type: object
served: true
storage: true
Expand Down
14 changes: 13 additions & 1 deletion pkg/nfd-worker/nfd-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type nfdWorker struct {
nfdClient *nfdclient.Clientset
stop chan struct{} // channel for signaling stop
featureSources []source.FeatureSource
featureSourceErrors int
labelSources []source.LabelSource
}

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.featureSourceErrors = 0
for _, s := range w.featureSources {
currentSourceStart := time.Now()
if err := s.Discover(); err != nil {
w.featureSourceErrors++
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 @@ -762,10 +765,19 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
nfrUpdated.Labels = map[string]string{nfdv1alpha1.NodeFeatureObjNodeNameLabel: nodename}
nfrUpdated.OwnerReferences = ownerRefs
nfrUpdated.Spec = nfdv1alpha1.NodeFeatureSpec{
Features: *features,
Features: *features,
Labels: labels,
}

currentTime := time.Now()
updated := fmt.Sprintf("Updated: %q", currentTime)
nFeatures := fmt.Sprintf("Number of feature sources: %q", len(m.featureSources))
nFeatureErrors := fmt.Sprintf("Number of sources that had failuers: %q", m.featureSourceErrors)
nLabels := fmt.Sprintf("Number of label sources: %q", len(m.labelSources))

nfrUpdated.Status = nfdv1alpha1.NodeFeatureStatus{
Status: []string{ updated, nFeatures, nFeatureErrors, nLabels },
}
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

0 comments on commit 48417ef

Please sign in to comment.