Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable status checks and finalizers for TopologyUpdater #117

Merged
merged 3 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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