Skip to content
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

Use Common Event API for Remediation cannot start due to node not found #124

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions controllers/machinedeletionremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const (
noMachineAnnotationError = "failed to find openshift machine annotation on node name: %s"
invalidValueMachineAnnotationError = "failed to extract Machine Name and Machine Namespace from machine annotation on the node for node name: %s"
failedToDeleteMachineError = "failed to delete machine of node name: %s"
nodeNotFoundErrorMsg = "failed to fetch node"
machineNotFoundErrorMsg = "failed to fetch machine of node"
nodeNotFoundErrorMsg = "could not get the node"
machineNotFoundErrorMsg = "could not get node's machine"
noControllerOwnerErrorMsg = "ignoring remediation of the machine: the machine has no controller owner"
// Cluster Provider messages
machineDeletedOnCloudProviderMessage = "Machine will be deleted and the unhealthy node replaced. This is a Cloud cluster provider: the new node is expected to have a new name"
Expand All @@ -71,13 +71,13 @@ const (
type conditionChangeReason string

const (
remediationStarted conditionChangeReason = "RemediationStarted"
remediationTimedOutByNhc conditionChangeReason = "RemediationStoppedByNHC"
remediationFinishedMachineDeleted conditionChangeReason = "MachineDeleted"
remediationSkippedNodeNotFound conditionChangeReason = "RemediationSkippedNodeNotFound"
remediationSkippedMachineNotFound conditionChangeReason = "RemediationSkippedMachineNotFound"
remediationSkippedNoControllerOwner conditionChangeReason = "RemediationSkippedNoControllerOwner"
remediationFailed conditionChangeReason = "RemediationFailed"
remediationStarted conditionChangeReason = "RemediationStarted"
remediationTimedOutByNhc conditionChangeReason = "RemediationStoppedByNHC"
remediationFinishedMachineDeleted conditionChangeReason = "MachineDeleted"
remediationCannotStartNodeNotFound conditionChangeReason = "RemediationCannotStartNodeNotFound"
remediationCannotStartMachineNotFound conditionChangeReason = "RemediationCannotStartMachineNotFound"
remediationCannotStartNoControllerOwner conditionChangeReason = "RemediationCannotStartNoControllerOwner"
remediationFailed conditionChangeReason = "RemediationFailed"
)

var (
Expand Down Expand Up @@ -156,11 +156,11 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re
// situation. An error is returned only if it does not match the following custom errors, or
// updateConditions fails.
if err == nodeNotFoundError {
commonevents.WarningEvent(r.Recorder, mdr, string(remediationSkippedNodeNotFound), nodeNotFoundErrorMsg)
_, err = r.updateConditions(remediationSkippedNodeNotFound, mdr)
commonevents.GetTargetNodeFailed(r.Recorder, mdr)
_, err = r.updateConditions(remediationCannotStartNodeNotFound, mdr)
} else if err == machineNotFoundError {
commonevents.WarningEvent(r.Recorder, mdr, string(remediationSkippedMachineNotFound), machineNotFoundErrorMsg)
_, err = r.updateConditions(remediationSkippedMachineNotFound, mdr)
commonevents.WarningEvent(r.Recorder, mdr, string(remediationCannotStartMachineNotFound), machineNotFoundErrorMsg)
_, err = r.updateConditions(remediationCannotStartMachineNotFound, mdr)
} else if err == unrecoverableError {
commonevents.WarningEvent(r.Recorder, mdr, string(remediationFailed), unrecoverableError.Error())
_, err = r.updateConditions(remediationFailed, mdr)
Expand Down Expand Up @@ -233,8 +233,8 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re

if !hasControllerOwner(machine) {
log.Info(noControllerOwnerErrorMsg, "machine", machine.GetName(), "remediation name", mdr.Name)
commonevents.WarningEvent(r.Recorder, mdr, string(remediationSkippedNoControllerOwner), noControllerOwnerErrorMsg)
_, err = r.updateConditions(remediationSkippedNoControllerOwner, mdr)
commonevents.WarningEvent(r.Recorder, mdr, string(remediationCannotStartNoControllerOwner), noControllerOwnerErrorMsg)
_, err = r.updateConditions(remediationCannotStartNoControllerOwner, mdr)
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -418,9 +418,9 @@ func (r *MachineDeletionRemediationReconciler) updateConditions(reason condition
processingConditionStatus = metav1.ConditionFalse
succeededConditionStatus = metav1.ConditionTrue
case remediationTimedOutByNhc,
remediationSkippedNoControllerOwner,
remediationSkippedNodeNotFound,
remediationSkippedMachineNotFound,
remediationCannotStartNoControllerOwner,
remediationCannotStartNodeNotFound,
remediationCannotStartMachineNotFound,
remediationFailed:
processingConditionStatus = metav1.ConditionFalse
succeededConditionStatus = metav1.ConditionFalse
Expand Down
38 changes: 19 additions & 19 deletions controllers/machinedeletionremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyMachineNotDeleted(workerNodeMachineName)
verifyMachineNotDeleted(masterNodeMachineName)
verifyConditionsMatch([]expectedCondition{
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationSkippedNodeNotFound},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationSkippedNodeNotFound}})
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationCannotStartNodeNotFound},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationCannotStartNodeNotFound}})
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNodeNotFound", "failed to fetch node", true},
{v1.EventTypeWarning, "RemediationCannotStart", "Could not get remediation target Node", true},
razo7 marked this conversation as resolved.
Show resolved Hide resolved
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
Expand All @@ -162,12 +162,12 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyMachineNotDeleted(workerNodeMachineName)
verifyMachineNotDeleted(masterNodeMachineName)
verifyConditionsMatch([]expectedCondition{
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationSkippedNoControllerOwner},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationSkippedNoControllerOwner},
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationCannotStartNoControllerOwner},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationCannotStartNoControllerOwner},
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeWarning, string(remediationCannotStartNoControllerOwner), noControllerOwnerErrorMsg, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
Expand All @@ -184,12 +184,12 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyMachineNotDeleted(workerNodeMachineName)
verifyMachineNotDeleted(masterNodeMachineName)
verifyConditionsMatch([]expectedCondition{
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationSkippedNoControllerOwner},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationSkippedNoControllerOwner},
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationCannotStartNoControllerOwner},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationCannotStartNoControllerOwner},
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeWarning, "RemediationCannotStartNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
Expand All @@ -207,13 +207,13 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyMachineNotDeleted(workerNodeMachineName)
verifyMachineNotDeleted(masterNodeMachineName)
verifyConditionsMatch([]expectedCondition{
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationSkippedNoControllerOwner},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationSkippedNoControllerOwner},
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationCannotStartNoControllerOwner},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationCannotStartNoControllerOwner},
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})

verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeWarning, "RemediationCannotStartNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
Expand Down Expand Up @@ -366,11 +366,11 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
}, 30*time.Second, 1*time.Second).Should(BeTrue())

verifyConditionsMatch([]expectedCondition{
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationSkippedNodeNotFound},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationSkippedNodeNotFound}})
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationCannotStartNodeNotFound},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationCannotStartNodeNotFound}})
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNodeNotFound", "failed to fetch node", true},
{v1.EventTypeWarning, "RemediationCannotStart", "Could not get remediation target Node", true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
Expand Down Expand Up @@ -452,17 +452,17 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
Expect(k8sClient.Update(context.Background(), masterNode)).ToNot(HaveOccurred())
})

It("failed to fetch machine error", func() {
It("failed to get machine error", func() {
Eventually(func() bool {
return plogs.Contains(machineNotFoundErrorMsg)
}, 30*time.Second, 1*time.Second).Should(BeTrue())

verifyConditionsMatch([]expectedCondition{
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationSkippedMachineNotFound},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationSkippedMachineNotFound}})
{commonconditions.ProcessingType, metav1.ConditionFalse, remediationCannotStartMachineNotFound},
{commonconditions.SucceededType, metav1.ConditionFalse, remediationCannotStartMachineNotFound}})
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedMachineNotFound", "failed to fetch machine of node", true},
{v1.EventTypeWarning, "RemediationCannotStartMachineNotFound", "could not get node's machine", true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/go-logr/logr v1.4.1
github.com/medik8s/common v1.13.0
github.com/medik8s/common v1.15.1
razo7 marked this conversation as resolved.
Show resolved Hide resolved
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.1
github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e // release-4.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/medik8s/common v1.13.0 h1:M6R2DjJt5dB1uNGPrGxPBiJj9CX0FESUbMm0G04Q3iQ=
github.com/medik8s/common v1.13.0/go.mod h1:Dfbu7aAj4NcYeUPA7BYzcK/JwT+QeU4GlZcJ/p+hXQY=
github.com/medik8s/common v1.15.1 h1:qo2FBZGSegf5q35AZlWzrmgwW1GfUPNmmWaPhb/Uurc=
github.com/medik8s/common v1.15.1/go.mod h1:A9jYldC6PZcAuBowNNm712FqWdASB2ey5Vjp8MYN/PY=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
11 changes: 8 additions & 3 deletions vendor/github.com/medik8s/common/pkg/events/events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ github.com/json-iterator/go
github.com/mailru/easyjson/buffer
github.com/mailru/easyjson/jlexer
github.com/mailru/easyjson/jwriter
# github.com/medik8s/common v1.13.0
# github.com/medik8s/common v1.15.1
## explicit; go 1.20
github.com/medik8s/common/pkg/annotations
github.com/medik8s/common/pkg/conditions
Expand Down
Loading