Skip to content

Commit

Permalink
Adding docs to NFD state funcs related to NFD itself (not just the op…
Browse files Browse the repository at this point in the history
…erator)

Adding documentation to the NFD state functions related to NFD itself
so that users and contributors can understand how NFD works with the NFD
operator, especially if they are looking at another file that references
these functions and the NFD struct.
  • Loading branch information
courtneypacheco committed May 14, 2021
1 parent d61b601 commit 7f03dc5
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion controllers/nodefeaturediscovery_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,41 @@ import (
nfdv1 "github.com/kubernetes-sigs/node-feature-discovery-operator/api/v1"
)

// NFD holds the needed information to watch from the Controller
// NFD holds the needed information to watch from the Controller. The
// following descriptions elaborate on each field in this struct:
type NFD struct {

// resources contains information about NFD's resources. For more
// information, see ./nodefeaturediscovery_resources.go
resources []Resources

// controls is a list that contains the status of an NFD resource
// as being Ready (=0) or NotReady (=1)
controls []controlFunc

// rec represents the NFD reconciler struct used for reconciliation
rec *NodeFeatureDiscoveryReconciler

// ins is the NodeFeatureDiscovery struct that contains the Schema
// for the nodefeaturediscoveries API
ins *nfdv1.NodeFeatureDiscovery

// idx is the index that is used to step through the 'controls' list
// and is set to 0 upon calling 'init()'
idx int
}

// addState takes a given path and finds resources in that path, then
// appends a list of ctrl's functions to the NFD object's 'controls'
// field and adds the list of resources found to 'n.resources'
func (n *NFD) addState(path string) {
res, ctrl := addResourcesControls(path)
n.controls = append(n.controls, ctrl)
n.resources = append(n.resources, res)
}

// init initializes an NFD object by populating the fields before
// attempting to run any kind of check.
func (n *NFD) init(
r *NodeFeatureDiscoveryReconciler,
i *nfdv1.NodeFeatureDiscovery,
Expand All @@ -50,7 +70,17 @@ func (n *NFD) init(
}
}

// step steps through the list of functions stored in 'n.controls',
// then attempts to determine if the given resource is Ready or
// NotReady. (See the following file for a list of functions that
// 'n.controls' can take on: ./nodefeaturediscovery_resources.go.)
func (n *NFD) step() error {

// For each function in n.controls, attempt to check the status of
// the relevant resource. If no error occurs and the resource is
// defined as being "NotReady," then return an error saying it's not
// ready. Otherwise, return the status as being ready, then increment
// the index for n.controls so that we can parse the next resource.
for _, fs := range n.controls[n.idx] {
stat, err := fs(*n)
if err != nil {
Expand All @@ -64,6 +94,8 @@ func (n *NFD) step() error {
return nil
}

// last checks if the last index equals the number of functions
// stored in n.controls.
func (n *NFD) last() bool {
return n.idx == len(n.controls)
}
Expand Down

0 comments on commit 7f03dc5

Please sign in to comment.