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 19, 2024
1 parent a7c58b1 commit 2fa5f6b
Show file tree
Hide file tree
Showing 7 changed files with 109 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.

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 {
// Annotations to create if the rule matches.
// +optional
LastAppliedAt metav1.Time `json:"lastAppliedAt,omitempty"`
// +optional
// Number of features discovered.
NumberOfFeatures int `json:"numberOfFeatures,omitempty"`
// +optional
// Number of errors during 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: Annotations to create if the rule matches.
format: date-time
type: string
numberOfFeatureErrors:
description: Number of errors during 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: Annotations to create if the rule matches.
format: date-time
type: string
numberOfFeatureErrors:
description: Number of errors during 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
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{
LastAppliedAt: metav1.Time{Time: 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 2fa5f6b

Please sign in to comment.