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

Allow overriding of creation timeout for LoadBalancerMachines #279

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions api/v1beta1/loadbalancerset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// CreationTimeoutAnnotation can be set to override the defaut duration of
maboehm marked this conversation as resolved.
Show resolved Hide resolved
// 10 minutes, after which a new LoadBalancerMachine is deleted (by the LBM)
// if it reports no conditions yet.
CreationTimeoutAnnotation = "yawol.stackit.cloud/creationTimeout"
maboehm marked this conversation as resolved.
Show resolved Hide resolved
maboehm marked this conversation as resolved.
Show resolved Hide resolved
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=lbs
// +kubebuilder:subresource:status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,18 @@ func findFirstMachineForDeletion(machines []yawolv1beta1.LoadBalancerMachine) (y
// True if a condition is not good for 5 minutes
func shouldMachineBeDeleted(machine *yawolv1beta1.LoadBalancerMachine) (shouldDelete bool, reason string) {
before3Minutes := metav1.Time{Time: time.Now().Add(-3 * time.Minute)}
before10Minutes := metav1.Time{Time: time.Now().Add(-10 * time.Minute)}

creationTimeoutDuration := 10 * time.Minute
if v := machine.Annotations[yawolv1beta1.CreationTimeoutAnnotation]; v != "" {
// silently ignore errors
if parsed, err := time.ParseDuration(v); err == nil {
creationTimeoutDuration = parsed
}
}
creationTimeout := time.Now().Add(-1 * creationTimeoutDuration)

// in the first 10 minutes we tolerate empty conditions
if machine.CreationTimestamp.After(before10Minutes.Time) &&
if machine.CreationTimestamp.After(creationTimeout) &&
(machine.Status.Conditions == nil ||
len(*machine.Status.Conditions) == 0) {
return false, ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,29 @@ func TestIsMachineReady(t *testing.T) {
func TestShouldMachineBeDeleted(t *testing.T) {
t.Run("Do not delete if there are no conditions shortly after creation", func(t *testing.T) {
machine := &yawolv1beta1.LoadBalancerMachine{
ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.Time{Time: time.Now().Add(-9 * time.Minute)}},
ObjectMeta: metav1.ObjectMeta{
CreationTimestamp: metav1.Time{Time: time.Now().Add(-9 * time.Minute)},
},
Status: yawolv1beta1.LoadBalancerMachineStatus{
Conditions: nil,
},
}
got, _ := shouldMachineBeDeleted(machine)
want := false

if !reflect.DeepEqual(got, want) {
nschad marked this conversation as resolved.
Show resolved Hide resolved
t.Errorf("Expected %v got %v", want, got)
}
})

t.Run("Do not delete if there are no conditions and the grace period has been adjusted", func(t *testing.T) {
maboehm marked this conversation as resolved.
Show resolved Hide resolved
machine := &yawolv1beta1.LoadBalancerMachine{
ObjectMeta: metav1.ObjectMeta{
CreationTimestamp: metav1.Time{Time: time.Now().Add(-30 * time.Minute)},
Annotations: map[string]string{
yawolv1beta1.CreationTimeoutAnnotation: "1h",
},
},
Status: yawolv1beta1.LoadBalancerMachineStatus{
Conditions: nil,
},
Expand Down