Skip to content

Commit b4552ce

Browse files
Enable status checks and finalizers for TopologyUpdater (#117)
* Add status checks for TopologyUpdater Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]> Co-authored-by: Markus Lehtonen <[email protected]> * Enable finalizer check for the CRD Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]> * Apply suggestions from code review Co-authored-by: Markus Lehtonen <[email protected]> Co-authored-by: Markus Lehtonen <[email protected]>
1 parent 20a30e5 commit b4552ce

6 files changed

+630
-44
lines changed

controllers/nodefeaturediscovery_controller.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import (
3838
// nfd is an NFD object that will be used to initialize the NFD operator
3939
var nfd NFD
4040

41+
const finalizer = "foreground-deletion"
42+
4143
// NodeFeatureDiscoveryReconciler reconciles a NodeFeatureDiscovery object
4244
type NodeFeatureDiscoveryReconciler struct {
4345

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

154+
// If the resources are to be deleted, first check to see if the
155+
// deletion timestamp pointer is not nil. A non-nil value indicates
156+
// someone or something has triggered the deletion.
157+
if instance.DeletionTimestamp != nil {
158+
return r.finalizeNFDOperand(ctx, instance, finalizer)
159+
}
160+
161+
// If the finalizer doesn't exist, add it.
162+
if !r.hasFinalizer(instance, finalizer) {
163+
return r.addFinalizer(ctx, instance, finalizer)
164+
}
165+
152166
klog.Info("Ready to apply components")
153167
nfd.init(r, instance)
154168
result, err := applyComponents()
@@ -178,14 +192,14 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
178192
}
179193

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

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

247+
// Check if nfd-topology-updater is needed, if not, skip
248+
if instance.Spec.TopologyUpdater {
249+
// Check the status of the NFD Operator TopologyUpdater Worker DaemonSet
250+
if rstatus, err := r.getTopologyUpdaterDaemonSetConditions(ctx, instance); err != nil {
251+
return r.updateDegradedCondition(instance, conditionNFDTopologyUpdaterDaemonSetDegraded, err.Error())
252+
} else if rstatus.isProgressing {
253+
return r.updateProgressingCondition(instance, err.Error(), "nfd-topology-updater Daemonset is progressing")
254+
} else if rstatus.isDegraded {
255+
return r.updateDegradedCondition(instance, err.Error(), "nfd-topology-updater Daemonset has been degraded")
256+
}
257+
// Check the status of the NFD Operator TopologyUpdater cluster role
258+
if rstatus, err := r.getTopologyUpdaterClusterRoleConditions(ctx, instance); err != nil {
259+
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, err.Error())
260+
} else if rstatus.isDegraded {
261+
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, "nfd-topology-updater ClusterRole has been degraded")
262+
}
263+
// Check the status of the NFD Operator TopologyUpdater cluster role binding
264+
if rstatus, err := r.getTopologyUpdaterClusterRoleBindingConditions(ctx, instance); err != nil {
265+
return r.updateDegradedCondition(instance, conditionFailedGettingNFDClusterRoleBinding, err.Error())
266+
} else if rstatus.isDegraded {
267+
return r.updateDegradedCondition(instance, conditionNFDClusterRoleBindingDegraded, "nfd-topology-updater ClusterRoleBinding has been degraded")
268+
}
269+
// Check the status of the NFD Operator TopologyUpdater ServiceAccount
270+
if rstatus, err := r.getTopologyUpdaterServiceAccountConditions(ctx, instance); err != nil {
271+
return r.updateDegradedCondition(instance, conditionFailedGettingNFDTopologyUpdaterServiceAccount, err.Error())
272+
} else if rstatus.isDegraded {
273+
return r.updateDegradedCondition(instance, conditionNFDTopologyUpdaterServiceAccountDegraded, "nfd-topology-updater service account has been degraded")
274+
}
275+
}
276+
233277
// Get available conditions
234278
conditions := r.getAvailableConditions()
235279

controllers/nodefeaturediscovery_controls.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ func ClusterRole(n NFD) (ResourceStatus, error) {
159159

160160
// ClusterRoleBinding checks if a ClusterRoleBinding exists and creates one if it doesn't
161161
func ClusterRoleBinding(n NFD) (ResourceStatus, error) {
162-
163162
// state represents the resource's 'control' function index
164163
state := n.idx
165164

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

211210
// Role checks if a Role exists and creates a Role if it doesn't
212211
func Role(n NFD) (ResourceStatus, error) {
213-
214212
// state represents the resource's 'control' function index
215213
state := n.idx
216214

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

263261
// RoleBinding checks if a RoleBinding exists and creates a RoleBinding if it doesn't
264262
func RoleBinding(n NFD) (ResourceStatus, error) {
265-
266263
// state represents the resource's 'control' function index
267264
state := n.idx
268265

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

316313
// ConfigMap checks if a ConfigMap exists and creates one if it doesn't
317314
func ConfigMap(n NFD) (ResourceStatus, error) {
318-
319315
// state represents the resource's 'control' function index
320316
state := n.idx
321317

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

373369
// DaemonSet checks the readiness of a DaemonSet and creates one if it doesn't exist
374370
func DaemonSet(n NFD) (ResourceStatus, error) {
375-
376371
// state represents the resource's 'control' function index
377372
state := n.idx
378373

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

480475
// Service checks if a Service exists and creates one if it doesn't exist
481476
func Service(n NFD) (ResourceStatus, error) {
482-
483477
// state represents the resource's 'control' function index
484478
state := n.idx
485479

0 commit comments

Comments
 (0)