-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add conditions
and patch
helpers, and docs to runtime
#101
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6df6c0e
Add `conditions` helper to `runtime`
hiddeco 1cf6ea6
Add support for negative polarity conditions
hiddeco 45d6bb8
Prio Stalled and Reconciling in lexico cond order
hiddeco e1d94e5
Always update ObservedGeneration on condition Set
hiddeco 308c5d6
Support summarizing to condition other than Ready
hiddeco 723c6bd
Add `patch` helper to `runtime`
hiddeco 84a9050
Allow subset message match in MatchConditions
hiddeco 4bae447
Expand `SetAggregate` API and features
hiddeco 4a7e889
Further tidying of runtime and meta elements
hiddeco 16fa76c
Document Kustomize API package
hiddeco ab78173
Document meta API package
hiddeco 94067b9
Document runtime client package
hiddeco 702679a
Document runtime conditions package
hiddeco 7c2b0b8
Document runtime controller package
hiddeco bac7da8
Make runtime dependency package to use meta API
hiddeco 0db78f1
Make runtime errors package errors more generic
hiddeco 0e9caec
Document runtime leaderelection package
hiddeco 2d67687
Document runtime testenv package
hiddeco 4ee6f3b
Document runtime probes package
hiddeco 95d5db3
Document runtime transform package
hiddeco f248cff
Document runtime events package
hiddeco ac747c7
Document runtime logger package
hiddeco 7b2d1e9
Document and extend runtime pprof package
hiddeco 65de24f
Align Go modules with all recent changes
hiddeco 7ec4df6
Document runtime metrics package
hiddeco 06cface
Document runtime predicates package
hiddeco 25fb8b6
Document runtime patch package
hiddeco b7eec63
Fixup: indents in-comment code blocks and wordings
hiddeco 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,62 +17,99 @@ limitations under the License. | |
package meta | ||
|
||
import ( | ||
apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// These constants define generic Condition types to be used by GitOps Toolkit components. | ||
// | ||
// The ReadyCondition SHOULD be implemented by all components' Kubernetes resources to indicate they have been fully | ||
// reconciled by their respective reconciler. This MAY suffice for simple resources, e.g. a resource that just declares | ||
// state once and is not expected to receive any updates afterwards. | ||
// | ||
// For Kubernetes resources that are expected to receive spec updates over time, take a longer time to reconcile, or | ||
// deal with more complex logic in which for example a finite error state can be observed, it is RECOMMENDED to | ||
// implement the StalledCondition and ReconcilingCondition. | ||
// | ||
// By doing this, observers making use of kstatus to determine the current state of the resource will have a better | ||
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. <3 this explanation |
||
// experience while they are e.g. waiting for a change to be reconciled, and will be able to stop waiting for a change | ||
// if a StalledCondition is observed, without having to rely on a timeout. | ||
// | ||
// For more information on kstatus, see: | ||
// https://github.com/kubernetes-sigs/cli-utils/blob/v0.25.0/pkg/kstatus/README.md | ||
const ( | ||
// ReadyCondition is the name of the Ready condition implemented by all toolkit | ||
// resources. | ||
// ReadyCondition indicates the resource is ready and fully reconciled. | ||
// If the Condition is False, the resource SHOULD be considered to be in the process of reconciling and not a | ||
// representation of actual state. | ||
ReadyCondition string = "Ready" | ||
|
||
// StalledCondition is the name of the Stalled kstatus condition | ||
// StalledCondition indicates the reconciliation of the resource has stalled, e.g. because the controller has | ||
// encountered an error during the reconcile process or it has made insufficient progress (timeout). | ||
// The Condition adheres to an "abnormal-true" polarity pattern, and MUST only be present on the resource if the | ||
hiddeco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Condition is True. | ||
// For more information about polarity patterns, see: | ||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties | ||
StalledCondition string = "Stalled" | ||
|
||
// ReconcilingCondition is the name of the Reconciling kstatus condition | ||
// ReconcilingCondition indicates the controller is currently working on reconciling the latest changes. This MAY be | ||
// True for multiple reconciliation attempts, e.g. when an transient error occurred. | ||
// The Condition adheres to an "abnormal-true" polarity pattern, and MUST only be present on the resource if the | ||
// Condition is True. | ||
// For more information about polarity patterns, see: | ||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties | ||
ReconcilingCondition string = "Reconciling" | ||
) | ||
|
||
// These constants define generic Condition reasons to be used by GitOps Toolkit components. | ||
// | ||
// Making use of a generic Reason is RECOMMENDED whenever it can be applied to a Condition in which it provides | ||
// sufficient context together with the type to summarize the meaning of the Condition cause. | ||
// | ||
// Where any of the generic Condition reasons does not suffice, GitOps Toolkit components can introduce new reasons to | ||
// their API specification, or use an arbitrary PascalCase string when setting the Condition. | ||
// Declaration of domain common Condition reasons in the API specification is RECOMMENDED, as it eases observations | ||
// for user and computer. | ||
// | ||
// For more information on Condition reason conventions, see: | ||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties | ||
const ( | ||
// ReconciliationSucceededReason represents the fact that the reconciliation of | ||
// a toolkit resource has succeeded. | ||
ReconciliationSucceededReason string = "ReconciliationSucceeded" | ||
|
||
// ReconciliationFailedReason represents the fact that the reconciliation of a | ||
// toolkit resource has failed. | ||
ReconciliationFailedReason string = "ReconciliationFailed" | ||
|
||
// ProgressingReason represents the fact that the reconciliation of a toolkit | ||
// resource is underway. | ||
// SucceededReason indicates a condition or event observed a success, for example when declared desired state | ||
// matches actual state, or a performed action succeeded. | ||
// | ||
// More information about the reason of success MAY be available as additional metadata in an attached message. | ||
SucceededReason string = "Succeeded" | ||
|
||
// FailedReason indicates a condition or event observed a failure, for example when declared state does not match | ||
// actual state, or a performed action failed. | ||
// | ||
// More information about the reason of failure MAY be available as additional metadata in an attached message. | ||
FailedReason string = "Failed" | ||
|
||
// ProgressingReason indicates a condition or event observed progression, for example when the reconciliation of a | ||
// resource or an action has started. | ||
// | ||
// When this reason is given, other conditions and types MAY no longer be considered as an up-to-date observation. | ||
// Producers of the specific condition type or event SHOULD provide more information about the expectations and | ||
// precise meaning in their API specification. | ||
// | ||
// More information about the reason or the current state of the progression MAY be available as additional metadata | ||
// in an attached message. | ||
ProgressingReason string = "Progressing" | ||
|
||
// DependencyNotReadyReason represents the fact that one of the toolkit resource | ||
// dependencies is not ready. | ||
DependencyNotReadyReason string = "DependencyNotReady" | ||
|
||
// SuspendedReason represents the fact that the reconciliation of a toolkit | ||
// resource is suspended. | ||
// SuspendedReason indicates a condition or event has observed a suspension, for | ||
// example because a resource has been suspended, or a dependency is. | ||
SuspendedReason string = "Suspended" | ||
) | ||
|
||
// ObjectWithStatusConditions is an interface that describes kubernetes resource | ||
// type structs with Status Conditions | ||
// ObjectWithConditions describes a Kubernetes resource object with status conditions. | ||
// +k8s:deepcopy-gen=false | ||
type ObjectWithStatusConditions interface { | ||
GetStatusConditions() *[]metav1.Condition | ||
type ObjectWithConditions interface { | ||
// GetConditions returns a slice of metav1.Condition | ||
GetConditions() []metav1.Condition | ||
} | ||
|
||
// SetResourceCondition sets the given condition with the given status, | ||
// reason and message on a resource. | ||
func SetResourceCondition(obj ObjectWithStatusConditions, condition string, status metav1.ConditionStatus, reason, message string) { | ||
conditions := obj.GetStatusConditions() | ||
|
||
newCondition := metav1.Condition{ | ||
Type: condition, | ||
Status: status, | ||
Reason: reason, | ||
Message: message, | ||
} | ||
|
||
apimeta.SetStatusCondition(conditions, newCondition) | ||
// ObjectWithConditionsSetter describes a Kubernetes resource object with a status conditions setter. | ||
// +k8s:deepcopy-gen=false | ||
type ObjectWithConditionsSetter interface { | ||
// SetConditions sets the status conditions on the object | ||
SetConditions([]metav1.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
Copyright 2021 The Flux authors | ||
|
||
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 meta | ||
|
||
// ObjectWithDependencies describes a Kubernetes resource object with dependencies. | ||
// +k8s:deepcopy-gen=false | ||
type ObjectWithDependencies interface { | ||
// GetDependsOn returns a NamespacedObjectReference list the object depends on. | ||
GetDependsOn() []NamespacedObjectReference | ||
} |
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.
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 think it's time to remove this, we've switched all controllers to
ReconcileRequestAnnotation
in 2020.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 would probably do this in a separate PR to not incorporate more "hidden" breaking changes in this one.