Skip to content

Commit

Permalink
Add status checks for TopologyUpdater
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>
Co-authored-by: Markus Lehtonen <markus.lehtonen@intel.com>
  • Loading branch information
ArangoGutierrez and marquiz committed Feb 11, 2022
1 parent 20a30e5 commit e3bbd9a
Show file tree
Hide file tree
Showing 6 changed files with 661 additions and 44 deletions.
48 changes: 46 additions & 2 deletions controllers/nodefeaturediscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
// nfd is an NFD object that will be used to initialize the NFD operator
var nfd NFD

const finalizer = "foreground-deletion"

// NodeFeatureDiscoveryReconciler reconciles a NodeFeatureDiscovery object
type NodeFeatureDiscoveryReconciler struct {

Expand Down Expand Up @@ -149,6 +151,18 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
return ctrl.Result{Requeue: true}, err
}

// If the resources are to be deleted, first check to see if the
// deletion timestamp pointer is not nil. A non-nil value indicates
// someone or something has triggered the deletion.
if instance.DeletionTimestamp != nil {
return r.finalizeNFDOperand(ctx, instance, finalizer)
}

// If the finalizer doesn't exist, add it.
if !r.hasFinalizer(instance, finalizer) {
return r.addFinalizer(ctx, instance, finalizer)
}

klog.Info("Ready to apply components")
nfd.init(r, instance)
result, err := applyComponents()
Expand Down Expand Up @@ -178,14 +192,14 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
}

// Check the status of the NFD Operator cluster role
if rstatus, err := r.getClusterRoleConditions(ctx, instance); err != nil {
if rstatus, err := r.getMasterClusterRoleConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, "nfd ClusterRole has been degraded")
}

// Check the status of the NFD Operator cluster role binding
if rstatus, err := r.getClusterRoleBindingConditions(ctx, instance); err != nil {
if rstatus, err := r.getMasterClusterRoleBindingConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDClusterRoleBinding, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleBindingDegraded, "nfd ClusterRoleBinding has been degraded")
Expand Down Expand Up @@ -230,6 +244,36 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
return r.updateDegradedCondition(instance, err.Error(), "nfd-master Daemonset has been degraded")
}

// Check if nfd-topology-updater is needed, if not, skip
if instance.Spec.TopologyUpdater {
// Check the status of the NFD Operator TopologyUpdater Worker DaemonSet
if rstatus, err := r.getTopologyUpdaterDaemonSetConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionNFDTopologyUpdaterDaemonSetDegraded, err.Error())
} else if rstatus.isProgressing {
return r.updateProgressingCondition(instance, err.Error(), "nfd-topology-updater Daemonset is progressing")
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), "nfd-topology-updater Daemonset has been degraded")
}
// Check the status of the NFD Operator TopologyUpdater cluster role
if rstatus, err := r.getTopologyUpdaterClusterRoleConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, "nfd-topology-updater ClusterRole has been degraded")
}
// Check the status of the NFD Operator TopologyUpdater cluster role binding
if rstatus, err := r.getTopologyUpdaterClusterRoleBindingConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDClusterRoleBinding, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleBindingDegraded, "nfd-topology-updater ClusterRoleBinding has been degraded")
}
// Check the status of the NFD Operator TopologyUpdater ServiceAccount
if rstatus, err := r.getTopologyUpdaterServiceAccountConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDTopologyUpdaterServiceAccount, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDTopologyUpdaterServiceAccountDegraded, "nfd-topology-updater service account has been degraded")
}
}

// Get available conditions
conditions := r.getAvailableConditions()

Expand Down
6 changes: 0 additions & 6 deletions controllers/nodefeaturediscovery_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func ClusterRole(n NFD) (ResourceStatus, error) {

// ClusterRoleBinding checks if a ClusterRoleBinding exists and creates one if it doesn't
func ClusterRoleBinding(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

Expand Down Expand Up @@ -210,7 +209,6 @@ func ClusterRoleBinding(n NFD) (ResourceStatus, error) {

// Role checks if a Role exists and creates a Role if it doesn't
func Role(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

Expand Down Expand Up @@ -262,7 +260,6 @@ func Role(n NFD) (ResourceStatus, error) {

// RoleBinding checks if a RoleBinding exists and creates a RoleBinding if it doesn't
func RoleBinding(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

Expand Down Expand Up @@ -315,7 +312,6 @@ func RoleBinding(n NFD) (ResourceStatus, error) {

// ConfigMap checks if a ConfigMap exists and creates one if it doesn't
func ConfigMap(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

Expand Down Expand Up @@ -372,7 +368,6 @@ func ConfigMap(n NFD) (ResourceStatus, error) {

// DaemonSet checks the readiness of a DaemonSet and creates one if it doesn't exist
func DaemonSet(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

Expand Down Expand Up @@ -479,7 +474,6 @@ func DaemonSet(n NFD) (ResourceStatus, error) {

// Service checks if a Service exists and creates one if it doesn't exist
func Service(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

Expand Down
Loading

0 comments on commit e3bbd9a

Please sign in to comment.