forked from gardener/machine-controller-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Machine Phase to Terminating & make drain calculations based on d…
…eletionTimestamp (gardener#564) * Fixes issues with machines being force drained The machines were being force drained during race conditions due to PR gardener#492. This commit fixes that by - Make the drain calculation based on deletion timestamp - Reverted logic from PR gardener#492 to first set machine Termination phase
- Loading branch information
1 parent
7a45ca1
commit c054e44
Showing
8 changed files
with
277 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package time is used to provide the core functionalities of machine-controller-manager | ||
package time | ||
|
||
import ( | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// HasTimeOutOccurred returns true, when time.Now() is more than time + period | ||
func HasTimeOutOccurred(timeStamp metav1.Time, period time.Duration) bool { | ||
// Timeout value obtained by subtracting last operation with expected time out period | ||
timeOut := metav1.Now().Add(-period).Sub(timeStamp.Time) | ||
return timeOut > 0 | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package time_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestTime(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Time Suite") | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package time | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("time", func() { | ||
Describe("#hasTimeOutOccurred", func() { | ||
type setup struct { | ||
timeStamp metav1.Time | ||
period time.Duration | ||
} | ||
type action struct { | ||
} | ||
type expect struct { | ||
timeOutOccurred bool | ||
} | ||
type data struct { | ||
setup setup | ||
action action | ||
expect expect | ||
} | ||
DescribeTable("##TimeOut scenarios", | ||
func(data *data) { | ||
timeOutOccurred := HasTimeOutOccurred(data.setup.timeStamp, data.setup.period) | ||
Expect(timeOutOccurred).To(Equal(data.expect.timeOutOccurred)) | ||
}, | ||
Entry("Time stamp is one hour ago and period is 30mins", &data{ | ||
setup: setup{ | ||
timeStamp: metav1.Time{Time: time.Now().Add(-time.Hour)}, | ||
period: 30 * time.Minute, | ||
}, | ||
expect: expect{ | ||
timeOutOccurred: true, | ||
}, | ||
}), | ||
Entry("Time stamp is one hour ago and period is 90mins", &data{ | ||
setup: setup{ | ||
timeStamp: metav1.Time{Time: time.Now().Add(-time.Hour)}, | ||
period: 90 * time.Minute, | ||
}, | ||
expect: expect{ | ||
timeOutOccurred: false, | ||
}, | ||
}), | ||
Entry("Time stamp is now and period is 5mins", &data{ | ||
setup: setup{ | ||
timeStamp: metav1.Time{Time: time.Now()}, | ||
period: 5 * time.Minute, | ||
}, | ||
expect: expect{ | ||
timeOutOccurred: false, | ||
}, | ||
}), | ||
) | ||
}) | ||
}) |