Skip to content
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

Improve Conditions Returned By ApplicationGroup #313

Merged
merged 13 commits into from
Jun 16, 2021
Merged
66 changes: 42 additions & 24 deletions api/v1alpha1/appgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type WorkflowType string

const (
Forward WorkflowType = "forward"
Reverse WorkflowType = "reverse"
Rollback WorkflowType = "rollback"
)

var WorkflowConditionMap = map[WorkflowType]string{
Forward: meta.ForwardWorkflowSucceededCondition,
Reverse: meta.ReverseWorkflowSucceededCondition,
Rollback: meta.RollbackWorkflowSucceededCondition,
}

const (
DefaultProgressingRequeue = 5 * time.Second
DefaultSucceededRequeue = 5 * time.Minute
Expand All @@ -23,6 +37,10 @@ const (

LastSuccessfulAnnotation = "orkestra/last-successful-applicationgroup"
ParentChartAnnotation = "orkestra/parent-chart"

ForwardWorkflow WorkflowType = "forward"
ReverseWorkflow WorkflowType = "reverse"
RollbackWorkflow WorkflowType = "rollback"
)

// GetInterval returns the interval if specified in the application group
Expand Down Expand Up @@ -133,6 +151,8 @@ type ChartStatus struct {
// ApplicationGroupSpec defines the desired state of ApplicationGroup
type ApplicationGroupSpec struct {
// Applications that make up the application group
// +kubebuilder:validation:MinItems:=1
// +required
Applications []Application `json:"applications,omitempty"`

// Interval specifies the between reconciliations of the ApplicationGroup
Expand Down Expand Up @@ -180,11 +200,7 @@ type ApplicationStatus struct {
type ApplicationGroupStatus struct {
// Applications status
// +optional
Applications []ApplicationStatus `json:"status,omitempty"`

// Phase is the reconciliation phase
// +optional
Update bool `json:"update,omitempty"`
Applications []ApplicationStatus `json:"applications,omitempty"`

// ObservedGeneration captures the last generation
// that was captured and completed by the reconciler
Expand Down Expand Up @@ -238,22 +254,22 @@ func (in *ApplicationGroup) ReadySucceeded() {
meta.SetResourceCondition(in, meta.ReadyCondition, metav1.ConditionTrue, meta.SucceededReason, "workflow and reconciliation succeeded")
}

// ReadyFailed sets the meta.ReadyCondition to 'True' and
// meta.FailedReason reason and message
func (in *ApplicationGroup) ReadyFailed(message string) {
meta.SetResourceCondition(in, meta.ReadyCondition, metav1.ConditionTrue, meta.FailedReason, message)
// WorkflowFailed sets the meta.ReadyCondition to 'False' and
// meta.ReadyWorkflowFailed reason and message
func (in *ApplicationGroup) WorkflowFailed(message string) {
meta.SetResourceCondition(in, meta.ReadyCondition, metav1.ConditionFalse, meta.WorkflowFailedReason, message)
}

// DeploySucceeded sets the meta.DeployCondition to 'True', with the given
// meta.Succeeded reason and message
func (in *ApplicationGroup) DeploySucceeded() {
meta.SetResourceCondition(in, meta.DeployCondition, metav1.ConditionTrue, meta.SucceededReason, "application group reconciliation succeeded")
// ChartPullFailed sets the meta.ReadyCondition to 'False' and
// meta.ChartPullFailedReason reason and message
func (in *ApplicationGroup) ChartPullFailed(message string) {
meta.SetResourceCondition(in, meta.ReadyCondition, metav1.ConditionFalse, meta.ChartPullFailedReason, message)
}

// DeployFailed sets the meta.DeployCondition to 'True' and
// meta.FailedReason reason and message
func (in *ApplicationGroup) DeployFailed(message string) {
meta.SetResourceCondition(in, meta.DeployCondition, metav1.ConditionTrue, meta.FailedReason, message)
// WorkflowTemplateGenerationFailed sets the meta.ReadyCondition to 'False' and
// meta.TemplateGenerationFailed reason and message
func (in *ApplicationGroup) WorkflowTemplateGenerationFailed(message string) {
meta.SetResourceCondition(in, meta.ReadyCondition, metav1.ConditionFalse, meta.WorkflowTemplateGenerationFailedReason, message)
}

// GetReadyCondition gets the string condition.Reason of the
Expand All @@ -266,10 +282,12 @@ func (in *ApplicationGroup) GetReadyCondition() string {
return condition.Reason
}

jonathan-innis marked this conversation as resolved.
Show resolved Hide resolved
// GetDeployCondition gets the string condition.Reason of the
// meta.ReadyCondition type
func (in *ApplicationGroup) GetDeployCondition() string {
condition := meta.GetResourceCondition(in, meta.DeployCondition)
// GetWorkflowCondition gets the string condition.Reason of the given workflow type
func (in *ApplicationGroup) GetWorkflowCondition(wfType WorkflowType) string {
var condition *metav1.Condition
if wfCondition, ok := WorkflowConditionMap[wfType]; ok {
condition = meta.GetResourceCondition(in, wfCondition)
}
if condition == nil {
return meta.ProgressingReason
}
Expand Down Expand Up @@ -306,10 +324,10 @@ func (in *ApplicationGroup) SetLastSuccessful() {
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=applicationgroups,scope=Cluster,shortName=ag
// +kubebuilder:resource:path=applicationgroups,scope=Cluster,shortName={"ag","appgroup"}
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Deploy",type="string",JSONPath=".status.conditions[?(@.type==\"Deploy\")].reason"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].reason"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].reason"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ spec:
plural: applicationgroups
shortNames:
- ag
- appgroup
singular: applicationgroup
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .status.conditions[?(@.type=="Deploy")].reason
name: Deploy
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].reason
name: Ready
name: Reason
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].message
name: Message
Expand Down Expand Up @@ -265,6 +266,7 @@ spec:
required:
- name
type: object
minItems: 1
type: array
interval:
description: Interval specifies the between reconciliations of the ApplicationGroup Defaults to 5s for short requeue and 30s for long requeue
Expand All @@ -273,59 +275,7 @@ spec:
status:
description: ApplicationGroupStatus defines the observed state of ApplicationGroup
properties:
conditions:
description: Conditions holds the conditions of the ApplicationGroup
items:
description: "Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. For example, type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: \"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type Conditions []metav1.Condition `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase. --- Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be useful (see .node.status.conditions), the ability to deconflict is important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
lastSucceededGeneration:
description: LastSucceededGeneration captures the last generation that has successfully completed a full workflow rollout of the application group
format: int64
type: integer
observedGeneration:
description: ObservedGeneration captures the last generation that was captured and completed by the reconciler
format: int64
type: integer
status:
applications:
description: Applications status
items:
description: ApplicationStatus shows the current status of the application helm release
Expand Down Expand Up @@ -448,9 +398,58 @@ spec:
type: string
type: object
type: array
update:
description: Phase is the reconciliation phase
type: boolean
conditions:
description: Conditions holds the conditions of the ApplicationGroup
items:
description: "Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. For example, type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: \"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type Conditions []metav1.Condition `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase. --- Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be useful (see .node.status.conditions), the ability to deconflict is important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
lastSucceededGeneration:
description: LastSucceededGeneration captures the last generation that has successfully completed a full workflow rollout of the application group
format: int64
type: integer
observedGeneration:
description: ObservedGeneration captures the last generation that was captured and completed by the reconciler
format: int64
type: integer
type: object
type: object
served: true
Expand Down
Loading