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

[release-4.16] OCPBUGS-45998: Ensure deletion annotation takes priority and oldestPolicy can distinguish longer ages #1313

Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions pkg/controller/machineset/delete_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
couldDelete deletePriority = 20.0
mustNotDelete deletePriority = 0.0

secondsPerTenDays float64 = 864000
secondsPerHundredDays float64 = 8640000
)

type deletePriorityFunc func(machine *machinev1.Machine) deletePriority
Expand All @@ -67,7 +67,12 @@ func oldestDeletePriority(machine *machinev1.Machine) deletePriority {
if d.Seconds() < 0 {
return mustNotDelete
}
return deletePriority(float64(mustDelete) * (1.0 - math.Exp(-d.Seconds()/secondsPerTenDays)))

// The oldest machine, not already marked for deletion, should be deleted first.
// The priority is calculated as a function of the time since the machine was created.
// As the machine gets older the exponential term will approach 1, and the priority will approach the value of betterDelete.
// With the current division by secondsPerHundredDays, the priority will tend to betterDelete after approx ~3750 days (~10.3 years).
return deletePriority(float64(betterDelete) * (1.0 - math.Exp(-d.Seconds()/secondsPerHundredDays)))
}

func newestDeletePriority(machine *machinev1.Machine) deletePriority {
Expand Down
19 changes: 19 additions & 0 deletions pkg/controller/machineset/delete_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ func TestMachineOldestDelete(t *testing.T) {
new := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -5))}}
old := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -10))}}
oldest := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -10))}}
old500Day := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -500))}}
old1000Day := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -1000))}}
old3750Day := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -3750))}}
annotatedMachine := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{DeleteNodeAnnotation: "yes"}, CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -1))}}
oldAnnotatedMachine := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{oldDeleteNodeAnnotation: "yes"}, CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -1))}}
unhealthyMachine := &machinev1.Machine{ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.NewTime(currentTime.Time.AddDate(0, 0, -10))}, Status: machinev1.MachineStatus{ErrorReason: &statusError}}
Expand Down Expand Up @@ -347,6 +350,22 @@ func TestMachineOldestDelete(t *testing.T) {
},
expect: []*machinev1.Machine{unhealthyMachine},
},
{
desc: "func=oldestDeletePriority, diff=1 (old but with annotate priority)",
diff: 1,
machines: []*machinev1.Machine{
new, annotatedMachine, old500Day, old1000Day, old3750Day,
},
expect: []*machinev1.Machine{annotatedMachine},
},
{
desc: "func=oldestDeletePriority, diff=3 (old machines in order)",
diff: 3,
machines: []*machinev1.Machine{
new, old500Day, old1000Day, old3750Day,
},
expect: []*machinev1.Machine{old3750Day, old1000Day, old500Day},
},
}

for _, test := range tests {
Expand Down