Skip to content

Commit

Permalink
Add error prints in build-fa-parameters
Browse files Browse the repository at this point in the history
We log an error prior to every time that the function returns an error
  • Loading branch information
razo7 committed Jul 25, 2023
1 parent 49362d3 commit a5f4761
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
15 changes: 8 additions & 7 deletions controllers/fenceagentsremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct
// buildFenceAgentParams collects the FAR's parameters for the node based on FAR CR, and if the CR is missing parameters
// or the CR's name don't match nodeParamter name then return an error
func buildFenceAgentParams(far *v1alpha1.FenceAgentsRemediation) ([]string, error) {
logger := ctrl.Log.WithName("build-fa-parameters")
if far.Spec.NodeParameters == nil || far.Spec.SharedParameters == nil {
return nil, errors.New(errorMissingParams)
err := errors.New(errorMissingParams)
logger.Error(err, "Missing parameters")
return nil, err
}
var fenceAgentParams []string
logger := ctrl.Log.WithName("build-fa-parameters")
// add shared parameters except the action parameter
for paramName, paramVal := range far.Spec.SharedParameters {
if paramName == parameterActionName {
if paramVal != parameterActionValue {
logger.Info("FAR doesn't support any other action than reboot", "action", paramVal)
}
} else {
if paramName != parameterActionName {
fenceAgentParams = appendParamToSlice(fenceAgentParams, paramName, paramVal)
} else if paramVal != parameterActionValue {
logger.Info("FAR doesn't support any other action than reboot", "action", paramVal)
}
}
// ensure the FA uses the reboot action
Expand All @@ -195,6 +195,7 @@ func buildFenceAgentParams(far *v1alpha1.FenceAgentsRemediation) ([]string, erro
fenceAgentParams = appendParamToSlice(fenceAgentParams, paramName, nodeVal)
} else {
err := errors.New(errorMissingNodeParams)
logger.Error(err, "Missing matching nodeParam and CR's name")
return nil, err
}
}
Expand Down
11 changes: 5 additions & 6 deletions test/e2e/far_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
configv1 "github.com/openshift/api/config/v1"

"github.com/medik8s/fence-agents-remediation/api/v1alpha1"
"github.com/medik8s/fence-agents-remediation/controllers"
"github.com/medik8s/fence-agents-remediation/pkg/utils"
e2eUtils "github.com/medik8s/fence-agents-remediation/test/e2e/utils"
)
Expand All @@ -30,7 +31,6 @@ const (
fenceAgentAction = "reboot"
nodeIdentifierPrefixAWS = "--plug"
nodeIdentifierPrefixIPMI = "--ipport"
succeesRebootMessage = "\"Success: Rebooted"
containerName = "manager"

//TODO: try to minimize timeout
Expand Down Expand Up @@ -104,11 +104,10 @@ var _ = Describe("FAR E2e", func() {
})
When("running FAR to reboot two nodes", func() {
It("should successfully remediate the first node", func() {
checkRemediation(nodeName, succeesRebootMessage, nodeBootTimeBefore)
checkRemediation(nodeName, nodeBootTimeBefore)
})
It("should successfully remediate the second node", func() {
checkRemediation(nodeName, succeesRebootMessage, nodeBootTimeBefore)

checkRemediation(nodeName,nodeBootTimeBefore)
})
})
})
Expand Down Expand Up @@ -293,15 +292,15 @@ func wasNodeRebooted(nodeName string, nodeBootTimeBefore time.Time) {
}

// checkRemediation verify whether the node was remediated
func checkRemediation(nodeName, logString string, nodeBootTimeBefore time.Time) {
func checkRemediation(nodeName string, nodeBootTimeBefore time.Time) {
By("Check if FAR NoExecute taint was added")
wasFarTaintAdded(nodeName)

By("Check if the response of the FA was a success")
// TODO: When reboot is running only once and it is running on FAR node, then FAR pod will
// be recreated on a new node and since the FA command won't be exuected again, then the log
// won't include any success message
checkFarLogs(succeesRebootMessage)
checkFarLogs(controllers.SuccessFAResponse)

By("Getting new node's boot time")
wasNodeRebooted(nodeName, nodeBootTimeBefore)
Expand Down

0 comments on commit a5f4761

Please sign in to comment.