-
Notifications
You must be signed in to change notification settings - Fork 1.8k
pkg/ansible: introduce managedStatus flag #744
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
15 commits
Select commit
Hold shift + click to select a range
6adbab4
ansible: introduce managedStatus flag
djzager 90b5098
manageStatus from watches.yaml should be *bool
djzager 556cdf9
Add managedStatus value from commandline
djzager 88080d2
Document the manageStatus flag
djzager 4c3bb83
Reconcile test for no manage status
djzager 70269a3
Test manageStatus: true for watches
djzager 8bc1830
managedStatus -> manageStatus, not runtime configurable
djzager f6a8364
Update documentation, add new test for default
djzager e3074ba
Reference last time pkg/sdk existed
djzager e9dd599
Update runner tests to handle manageStatus
djzager 0c18384
Default manageStatus to true
djzager 9053674
Move plain type into UnmarshalYAML
djzager 38a5ddd
Formatting fixes
djzager 9be1ddc
Put the runner.manageStatus on the controller options
djzager 66e2e7f
Add GetManageStatus to fake runner
djzager 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 |
---|---|---|
|
@@ -54,6 +54,7 @@ type AnsibleOperatorReconciler struct { | |
Client client.Client | ||
EventHandlers []events.EventHandler | ||
ReconcilePeriod time.Duration | ||
ManageStatus bool | ||
} | ||
|
||
// Reconcile - handle the event. | ||
|
@@ -112,28 +113,9 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc | |
return reconcileResult, err | ||
} | ||
} | ||
statusInterface := u.Object["status"] | ||
statusMap, _ := statusInterface.(map[string]interface{}) | ||
crStatus := ansiblestatus.CreateFromMap(statusMap) | ||
|
||
// If there is no current status add that we are working on this resource. | ||
errCond := ansiblestatus.GetCondition(crStatus, ansiblestatus.FailureConditionType) | ||
succCond := ansiblestatus.GetCondition(crStatus, ansiblestatus.RunningConditionType) | ||
|
||
// If the condition is currently running, making sure that the values are correct. | ||
// If they are the same a no-op, if they are different then it is a good thing we | ||
// are updating it. | ||
if (errCond == nil && succCond == nil) || (succCond != nil && succCond.Reason != ansiblestatus.SuccessfulReason) { | ||
c := ansiblestatus.NewCondition( | ||
ansiblestatus.RunningConditionType, | ||
v1.ConditionTrue, | ||
nil, | ||
ansiblestatus.RunningReason, | ||
ansiblestatus.RunningMessage, | ||
) | ||
ansiblestatus.SetCondition(&crStatus, *c) | ||
u.Object["status"] = crStatus.GetJSONMap() | ||
err = r.Client.Update(context.TODO(), u) | ||
if r.ManageStatus { | ||
err = r.markRunning(u) | ||
if err != nil { | ||
return reconcileResult, err | ||
} | ||
|
@@ -205,6 +187,48 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc | |
return reconcileResult, err | ||
} | ||
} | ||
if r.ManageStatus { | ||
err = r.markDone(u, statusEvent, failureMessages) | ||
} | ||
return reconcileResult, err | ||
} | ||
|
||
func (r *AnsibleOperatorReconciler) markRunning(u *unstructured.Unstructured) error { | ||
statusInterface := u.Object["status"] | ||
statusMap, _ := statusInterface.(map[string]interface{}) | ||
crStatus := ansiblestatus.CreateFromMap(statusMap) | ||
|
||
// If there is no current status add that we are working on this resource. | ||
errCond := ansiblestatus.GetCondition(crStatus, ansiblestatus.FailureConditionType) | ||
succCond := ansiblestatus.GetCondition(crStatus, ansiblestatus.RunningConditionType) | ||
|
||
// If the condition is currently running, making sure that the values are correct. | ||
// If they are the same a no-op, if they are different then it is a good thing we | ||
// are updating it. | ||
if (errCond == nil && succCond == nil) || (succCond != nil && succCond.Reason != ansiblestatus.SuccessfulReason) { | ||
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. +1 |
||
c := ansiblestatus.NewCondition( | ||
ansiblestatus.RunningConditionType, | ||
v1.ConditionTrue, | ||
nil, | ||
ansiblestatus.RunningReason, | ||
ansiblestatus.RunningMessage, | ||
) | ||
ansiblestatus.SetCondition(&crStatus, *c) | ||
u.Object["status"] = crStatus.GetJSONMap() | ||
err := r.Client.Update(context.TODO(), u) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (r *AnsibleOperatorReconciler) markDone(u *unstructured.Unstructured, statusEvent eventapi.StatusJobEvent, failureMessages eventapi.FailureMessages) error { | ||
statusInterface := u.Object["status"] | ||
statusMap, _ := statusInterface.(map[string]interface{}) | ||
crStatus := ansiblestatus.CreateFromMap(statusMap) | ||
|
||
runSuccessful := len(failureMessages) == 0 | ||
ansibleStatus := ansiblestatus.NewAnsibleResultFromStatusJobEvent(statusEvent) | ||
|
||
if !runSuccessful { | ||
|
@@ -233,9 +257,8 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc | |
} | ||
// This needs the status subresource to be enabled by default. | ||
u.Object["status"] = crStatus.GetJSONMap() | ||
err = r.Client.Update(context.TODO(), u) | ||
return reconcileResult, err | ||
|
||
return r.Client.Update(context.TODO(), u) | ||
} | ||
|
||
func contains(l []string, s string) bool { | ||
|
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
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.
Can you also update the
doc/ansible/dev/developer-guide.yaml
and either remove the watches file section there or update it?I vote to remove so that this is only documented in one place to keep track of.