forked from opendatahub-io/opendatahub-operator
-
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.
Adding scafolding for status reporting. opendatahub-io#158
- Loading branch information
Showing
5 changed files
with
217 additions
and
25 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,148 @@ | ||
/* | ||
Copyright 2023. | ||
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 controllers | ||
|
||
import ( | ||
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// These constants represent the overall Phase as used by .Status.Phase | ||
var ( | ||
// PhaseIgnored is used when a resource is ignored | ||
PhaseIgnored = "Ignored" | ||
// PhaseProgressing is used when SetProgressingCondition is called | ||
PhaseProgressing = "Progressing" | ||
// PhaseError is used when SetErrorCondition is called | ||
PhaseError = "Error" | ||
// PhaseReady is used when SetCompleteCondition is called | ||
PhaseReady = "Ready" | ||
// PhaseNotReady is used when waiting for system to be ready | ||
// after reconcile is successful | ||
PhaseNotReady = "Not Ready" | ||
// PhaseClusterExpanding is used when cluster is expanding capacity | ||
PhaseClusterExpanding = "Expanding Capacity" | ||
// PhaseDeleting is used when cluster is deleting | ||
PhaseDeleting = "Deleting" | ||
// PhaseConnecting is used when cluster is connecting to external cluster | ||
PhaseConnecting = "Connecting" | ||
// PhaseOnboarding is used when consumer is Onboarding | ||
PhaseOnboarding = "Onboarding" | ||
) | ||
|
||
const ( | ||
ConditionReconcileComplete conditionsv1.ConditionType = "ReconcileComplete" | ||
) | ||
|
||
const ( | ||
// TODO: update this list of constants with proper reasons for conditions | ||
AReason = "AReason" | ||
AnotherReason = "AnotherReason" | ||
) | ||
|
||
// SetProgressingCondition sets the ProgressingCondition to True and other conditions to | ||
// false or Unknown. Used when we are just starting to reconcile, and there are no existing | ||
// conditions. | ||
func SetProgressingCondition(conditions *[]conditionsv1.Condition, reason string, message string) { | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: ConditionReconcileComplete, | ||
Status: corev1.ConditionUnknown, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionAvailable, | ||
Status: corev1.ConditionFalse, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionProgressing, | ||
Status: corev1.ConditionTrue, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionDegraded, | ||
Status: corev1.ConditionFalse, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionUpgradeable, | ||
Status: corev1.ConditionUnknown, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
} | ||
|
||
// SetErrorCondition sets the ConditionReconcileComplete to False in case of any errors | ||
// during the reconciliation process. | ||
func SetErrorCondition(conditions *[]conditionsv1.Condition, reason string, message string) { | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: ConditionReconcileComplete, | ||
Status: corev1.ConditionFalse, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
} | ||
|
||
// SetCompleteCondition sets the ConditionReconcileComplete to True and other Conditions | ||
// to indicate that the reconciliation process has completed successfully. | ||
func SetCompleteCondition(conditions *[]conditionsv1.Condition, reason string, message string) { | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: ConditionReconcileComplete, | ||
Status: corev1.ConditionTrue, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionAvailable, | ||
Status: corev1.ConditionTrue, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionProgressing, | ||
Status: corev1.ConditionFalse, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionDegraded, | ||
Status: corev1.ConditionFalse, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{ | ||
Type: conditionsv1.ConditionUpgradeable, | ||
Status: corev1.ConditionTrue, | ||
Reason: reason, | ||
Message: message, | ||
}) | ||
} | ||
|
||
// won't override a status condition of the same type and status | ||
func setStatusConditionIfNotPresent(conditions *[]conditionsv1.Condition, condition conditionsv1.Condition) { | ||
|
||
foundCondition := conditionsv1.FindStatusCondition(*conditions, condition.Type) | ||
if foundCondition != nil && foundCondition.Status == condition.Status { | ||
// already exists | ||
return | ||
} | ||
|
||
conditionsv1.SetStatusCondition(conditions, condition) | ||
} |
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