-
Notifications
You must be signed in to change notification settings - Fork 150
Operator status revisions #139
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
Closed
benjaminapetersen
wants to merge
11
commits into
openshift:master
from
benjaminapetersen:operator-status-revisions
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
62e1e49
Operator status
jhadvig 5939692
remove race
jhadvig 29d48f5
remove aggregation
jhadvig c98bd0a
1
jhadvig 5e1f548
debug
jhadvig b8e4e18
Extract setUnmanagedConditions() into separate file/func
benjaminapetersen b3a496e
f
benjaminapetersen 9988728
Extract operator status updates into separate functions
benjaminapetersen 657ac0f
f
benjaminapetersen 817efcc
Add log messages to operator status funcs
benjaminapetersen a7cca40
Revise all status.condition funcs to ensure symmetry
benjaminapetersen 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| apiVersion: config.openshift.io/v1 | ||
| kind: ClusterOperator | ||
| metadata: | ||
| name: console | ||
| spec: {} |
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 |
|---|---|---|
| @@ -0,0 +1,257 @@ | ||
| package operator | ||
|
Contributor
Author
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. These are pretty verbose / repetitive. |
||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| operatorsv1 "github.com/openshift/api/operator/v1" | ||
| "github.com/openshift/library-go/pkg/operator/v1helpers" | ||
| ) | ||
|
|
||
| // Operator status is set on the Operator Config, which is: | ||
| // group: console.operator.openshift.io | ||
| // kind: Console | ||
| // name: console | ||
| // And is replicated out onto the the clusteroperator by a separate sync loop: | ||
| // group: config.openshift.io | ||
| // kind: ClusterOperator | ||
| // name: console | ||
| // | ||
| // Status Condition Types | ||
| // Status conditions should not be set to a "default" state when the operator starts up. | ||
| // Instead, set a status explicitly only when the state is known. This is because | ||
| // the various status conditions may have been set on previous runs of the sync loop, or | ||
| // possibly even by a previous operator container. | ||
| // | ||
| // Available = the operand (not the operator) is available | ||
| // example: the console resources are stabilized. | ||
| // example: the console is not yet in a functional state, one or | ||
| // more resources may be missing. | ||
| // Progressing = the operator is trying to transition operand state | ||
| // example: during the initial deployment, the operator needs to create a number | ||
| // of resources. the console (operand) is likely in flux. | ||
| // example: the assigned route .spec.host changes for the console. the oauthclient | ||
| // must be updated, as must the configmap, etc. numerous resources are in flux, | ||
| // the operator reports progressing until the resources stabilize | ||
| // Failing = the operator (not the operand) is failing | ||
| // example: The console operator is unable to update the console config with | ||
| // a new logoutRedirect URL. The operator is failing to do its job, however the | ||
| // console (operand) may or may not be functional (see Available above). | ||
| // | ||
| // | ||
| // Status Condition Reason & Message | ||
| // Reason: OperatorSyncLoopError | ||
| // Message: "The operator sync loop was not completed successfully" | ||
| // | ||
| // | ||
|
|
||
| // Lets transition to using this, and get the repetition out of all of the above. | ||
| func (c *consoleOperator) SyncStatus(operatorConfig *operatorsv1.Console) (*operatorsv1.Console, error) { | ||
| updatedConfig, err := c.operatorConfigClient.UpdateStatus(operatorConfig) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("status update error: %v \n", err) | ||
| } | ||
| return updatedConfig, nil | ||
| } | ||
|
|
||
| // setStatusCondition | ||
| // A generic helper for setting a status condition | ||
| // examples: | ||
| // setStatusCondition(operatorConfig, Failing, True, "SyncLoopError", "Sync loop failed to complete successfully") | ||
| func (c *consoleOperator) SetStatusCondition(operatorConfig *operatorsv1.Console, conditionType string, conditionStatus operatorsv1.ConditionStatus, conditionReason string, conditionMessage string) *operatorsv1.Console { | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: conditionType, | ||
| Status: conditionStatus, | ||
| Reason: conditionReason, | ||
| Message: conditionMessage, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| // examples: | ||
| // conditionFailing(operatorConfig, "SyncLoopError", "Sync loop failed to complete successfully") | ||
| func (c *consoleOperator) ConditionFailing(operatorConfig *operatorsv1.Console, conditionReason string, conditionMessage string) *operatorsv1.Console { | ||
| fmt.Printf( | ||
| "Status: %s %s %s %s %s", | ||
| operatorsv1.OperatorStatusTypeFailing, | ||
| operatorsv1.ConditionTrue, | ||
| conditionReason, | ||
| conditionMessage, | ||
| metav1.Now()) | ||
| // conditionReason string, conditionMessage string | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeFailing, | ||
| Status: operatorsv1.ConditionTrue, | ||
| Reason: conditionReason, | ||
| Message: conditionMessage, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionNotFailing(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeFailing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionProgressing() { | ||
| // TODO: if progressing, we are saying something is moving and we need to report why. | ||
| } | ||
| func (c *consoleOperator) ConditionNotProgressing(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeProgressing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionAvailable(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeAvailable, | ||
| Status: operatorsv1.ConditionTrue, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionNotAvailable(operatorConfig *operatorsv1.Console) { | ||
| // TODO: if not available, something with the operand is wrong asd we need to report why | ||
| } | ||
|
|
||
| // A sync failure has happened. | ||
| // We dont necessarily know the condition of the operand (console), | ||
| // but we do know that the operator is failing to update the operand. | ||
| func (c *consoleOperator) ConditionResourceSyncFailure(operatorConfig *operatorsv1.Console, message string) *operatorsv1.Console { | ||
| logrus.Printf("Status: Workload sync failure: %v \n", message) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeFailing, | ||
| Status: operatorsv1.ConditionTrue, | ||
| Message: message, | ||
| Reason: "SyncError", | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionResourceSyncSuccess(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| logrus.Printf("Status: Workload sync success: \n") | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeFailing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionDeploymentAvailable(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| logrus.Printf("Status: Available: console pods available \n") | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeAvailable, | ||
| Status: operatorsv1.ConditionTrue, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionDeploymentNotAvailable(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| reason := "NoPodsAvailable" | ||
| message := "No pods available for Console deployment." | ||
| logrus.Printf("Status: Not Available: %v \n", message) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeAvailable, | ||
| Status: operatorsv1.ConditionFalse, | ||
| Reason: reason, | ||
| Message: message, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionResourceSyncProgressing(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| reason := "SyncLoopProgressing" | ||
| message := "Changes made during sync updates, additional sync expected." | ||
| logrus.Printf("Status: Progressing: %v \n", message) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeProgressing, | ||
| Status: operatorsv1.ConditionTrue, | ||
| Reason: reason, | ||
| Message: message, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| func (c *consoleOperator) ConditionResourceSyncNotProgressing(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| logrus.Printf("Status: Not Progressing: Sync success \n") | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeProgressing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| // sets multiple conditions | ||
| func (c *consoleOperator) ConditionsManagementStateUnmanaged(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| logrus.Printf("Status: ManagementState: Removed. Conditions unknown.") | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeAvailable, | ||
| Status: operatorsv1.ConditionUnknown, | ||
| Reason: "ManagementStateUnmanaged", | ||
| Message: "the operator is in an unmanaged state, therefore its availability is unknown.", | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeProgressing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| Reason: "ManagementStateUnmanaged", | ||
| Message: "the operator is in an unmanaged state, therefore no changes are being applied.", | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeFailing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| Reason: "ManagementStateUnmanaged", | ||
| Message: "the operator is in an unmanaged state, therefore no operator actions are failing.", | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
|
|
||
| // sets multiple conditions | ||
| func (c *consoleOperator) ConditionsManagementStateRemoved(operatorConfig *operatorsv1.Console) *operatorsv1.Console { | ||
| logrus.Printf("Status: ManagementState: Removed") | ||
| reason := "ManagementStateRemoved" | ||
| message := "The console has been removed." | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeAvailable, | ||
| Status: operatorsv1.ConditionFalse, | ||
| Reason: reason, | ||
| Message: message, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeProgressing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| Reason: reason, | ||
| Message: message, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{ | ||
| Type: operatorsv1.OperatorStatusTypeFailing, | ||
| Status: operatorsv1.ConditionFalse, | ||
| Reason: reason, | ||
| Message: message, | ||
| LastTransitionTime: metav1.Now(), | ||
| }) | ||
| return operatorConfig | ||
| } | ||
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.
I didn't notice this change, I need to look into it a bit.