-
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.
Improve reconcile flows
- Loading branch information
Showing
13 changed files
with
411 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/redhat-cop/operator-utils/pkg/util/apis" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type Conditions struct { | ||
// +patchMergeKey=type | ||
// +patchStrategy=merge | ||
// +listType=map | ||
// +listMapKey=type | ||
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` | ||
} | ||
|
||
func getOpt(idx int, opts ...string) string { | ||
if len(opts) < idx+1 { | ||
return "" | ||
} | ||
|
||
return opts[idx] | ||
} | ||
|
||
func (s *Conditions) UpdateCondition(conditionType string, conditionStatus metav1.ConditionStatus, opts ...string) { | ||
s.Conditions = apis.AddOrReplaceCondition(metav1.Condition{ | ||
Type: conditionType, | ||
Status: conditionStatus, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: getOpt(0, opts...), | ||
Message: getOpt(1, opts...), | ||
}, s.Conditions) | ||
} | ||
|
||
func (s *Conditions) SetReady(conditionStatus metav1.ConditionStatus, msg ...string) { | ||
s.UpdateCondition(apis.ReconcileSuccess, conditionStatus, apis.ReconcileSuccessReason, getOpt(0, msg...)) | ||
} | ||
|
||
func (s *Conditions) IsReady() bool { | ||
c, exists := apis.GetCondition(apis.ReconcileSuccess, s.Conditions) | ||
if !exists { | ||
return false | ||
} | ||
|
||
return c.Status == metav1.ConditionTrue | ||
} |
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
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
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
Oops, something went wrong.