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

feat!: add Conditions to Projects #2401

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api/v1alpha1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ const (
// reconciled.
ConditionTypeReconciling = "Reconciling"

// ConditionTypeStalled denotes that the reconciliation of the resource
// has stalled.
//
// This condition is used to indicate that the controller has stopped
// making progress on the resource, and further changes to the resource
// are not expected until the reason for the stall is resolved, which
// MAY require manual intervention. The condition is removed when the
// controller has resumed making progress on the resource.
//
// This is a "normal-false" or "negative polarity" condition, meaning
// that the presence of the condition with a status of "True" indicates
// that the resource has stalled, and the absence of the condition or
// a status of "False" indicates that the resource is operating as
// expected.
ConditionTypeStalled = "Stalled"

// ConditionTypeHealthy denotes that the resource is healthy.
//
// The meaning of "healthy" is specific to the resource type. For example,
Expand Down
579 changes: 320 additions & 259 deletions api/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions api/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion api/v1alpha1/project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name=Phase,type=string,JSONPath=`.status.phase`
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message"
// +kubebuilder:printcolumn:name=Age,type=date,JSONPath=`.metadata.creationTimestamp`

// Project is a resource type that reconciles to a specially labeled namespace
Expand Down Expand Up @@ -73,14 +74,33 @@

// ProjectStatus describes a Project's current status.
type ProjectStatus struct {
// Conditions contains the last observations of the Project's current
// state.
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchMergeKey:"type" patchStrategy:"merge" protobuf:"bytes,3,rep,name=conditions"`
// Phase describes the Project's current phase.
//
// Deprecated: Use the Conditions field instead.
Phase ProjectPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
// Message is a display message about the Project, including any errors
// preventing the Project from being reconciled. i.e. If the Phase field has a
// value of CreationFailed, this field can be expected to explain why.
//
// Deprecated: Use the Conditions field instead.
Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
}

func (w *ProjectStatus) GetConditions() []metav1.Condition {
return w.Conditions

Check warning on line 97 in api/v1alpha1/project_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/project_types.go#L96-L97

Added lines #L96 - L97 were not covered by tests
}

func (w *ProjectStatus) SetConditions(conditions []metav1.Condition) {
w.Conditions = conditions

Check warning on line 101 in api/v1alpha1/project_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/project_types.go#L100-L101

Added lines #L100 - L101 were not covered by tests
}

// +kubebuilder:object:root=true

// ProjectList is a list of Project resources.
Expand Down
9 changes: 8 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 88 additions & 3 deletions charts/kargo/resources/crds/kargo.akuity.io_projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ spec:
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].message
name: Status
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -79,14 +82,96 @@ spec:
status:
description: Status describes the Project's current status.
properties:
conditions:
description: |-
Conditions contains the last observations of the Project's current
state.
items:
description: "Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
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
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
message:
description: |-
Message is a display message about the Project, including any errors
preventing the Project from being reconciled. i.e. If the Phase field has a
value of CreationFailed, this field can be expected to explain why.


Deprecated: Use the Conditions field instead.
type: string
phase:
description: Phase describes the Project's current phase.
description: |-
Phase describes the Project's current phase.


Deprecated: Use the Conditions field instead.
type: string
type: object
type: object
Expand Down
14 changes: 12 additions & 2 deletions internal/cli/cmd/get/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"github.com/akuity/kargo/internal/cli/io"
"github.com/akuity/kargo/internal/cli/kubernetes"
"github.com/akuity/kargo/internal/cli/templates"
"github.com/akuity/kargo/internal/conditions"
v1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
)

Expand Down Expand Up @@ -134,10 +135,18 @@
rows := make([]metav1.TableRow, len(list.Items))
for i, item := range list.Items {
project := item.Object.(*kargoapi.Project) // nolint: forcetypeassert

var ready, status = string(metav1.ConditionUnknown), ""
if readyCond := conditions.Get(&project.Status, kargoapi.ConditionTypeReady); readyCond != nil {
ready = string(readyCond.Status)
status = readyCond.Message

Check warning on line 142 in internal/cli/cmd/get/projects.go

View check run for this annotation

Codecov / codecov/patch

internal/cli/cmd/get/projects.go#L139-L142

Added lines #L139 - L142 were not covered by tests
}

rows[i] = metav1.TableRow{
Cells: []any{
project.Name,
project.Status.Phase,
ready,
status,

Check warning on line 149 in internal/cli/cmd/get/projects.go

View check run for this annotation

Codecov / codecov/patch

internal/cli/cmd/get/projects.go#L148-L149

Added lines #L148 - L149 were not covered by tests
duration.HumanDuration(time.Since(project.CreationTimestamp.Time)),
},
Object: list.Items[i],
Expand All @@ -146,7 +155,8 @@
return &metav1.Table{
ColumnDefinitions: []metav1.TableColumnDefinition{
{Name: "Name", Type: "string"},
{Name: "Phase", Type: "string"},
{Name: "Ready", Type: "string"},
{Name: "Status", Type: "string"},

Check warning on line 159 in internal/cli/cmd/get/projects.go

View check run for this annotation

Codecov / codecov/patch

internal/cli/cmd/get/projects.go#L158-L159

Added lines #L158 - L159 were not covered by tests
{Name: "Age", Type: "string"},
},
Rows: rows,
Expand Down
Loading
Loading