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 18, 2024
1 parent a7c58b1 commit b58d1bd
Show file tree
Hide file tree
Showing 7 changed files with 94 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.

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

// Status of a NodeFeature object.
type NodeFeatureStatus struct {
// +optional
UpdatedAt string `json:"updatedAt"`
// +optional
NumberOfFeatures int `json:"numberOfFeatures"`
// +optional
NumberOfFeatureErrors int `json:"numberOfFeatureErrors"`
// +optional
NumberOfLabels int `json:"numberOfLabels"`
}

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

13 changes: 13 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,21 @@ spec:
be created.
type: object
type: object
status:
description: Status of a NodeFeature object.
properties:
numberOfFeatureErrors:
type: integer
numberOfFeatures:
type: integer
numberOfLabels:
type: integer
updatedAt:
type: string
type: object
required:
- spec
- status
type: object
served: true
storage: true
Expand Down
13 changes: 13 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,21 @@ spec:
be created.
type: object
type: object
status:
description: Status of a NodeFeature object.
properties:
numberOfFeatureErrors:
type: integer
numberOfFeatures:
type: integer
numberOfLabels:
type: integer
updatedAt:
type: string
type: object
required:
- spec
- status
type: object
served: true
storage: true
Expand Down
10 changes: 9 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 @@ -765,7 +768,12 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
Features: *features,
Labels: labels,
}

nfrUpdated.Status = nfdv1alpha1.NodeFeatureStatus{
UpdatedAt: fmt.Sprintf("%q", time.Now()),
NumberOfFeatures: len(m.featureSources),
NumberOfFeatureErrors: m.featureSourceErrors,
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

0 comments on commit b58d1bd

Please sign in to comment.