Skip to content

Commit

Permalink
feat!: add Conditions to Projects (#2401)
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
Signed-off-by: Kent Rancourt <[email protected]>
Co-authored-by: Kent Rancourt <[email protected]>
  • Loading branch information
hiddeco and krancour authored Oct 11, 2024
1 parent 8d666c5 commit 172da95
Show file tree
Hide file tree
Showing 11 changed files with 1,030 additions and 337 deletions.
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
505 changes: 283 additions & 222 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 @@ func (p *ProjectPhase) IsTerminal() bool {
// +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 @@ type PromotionPolicy struct {

// 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
}

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

// +kubebuilder:object:root=true

// ProjectList is a list of Project resources.
Expand Down
25 changes: 16 additions & 9 deletions api/v1alpha1/zz_generated.deepcopy.go

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

76 changes: 73 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,81 @@ 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.
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.
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 @@ import (
"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 @@ func newProjectTable(list *metav1.List) *metav1.Table {
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
}

rows[i] = metav1.TableRow{
Cells: []any{
project.Name,
project.Status.Phase,
ready,
status,
duration.HumanDuration(time.Since(project.CreationTimestamp.Time)),
},
Object: list.Items[i],
Expand All @@ -146,7 +155,8 @@ func newProjectTable(list *metav1.List) *metav1.Table {
return &metav1.Table{
ColumnDefinitions: []metav1.TableColumnDefinition{
{Name: "Name", Type: "string"},
{Name: "Phase", Type: "string"},
{Name: "Ready", Type: "string"},
{Name: "Status", Type: "string"},
{Name: "Age", Type: "string"},
},
Rows: rows,
Expand Down
Loading

0 comments on commit 172da95

Please sign in to comment.