-
Notifications
You must be signed in to change notification settings - Fork 1
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
Go unhealthy if not ready before timeout #306
Open
JohnGarbutt
wants to merge
12
commits into
main
Choose a base branch
from
feature/timeout-k8s-changes
base: main
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
12 commits
Select commit
Hold shift + click to select a range
e6ecca0
Go unhealthy if not ready before timeout
JohnGarbutt 1d0f590
Various fixes after initial testing
JohnGarbutt 2c739f9
Allow unhealthy to be preserved when lease pending
JohnGarbutt f664967
Rework to add status.last_updated_timestamp
JohnGarbutt a789486
Fix up bad timeout logic
JohnGarbutt f34076a
Merge branch 'main' into feature/timeout-k8s-changes
JohnGarbutt 00cf11b
Merge remote-tracking branch 'origin/main' into feature/timeout-k8s-c…
JohnGarbutt 664d8cf
Fix up latest review comments
JohnGarbutt c614460
Merge remote-tracking branch 'origin/feature/timeout-k8s-changes' int…
JohnGarbutt 618b21d
Remove non-required whitespace change
JohnGarbutt e4d7bd5
Add unknown into pending state list.
JohnGarbutt ceafc49
Fix typo
JohnGarbutt 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 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import datetime as dt | ||
import logging | ||
|
||
from .config import settings | ||
from .models.v1alpha1 import ( | ||
ClusterPhase, | ||
LeasePhase, | ||
|
@@ -48,29 +50,28 @@ def _reconcile_cluster_phase(cluster): | |
Sets the overall cluster phase based on the component phases. | ||
""" | ||
# Only consider the lease when reconciling the cluster phase if one is set | ||
if cluster.spec.lease_name: | ||
if ( | ||
cluster.spec.lease_name and | ||
cluster.status.lease_phase not in {LeasePhase.ACTIVE, LeasePhase.UPDATING} | ||
): | ||
if cluster.status.lease_phase in { | ||
LeasePhase.CREATING, | ||
LeasePhase.PENDING, | ||
LeasePhase.STARTING | ||
}: | ||
cluster.status.phase = ClusterPhase.PENDING | ||
return | ||
if cluster.status.lease_phase == LeasePhase.ERROR: | ||
cluster.status.phase = ClusterPhase.FAILED | ||
return | ||
if cluster.status.lease_phase in { | ||
LeasePhase.TERMINATING, | ||
LeasePhase.TERMINATED, | ||
LeasePhase.DELETING | ||
}: | ||
cluster.status.phase = ClusterPhase.UNHEALTHY | ||
return | ||
if cluster.status.lease_phase == LeasePhase.UNKNOWN: | ||
cluster.status.phase = ClusterPhase.PENDING | ||
return | ||
# At this point, either there is no lease or the lease phase is Active or Updating | ||
if cluster.status.networking_phase in { | ||
elif cluster.status.networking_phase in { | ||
NetworkingPhase.PENDING, | ||
NetworkingPhase.PROVISIONING | ||
}: | ||
|
@@ -143,6 +144,30 @@ def _reconcile_cluster_phase(cluster): | |
else: | ||
cluster.status.phase = ClusterPhase.READY | ||
|
||
# If we hit a terminal state, remove the updated timestamp, | ||
if cluster.status.phase in {ClusterPhase.READY, ClusterPhase.FAILED}: | ||
# reset the timeout timestamp, as we are now in a stable state | ||
# if we do not reset the last_updated here, we are unable | ||
# to know at the start of an update if we are re-entering | ||
# due to an error vs starting for the first time since the | ||
# last successful update (or its our fist ever update) | ||
cluster.status.last_updated = None | ||
else: | ||
# if not a terminal state, ensure timestamp has been set | ||
if cluster.status.last_updated is None: | ||
now = dt.datetime.now(dt.timezone.utc) | ||
cluster.status.last_updated = now | ||
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. So this case should still work when the state change isn't triggered by a spec change. I think this means when we get an auto healing failure, we should timeout the operation correctly. But I should re-test that case, for sure. |
||
|
||
# timeout pending states if we are stuck there too long | ||
if cluster.status.phase in {ClusterPhase.PENDING, | ||
ClusterPhase.RECONCILING, | ||
ClusterPhase.UPGRADING}: | ||
now = dt.datetime.now(dt.timezone.utc) | ||
timeout_after = cluster.status.last_updated + dt.timedelta( | ||
seconds=settings.cluster_timeout_seconds) | ||
if now > timeout_after: | ||
cluster.status.phase = ClusterPhase.UNHEALTHY | ||
|
||
|
||
def lease_updated(cluster, obj): | ||
""" | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
shouldn't be possible here - is it a condition you have seen? You should getUNKNOWN
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I saw this in my testing, because this can trigger before the first update completes, because I have not set the idle timer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, but I should include unknown in here, maybe I did hit unknown.