Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
machine-api-operator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
paas-tools
okd4-deployment
machine-api-operator
Commits
38d83427
Unverified
Commit
38d83427
authored
7 months ago
by
Joel Speed
Browse files
Options
Downloads
Patches
Plain Diff
Ensure deletion annotation takes priority and oldestPolicy can distinguish longer ages
parent
050b12eb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/controller/machineset/delete_policy.go
+7
-2
7 additions, 2 deletions
pkg/controller/machineset/delete_policy.go
pkg/controller/machineset/delete_policy_test.go
+19
-0
19 additions, 0 deletions
pkg/controller/machineset/delete_policy_test.go
with
26 additions
and
2 deletions
pkg/controller/machineset/delete_policy.go
+
7
−
2
View file @
38d83427
...
@@ -44,7 +44,7 @@ const (
...
@@ -44,7 +44,7 @@ const (
couldDelete
deletePriority
=
20.0
couldDelete
deletePriority
=
20.0
mustNotDelete
deletePriority
=
0.0
mustNotDelete
deletePriority
=
0.0
secondsPer
Ten
Days
float64
=
864000
secondsPer
Hundred
Days
float64
=
864000
0
)
)
type
deletePriorityFunc
func
(
machine
*
machinev1
.
Machine
)
deletePriority
type
deletePriorityFunc
func
(
machine
*
machinev1
.
Machine
)
deletePriority
...
@@ -67,7 +67,12 @@ func oldestDeletePriority(machine *machinev1.Machine) deletePriority {
...
@@ -67,7 +67,12 @@ func oldestDeletePriority(machine *machinev1.Machine) deletePriority {
if
d
.
Seconds
()
<
0
{
if
d
.
Seconds
()
<
0
{
return
mustNotDelete
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
{
func
newestDeletePriority
(
machine
*
machinev1
.
Machine
)
deletePriority
{
...
...
This diff is collapsed.
Click to expand it.
pkg/controller/machineset/delete_policy_test.go
+
19
−
0
View file @
38d83427
...
@@ -281,6 +281,9 @@ func TestMachineOldestDelete(t *testing.T) {
...
@@ -281,6 +281,9 @@ func TestMachineOldestDelete(t *testing.T) {
new
:=
&
machinev1
.
Machine
{
ObjectMeta
:
metav1
.
ObjectMeta
{
CreationTimestamp
:
metav1
.
NewTime
(
currentTime
.
Time
.
AddDate
(
0
,
0
,
-
5
))}}
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
))}}
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
))}}
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
))}}
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
))}}
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
}}
unhealthyMachine
:=
&
machinev1
.
Machine
{
ObjectMeta
:
metav1
.
ObjectMeta
{
CreationTimestamp
:
metav1
.
NewTime
(
currentTime
.
Time
.
AddDate
(
0
,
0
,
-
10
))},
Status
:
machinev1
.
MachineStatus
{
ErrorReason
:
&
statusError
}}
...
@@ -347,6 +350,22 @@ func TestMachineOldestDelete(t *testing.T) {
...
@@ -347,6 +350,22 @@ func TestMachineOldestDelete(t *testing.T) {
},
},
expect
:
[]
*
machinev1
.
Machine
{
unhealthyMachine
},
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
{
for
_
,
test
:=
range
tests
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment