@@ -38,6 +38,8 @@ import (
3838// nfd is an NFD object that will be used to initialize the NFD operator
3939var nfd NFD
4040
41+ const finalizer = "foreground-deletion"
42+
4143// NodeFeatureDiscoveryReconciler reconciles a NodeFeatureDiscovery object
4244type 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
0 commit comments