-
Notifications
You must be signed in to change notification settings - Fork 138
Fix handling of NotFound errors when deciding if a Failed machine should be terminated #1135
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
Open
thiyyakat
wants to merge
3
commits into
gardener:master
Choose a base branch
from
thiyyakat:bug/not-found-mcs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ import ( | |
| "sync" | ||
| "time" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| apiequality "k8s.io/apimachinery/pkg/api/equality" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
@@ -904,29 +905,32 @@ func isMachineStatusEqual(s1, s2 v1alpha1.MachineStatus) bool { | |
| // or if it is a candidate for auto-preservation. If none of these conditions are met, it returns true indicating | ||
| // that the failed machine should be terminated. | ||
| func (c *controller) shouldFailedMachineBeTerminated(machine *v1alpha1.Machine) bool { | ||
| // if preserve expiry time is set and is in the future, machine is already preserved | ||
| if machine.Status.CurrentStatus.PreserveExpiryTime != nil { | ||
| if machine.Status.CurrentStatus.PreserveExpiryTime.After(time.Now()) { | ||
| klog.V(3).Infof("Failed machine %q is preserved until %v", machine.Name, machine.Status.CurrentStatus.PreserveExpiryTime) | ||
| return false | ||
| } | ||
| klog.V(3).Infof("Preservation of failed machine %q has timed out at %v", machine.Name, machine.Status.CurrentStatus.PreserveExpiryTime) | ||
| var ( | ||
| nodeFound bool | ||
| node *corev1.Node | ||
| err error | ||
| ) | ||
| if machineutils.HasMachinePreservationExpired(machine) { | ||
| klog.V(3).Infof("Preservation of failed machine %q has timed out at %v.", machine.Name, machine.Status.CurrentStatus.PreserveExpiryTime) | ||
| return true | ||
| } | ||
| preserveValue, err := c.findEffectivePreserveValue(machine) | ||
| if err != nil { | ||
| // in case of error fetching node or annotations, we don't want to block deletion of failed machines, so we return true | ||
| klog.Errorf("error finding effective preserve value for machine %q: %v. Proceeding with termination of the machine.", machine.Name, err) | ||
| return true | ||
|
|
||
| nodeName := machine.Labels[v1alpha1.NodeLabelKey] | ||
| if nodeName != "" { | ||
| node, err = c.nodeLister.Get(nodeName) | ||
| if err != nil { | ||
| klog.Warningf("Error fetching node %q of machine %q: %v", nodeName, machine.Name, err) | ||
| } else { | ||
| nodeFound = true | ||
| } | ||
| } | ||
| switch preserveValue { | ||
| case machineutils.PreserveMachineAnnotationValueWhenFailed, machineutils.PreserveMachineAnnotationValueNow, machineutils.PreserveMachineAnnotationValueAutoPreserved: // this is in case preservation process is not complete yet | ||
|
|
||
| preserveInfo := machineutils.GetPreserveStateInfo(node, machine) | ||
|
Member
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. In cases when lister returned |
||
| if machineutils.IsPreservationRequested(machineutils.GetEffectivePreservationAnnotations(&preserveInfo, nodeFound)) { | ||
| klog.V(3).Infof("Failed machine %q is either preserved or in the process of being preserved.", machine.Name) | ||
| return false | ||
| case machineutils.PreserveMachineAnnotationValueFalse: | ||
| return true | ||
| default: | ||
| return true | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| // manageAutoPreservationOfFailedMachines annotates failed machines with preserve=auto-preserved annotation | ||
|
|
@@ -1019,23 +1023,3 @@ func removeAutoPreserveAnnotationFromMachine(machineToUpdate *v1alpha1.Machine) | |
| delete(machineToUpdate.Annotations, machineutils.PreserveMachineAnnotationKey) | ||
| return nil | ||
| } | ||
|
|
||
| func (c *controller) findEffectivePreserveValue(machine *v1alpha1.Machine) (string, error) { | ||
| var nodeAnnotationValue, machineAnnotationValue, lANodeAnnotationValue string | ||
| machineAnnotationValue = machine.Annotations[machineutils.PreserveMachineAnnotationKey] | ||
| lANodeAnnotationValue = machine.Annotations[machineutils.LastAppliedNodePreserveValueAnnotationKey] | ||
| nodeName := machine.Labels[v1alpha1.NodeLabelKey] | ||
| if nodeName != "" { | ||
| node, err := c.nodeLister.Get(nodeName) | ||
| if err != nil { | ||
| klog.Errorf("error fetching node %q for machine %q: %v", nodeName, machine.Name, err) | ||
| return "", err | ||
| } | ||
| nodeAnnotationValue = node.Annotations[machineutils.PreserveMachineAnnotationKey] | ||
| } | ||
| if nodeAnnotationValue == "" && lANodeAnnotationValue == "" { | ||
| return machineAnnotationValue, nil | ||
| } else { | ||
| return nodeAnnotationValue, nil | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.