Skip to content

Commit

Permalink
Verify SuccessFAResponse was received
Browse files Browse the repository at this point in the history
Check on Reconcile that stdout from running the FA equlas to SuccessFAResponse
  • Loading branch information
razo7 committed Jun 15, 2023
1 parent 42bc55d commit fe0534a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions controllers/fenceagentsremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
errorBuildingFAParams = "node parameter is required, and cannot be empty"
parameterNameAction = "--action"
parameterValueActionReboot = "reboot"
SuccessFAResponse = "Success: Rebooted"
)

// FenceAgentsRemediationReconciler reconciles a FenceAgentsRemediation object
Expand Down Expand Up @@ -110,9 +111,18 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct
return emptyResult, err
}
cmd := append([]string{far.Spec.Agent}, faParams...)
// The Fence Agent is excutable and the parameters are valid but we don't know about their values
if _, _, err := r.Executor.Execute(pod, cmd); err != nil {
//TODO: better seperation between errors from wrong shared parameters values and wrong node parameters values
// The Fence Agent is excutable and the parameters structure are valid, but we don't check their values
r.Log.Info("Execute the fence agent", "Fence Agent", far.Spec.Agent, "Node Name", req.Name)
outputRes, outputErr, err := r.Executor.Execute(pod, cmd)
if err != nil {
// response was a failure message
r.Log.Error(err, "Fence Agent response was a failure", "CR's Name", req.Name)
return emptyResult, err
}
if outputErr != "" || outputRes != SuccessFAResponse {
// response wasn't failure or sucesss message
err := fmt.Errorf("unknown fence agent response - expecting `%s` response, but we received `%s`", SuccessFAResponse, outputRes)
r.Log.Error(err, "Fence Agent response wasn't a success message", "CR's Name", req.Name)
return emptyResult, err
}
return emptyResult, nil
Expand Down
2 changes: 1 addition & 1 deletion controllers/fenceagentsremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,5 @@ func newMockExecuter() *mockExecuter {
func (m *mockExecuter) Execute(_ *corev1.Pod, command []string) (stdout string, stderr string, err error) {
m.command = command
m.mockLog.Info("Executed command has been stored", "command", m.command)
return "", "", nil
return SuccessFAResponse, "", nil
}

0 comments on commit fe0534a

Please sign in to comment.