-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add logic to set the operator's status in the NFD CR #84
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,16 +140,144 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl | |
r.Log.Info("Ready to apply components") | ||
|
||
nfd.init(r, instance) | ||
result, err := applyComponents() | ||
if err != nil { | ||
return ctrl.Result{Requeue: true}, err | ||
} | ||
|
||
// Check the status of the NFD Operator Worker SecurityContextConstraints | ||
rstatus, err := r.getSecurityContextConstraintsConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDScc, err) | ||
} | ||
Comment on lines
+153
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always first check for error, then other conditions. Ditto X times below Also, you could streamline a bit. Suggestion:
|
||
|
||
// Check the status of the NFD Operator Worker ServiceAccount | ||
rstatus, err = r.getWorkerServiceAccountConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerServiceAccount, err) | ||
} | ||
|
||
// Check the status of the NFD Operator Master ServiceAccount | ||
rstatus, err = r.getMasterServiceAccountConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterServiceAccount, err) | ||
} | ||
|
||
// Check the status of the NFD Operator role | ||
rstatus, err = r.getRoleConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionNFDRoleDegraded, err) | ||
} | ||
|
||
// Check the status of the NFD Operator cluster role | ||
rstatus, err = r.getClusterRoleConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, err) | ||
} | ||
|
||
// Check the status of the NFD Operator cluster role binding | ||
rstatus, err = r.getClusterRoleBindingConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionNFDClusterRoleBindingDegraded, err) | ||
} | ||
|
||
// Check the status of the NFD Operator role binding | ||
rstatus, err = r.getRoleBindingConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDRoleBinding, err) | ||
} | ||
|
||
// Check the status of the NFD Operator Service | ||
rstatus, err = r.getServiceConditions(ctx) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDService, err) | ||
} | ||
|
||
// Check the status of the NFD Operator worker ConfigMap | ||
rstatus, err = r.getWorkerConfigConditions(nfd) | ||
if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerConfig, err) | ||
} | ||
|
||
// Check the status of the NFD Operator Worker DaemonSet | ||
rstatus, err = r.getWorkerDaemonSetConditions(ctx) | ||
if rstatus.isProgressing { | ||
return r.updateProgressingCondition(instance, err.Error(), err) | ||
} else if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerDaemonSet, err) | ||
} | ||
|
||
// Check the status of the NFD Operator Master DaemonSet | ||
rstatus, err = r.getMasterDaemonSetConditions(ctx) | ||
if rstatus.isProgressing { | ||
return r.updateProgressingCondition(instance, err.Error(), err) | ||
|
||
} else if rstatus.isDegraded { | ||
return r.updateDegradedCondition(instance, err.Error(), err) | ||
|
||
} else if err != nil { | ||
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterDaemonSet, err) | ||
} | ||
|
||
// Get available conditions | ||
conditions := r.getAvailableConditions() | ||
|
||
// Update the status of the resource on the CRD | ||
if err := r.updateStatus(instance, conditions); err != nil { | ||
if result != nil { | ||
return *result, nil | ||
} | ||
Comment on lines
+257
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks suspicious, masking the error 😦 |
||
return reconcile.Result{}, err | ||
} | ||
|
||
if result != nil { | ||
return *result, nil | ||
} | ||
|
||
// All objects are healthy during reconcile loop | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func applyComponents() (*reconcile.Result, error) { | ||
|
||
for { | ||
err := nfd.step() | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
return &reconcile.Result{}, err | ||
} | ||
if nfd.last() { | ||
break | ||
} | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
return &ctrl.Result{}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,8 @@ func DaemonSet(n NFD) (ResourceStatus, error) { | |
if obj.ObjectMeta.Name == "nfd-master" { | ||
var args []string | ||
port := defaultServicePort | ||
|
||
// update ports | ||
Comment on lines
+317
to
+318
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unrelated |
||
if n.ins.Spec.Operand.ServicePort != 0 { | ||
port = n.ins.Spec.Operand.ServicePort | ||
} | ||
|
@@ -378,7 +380,6 @@ func Service(n NFD) (ResourceStatus, error) { | |
state := n.idx | ||
obj := n.resources[state].Service | ||
|
||
// update ports | ||
if n.ins.Spec.Operand.ServicePort != 0 { | ||
obj.Spec.Ports[0].Port = int32(n.ins.Spec.Operand.ServicePort) | ||
obj.Spec.Ports[0].TargetPort = intstr.FromInt(n.ins.Spec.Operand.ServicePort) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded empty line. Ditto X times below