-
Notifications
You must be signed in to change notification settings - Fork 311
Add support for detached annotation #827
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -183,6 +183,10 @@ func (hsm *hostStateMachine) ReconcileState(info *reconcileInfo) (actionRes acti | |
| return actionComplete{} | ||
| } | ||
|
|
||
| if detachedResult := hsm.checkDetachedHost(info); detachedResult != nil { | ||
| return detachedResult | ||
| } | ||
|
|
||
| if registerResult := hsm.ensureRegistered(info); registerResult != nil { | ||
| hostRegistrationRequired.Inc() | ||
| return registerResult | ||
|
|
@@ -216,7 +220,11 @@ func (hsm *hostStateMachine) checkInitiateDelete() bool { | |
| default: | ||
| hsm.NextState = metal3v1alpha1.StateDeleting | ||
| case metal3v1alpha1.StateProvisioning, metal3v1alpha1.StateProvisioned: | ||
| hsm.NextState = metal3v1alpha1.StateDeprovisioning | ||
| if hsm.Host.OperationalStatus() == metal3v1alpha1.OperationalStatusDetached { | ||
| hsm.NextState = metal3v1alpha1.StateDeleting | ||
| } else { | ||
| hsm.NextState = metal3v1alpha1.StateDeprovisioning | ||
| } | ||
| case metal3v1alpha1.StateDeprovisioning: | ||
| // Allow state machine to run to continue deprovisioning. | ||
| return false | ||
|
|
@@ -227,6 +235,46 @@ func (hsm *hostStateMachine) checkInitiateDelete() bool { | |
| return true | ||
| } | ||
|
|
||
| // hasInspectAnnotation checks for existence of baremetalhost.metal3.io/detached | ||
| func hasDetachedAnnotation(host *metal3v1alpha1.BareMetalHost) bool { | ||
| annotations := host.GetAnnotations() | ||
| if annotations != nil { | ||
| if _, ok := annotations[metal3v1alpha1.DetachedAnnotation]; ok { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (hsm *hostStateMachine) checkDetachedHost(info *reconcileInfo) (result actionResult) { | ||
| // If the detached annotation is set we remove any host from the | ||
| // provisioner and take no further action | ||
| // Note this doesn't change the current state, only the OperationalStatus | ||
|
hardys marked this conversation as resolved.
|
||
| if hasDetachedAnnotation(hsm.Host) { | ||
| // Only allow detaching hosts in Provisioned/ExternallyProvisioned states | ||
| switch info.host.Status.Provisioning.State { | ||
| case metal3v1alpha1.StateProvisioned, metal3v1alpha1.StateExternallyProvisioned: | ||
|
Member
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. There's probably a case to be made for allowing this in the Ready/Available state, but I'm fine with leaving it until someone actually has a requirement for it. |
||
| return hsm.Reconciler.detachHost(hsm.Provisioner, info) | ||
| } | ||
| } | ||
| if info.host.Status.ErrorType == metal3v1alpha1.DetachError { | ||
|
hardys marked this conversation as resolved.
|
||
| clearError(info.host) | ||
| hsm.Host.Status.ErrorCount = 0 | ||
| info.log.Info("removed detach error") | ||
| return actionUpdate{} | ||
| } | ||
| if info.host.OperationalStatus() == metal3v1alpha1.OperationalStatusDetached { | ||
| newStatus := metal3v1alpha1.OperationalStatusOK | ||
| if info.host.Status.ErrorType != "" { | ||
|
zaneb marked this conversation as resolved.
|
||
| newStatus = metal3v1alpha1.OperationalStatusError | ||
| } | ||
| info.host.SetOperationalStatus(newStatus) | ||
| info.log.Info("removed detached status") | ||
| return actionUpdate{} | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (hsm *hostStateMachine) ensureRegistered(info *reconcileInfo) (result actionResult) { | ||
| if !hsm.haveCreds { | ||
| // If we are in the process of deletion (which may start with | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.