Skip to content

Commit

Permalink
operational
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaps committed Jan 3, 2025
1 parent 9f38f3a commit fa6e0db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ type WorkloadStatus struct {
// Resources specifies the compute resources allocated to this workload
// +required
Resources map[string]resource.Quantity `json:"resources"`

// Operational indicates if all pods of the workload are ready
// +optional
Operational bool `json:"operational"`
}

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Kind",type="string",JSONPath=".status.kind"
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".status.type"
// +kubebuilder:printcolumn:name="CPU",type="string",JSONPath=".status.resources.cpu"
// +kubebuilder:printcolumn:name="Memory",type="string",JSONPath=".status.resources.memory"
// +kubebuilder:printcolumn:name="Operational",type="boolean",JSONPath=`.status.operational`

// Workload is the Schema for the workloads API
type Workload struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
- jsonPath: .status.resources.memory
name: Memory
type: string
- format: upper
jsonPath: .status.operational
name: Operational
type: boolean
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -59,6 +63,10 @@ spec:
description: Kind represents the type of workload (redis, postgres,
etc.)
type: string
operational:
description: Operational indicates if all pods of the workload are
ready
type: boolean
resources:
additionalProperties:
anyOf:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ type WorkloadReconciler struct {
// +kubebuilder:rbac:groups=cozystack.io,resources=workloads,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=cozystack.io,resources=workloads/status,verbs=get;update;patch

func (r *WorkloadReconciler) isPodReady(pod *corev1.Pod) bool {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodReady {
return condition.Status == corev1.ConditionTrue
}
}
return false
}

func (r *WorkloadReconciler) reconcilePod(ctx context.Context, pod *corev1.Pod) (ctrl.Result, error) {
logger := log.FromContext(ctx)

Expand Down Expand Up @@ -99,6 +108,7 @@ func (r *WorkloadReconciler) reconcilePod(ctx context.Context, pod *corev1.Pod)
workload.Status.Kind = kind
workload.Status.Type = workloadType
workload.Status.Resources = resources
workload.Status.Operational = r.isPodReady(pod)

return nil
})
Expand Down

0 comments on commit fa6e0db

Please sign in to comment.