Skip to content

Commit 637b32d

Browse files
committed
Add replica information to printer columns for workloads and workload deployments, add ReadyReplicas information.
1 parent 9b7d1ea commit 637b32d

File tree

6 files changed

+145
-59
lines changed

6 files changed

+145
-59
lines changed

api/v1alpha/workload_types.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ type WorkloadStatus struct {
5252
// Known condition types are: "Available", "Progressing"
5353
Conditions []metav1.Condition `json:"conditions,omitempty"`
5454

55-
// The number of instances created by a placement
55+
// The number of deployments that currently exist
56+
Deployments int32 `json:"deployments"`
57+
58+
// The number of instances that currently exist
5659
Replicas int32 `json:"replicas"`
5760

58-
// The number of instances created by a placement and have the latest
59-
// workload generation settings applied.
61+
// The number of instances which have the latest workload settings applied.
6062
CurrentReplicas int32 `json:"currentReplicas"`
6163

62-
// The desired number of instances to be managed by a placement.
64+
// The desired number of instances
6365
DesiredReplicas int32 `json:"desiredReplicas"`
6466

65-
// TODO(jreese) ReadyReplicas?
67+
// The number of instances which are ready.
68+
ReadyReplicas int32 `json:"readyReplicas"`
6669

6770
// The current status of placemetns in a workload.
6871
Placements []WorkloadPlacementStatus `json:"placements,omitempty"`
@@ -91,6 +94,11 @@ type WorkloadGatewayStatus struct {
9194
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
9295
// +kubebuilder:printcolumn:name="Available",type=string,JSONPath=`.status.conditions[?(@.type=="Available")].status`
9396
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Available")].reason`
97+
// +kubebuilder:printcolumn:name="Deployments",type=string,JSONPath=`.status.deployments`
98+
// +kubebuilder:printcolumn:name="Replicas",type=string,JSONPath=`.status.replicas`
99+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.readyReplicas`
100+
// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.status.desiredReplicas`
101+
// +kubebuilder:printcolumn:name="Up-to-date",type=string,JSONPath=`.status.currentReplicas`
94102
type Workload struct {
95103
metav1.TypeMeta `json:",inline"`
96104
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -134,17 +142,17 @@ type WorkloadPlacementStatus struct {
134142
// Known condition types are: "Available", "Progressing"
135143
Conditions []metav1.Condition `json:"conditions,omitempty"`
136144

137-
// The number of instances created by a placement
145+
// The number of instances that currently exist
138146
Replicas int32 `json:"replicas"`
139147

140-
// The number of instances created by a placement and have the latest
141-
// workload generation settings applied.
148+
// The number of instances which have the latest workload settings applied.
142149
CurrentReplicas int32 `json:"currentReplicas"`
143150

144-
// The desired number of instances to be managed by a placement.
151+
// The desired number of instances
145152
DesiredReplicas int32 `json:"desiredReplicas"`
146153

147-
// TODO(jreese) ReadyReplicas?
154+
// The number of instances which are ready.
155+
ReadyReplicas int32 `json:"readyReplicas"`
148156
}
149157

150158
type HorizontalScaleSettings struct {

api/v1alpha/workloaddeployment_types.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ type WorkloadDeploymentStatus struct {
4646
// Known condition types are: "Available", "Progressing"
4747
Conditions []metav1.Condition `json:"conditions,omitempty"`
4848

49-
// The number of instances created by a deployment
49+
// The number of instances created
5050
Replicas int32 `json:"replicas"`
5151

52-
// The number of instances created by a deployment and have the latest
53-
// deployment template settings applied.
52+
// The number of instances which have the latest workload settings applied.
5453
CurrentReplicas int32 `json:"currentReplicas"`
5554

56-
// The desired number of instances to be managed by a deployment.
55+
// The desired number of instances
5756
DesiredReplicas int32 `json:"desiredReplicas"`
5857

59-
// TODO(jreese) ReadyReplicas?
58+
// The number of instances which are ready.
59+
ReadyReplicas int32 `json:"readyReplicas"`
6060
}
6161

6262
const (
@@ -70,10 +70,14 @@ const (
7070

7171
// WorkloadDeployment is the Schema for the workloaddeployments API
7272
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
73-
// +kubebuilder:printcolumn:name="Location Namespce",type=string,JSONPath=`.status.location.namespace`
74-
// +kubebuilder:printcolumn:name="Location Name",type=string,JSONPath=`.status.location.name`
7573
// +kubebuilder:printcolumn:name="Available",type=string,JSONPath=`.status.conditions[?(@.type=="Available")].status`
7674
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Available")].reason`
75+
// +kubebuilder:printcolumn:name="Replicas",type=string,JSONPath=`.status.replicas`
76+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.readyReplicas`
77+
// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.status.desiredReplicas`
78+
// +kubebuilder:printcolumn:name="Up-to-date",type=string,JSONPath=`.status.currentReplicas`
79+
// +kubebuilder:printcolumn:name="Location Namespace",type=string,JSONPath=`.status.location.namespace`,priority=1
80+
// +kubebuilder:printcolumn:name="Location Name",type=string,JSONPath=`.status.location.name`,priority=1
7781
type WorkloadDeployment struct {
7882
metav1.TypeMeta `json:",inline"`
7983
metav1.ObjectMeta `json:"metadata,omitempty"`

config/crd/bases/compute.datumapis.com_workloaddeployments.yaml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,32 @@ spec:
1818
- jsonPath: .metadata.creationTimestamp
1919
name: Age
2020
type: date
21-
- jsonPath: .status.location.namespace
22-
name: Location Namespce
23-
type: string
24-
- jsonPath: .status.location.name
25-
name: Location Name
26-
type: string
2721
- jsonPath: .status.conditions[?(@.type=="Available")].status
2822
name: Available
2923
type: string
3024
- jsonPath: .status.conditions[?(@.type=="Available")].reason
3125
name: Reason
3226
type: string
27+
- jsonPath: .status.replicas
28+
name: Replicas
29+
type: string
30+
- jsonPath: .status.readyReplicas
31+
name: Ready
32+
type: string
33+
- jsonPath: .status.desiredReplicas
34+
name: Desired
35+
type: string
36+
- jsonPath: .status.currentReplicas
37+
name: Up-to-date
38+
type: string
39+
- jsonPath: .status.location.namespace
40+
name: Location Namespace
41+
priority: 1
42+
type: string
43+
- jsonPath: .status.location.name
44+
name: Location Name
45+
priority: 1
46+
type: string
3347
name: v1alpha
3448
schema:
3549
openAPIV3Schema:
@@ -1012,13 +1026,12 @@ spec:
10121026
type: object
10131027
type: array
10141028
currentReplicas:
1015-
description: |-
1016-
The number of instances created by a deployment and have the latest
1017-
deployment template settings applied.
1029+
description: The number of instances which have the latest workload
1030+
settings applied.
10181031
format: int32
10191032
type: integer
10201033
desiredReplicas:
1021-
description: The desired number of instances to be managed by a deployment.
1034+
description: The desired number of instances
10221035
format: int32
10231036
type: integer
10241037
location:
@@ -1035,13 +1048,18 @@ spec:
10351048
- name
10361049
- namespace
10371050
type: object
1051+
readyReplicas:
1052+
description: The number of instances which are ready.
1053+
format: int32
1054+
type: integer
10381055
replicas:
1039-
description: The number of instances created by a deployment
1056+
description: The number of instances created
10401057
format: int32
10411058
type: integer
10421059
required:
10431060
- currentReplicas
10441061
- desiredReplicas
1062+
- readyReplicas
10451063
- replicas
10461064
type: object
10471065
type: object

config/crd/bases/compute.datumapis.com_workloads.yaml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ spec:
2424
- jsonPath: .status.conditions[?(@.type=="Available")].reason
2525
name: Reason
2626
type: string
27+
- jsonPath: .status.deployments
28+
name: Deployments
29+
type: string
30+
- jsonPath: .status.replicas
31+
name: Replicas
32+
type: string
33+
- jsonPath: .status.readyReplicas
34+
name: Ready
35+
type: string
36+
- jsonPath: .status.desiredReplicas
37+
name: Desired
38+
type: string
39+
- jsonPath: .status.currentReplicas
40+
name: Up-to-date
41+
type: string
2742
name: v1alpha
2843
schema:
2944
openAPIV3Schema:
@@ -1005,13 +1020,16 @@ spec:
10051020
type: object
10061021
type: array
10071022
currentReplicas:
1008-
description: |-
1009-
The number of instances created by a placement and have the latest
1010-
workload generation settings applied.
1023+
description: The number of instances which have the latest workload
1024+
settings applied.
1025+
format: int32
1026+
type: integer
1027+
deployments:
1028+
description: The number of deployments that currently exist
10111029
format: int32
10121030
type: integer
10131031
desiredReplicas:
1014-
description: The desired number of instances to be managed by a placement.
1032+
description: The desired number of instances
10151033
format: int32
10161034
type: integer
10171035
gateway:
@@ -1353,37 +1371,46 @@ spec:
13531371
type: object
13541372
type: array
13551373
currentReplicas:
1356-
description: |-
1357-
The number of instances created by a placement and have the latest
1358-
workload generation settings applied.
1374+
description: The number of instances which have the latest workload
1375+
settings applied.
13591376
format: int32
13601377
type: integer
13611378
desiredReplicas:
1362-
description: The desired number of instances to be managed by
1363-
a placement.
1379+
description: The desired number of instances
13641380
format: int32
13651381
type: integer
13661382
name:
13671383
description: The name of the placement
13681384
type: string
1385+
readyReplicas:
1386+
description: The number of instances which are ready.
1387+
format: int32
1388+
type: integer
13691389
replicas:
1370-
description: The number of instances created by a placement
1390+
description: The number of instances that currently exist
13711391
format: int32
13721392
type: integer
13731393
required:
13741394
- currentReplicas
13751395
- desiredReplicas
13761396
- name
1397+
- readyReplicas
13771398
- replicas
13781399
type: object
13791400
type: array
1401+
readyReplicas:
1402+
description: The number of instances which are ready.
1403+
format: int32
1404+
type: integer
13801405
replicas:
1381-
description: The number of instances created by a placement
1406+
description: The number of instances that currently exist
13821407
format: int32
13831408
type: integer
13841409
required:
13851410
- currentReplicas
1411+
- deployments
13861412
- desiredReplicas
1413+
- readyReplicas
13871414
- replicas
13881415
type: object
13891416
required:

internal/controller/workload_controller.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req mcreconcile.Requ
186186

187187
deployment.Annotations = desiredDeployment.Annotations
188188
deployment.Labels = desiredDeployment.Labels
189+
190+
// TODO(jreese) consider how this plays well with autoscaling
189191
deployment.Spec = desiredDeployment.Spec
190192
return nil
191193
})
@@ -215,6 +217,8 @@ func (r *WorkloadReconciler) reconcileWorkloadStatus(
215217
totalReplicas := int32(0)
216218
totalCurrentReplicas := int32(0)
217219
totalDesiredReplicas := int32(0)
220+
totalReadyReplicas := int32(0)
221+
totalDeployments := int32(0)
218222

219223
availablePlacementFound := false
220224

@@ -233,7 +237,7 @@ func (r *WorkloadReconciler) reconcileWorkloadStatus(
233237
}
234238
}
235239

236-
availableCondition := metav1.Condition{
240+
placementAvailableCondition := metav1.Condition{
237241
Type: "Available",
238242
Status: metav1.ConditionFalse,
239243
Reason: "NoAvailableDeployments",
@@ -244,10 +248,13 @@ func (r *WorkloadReconciler) reconcileWorkloadStatus(
244248
replicas := int32(0)
245249
currentReplicas := int32(0)
246250
desiredReplicas := int32(0)
251+
readyReplicas := int32(0)
252+
totalDeployments += int32(len(placementDeployments))
247253
for _, deployment := range placementDeployments {
248254
replicas += deployment.Status.Replicas
249-
currentReplicas += deployment.Status.Replicas
250-
desiredReplicas += deployment.Status.Replicas
255+
currentReplicas += deployment.Status.CurrentReplicas
256+
desiredReplicas += deployment.Status.DesiredReplicas
257+
readyReplicas += deployment.Status.ReadyReplicas
251258

252259
if apimeta.IsStatusConditionTrue(deployment.Status.Conditions, "Available") {
253260
foundAvailableDeployment = true
@@ -256,19 +263,21 @@ func (r *WorkloadReconciler) reconcileWorkloadStatus(
256263
totalReplicas += replicas
257264
totalCurrentReplicas += currentReplicas
258265
totalDesiredReplicas += desiredReplicas
266+
totalReadyReplicas += readyReplicas
259267

260268
placementStatus.Replicas = replicas
261269
placementStatus.CurrentReplicas = currentReplicas
262270
placementStatus.DesiredReplicas = desiredReplicas
271+
placementStatus.ReadyReplicas = readyReplicas
263272

264273
if foundAvailableDeployment {
265-
availableCondition.Status = metav1.ConditionTrue
266-
availableCondition.Reason = "AvailableDeploymentFound"
267-
availableCondition.Message = "At least one available deployment was found"
274+
placementAvailableCondition.Status = metav1.ConditionTrue
275+
placementAvailableCondition.Reason = "AvailableDeploymentFound"
276+
placementAvailableCondition.Message = "At least one available deployment was found"
268277
availablePlacementFound = true
269278
}
270279

271-
apimeta.SetStatusCondition(&placementStatus.Conditions, availableCondition)
280+
apimeta.SetStatusCondition(&placementStatus.Conditions, placementAvailableCondition)
272281

273282
newWorkloadStatus.Placements = append(newWorkloadStatus.Placements, placementStatus)
274283
}
@@ -288,9 +297,11 @@ func (r *WorkloadReconciler) reconcileWorkloadStatus(
288297

289298
apimeta.SetStatusCondition(&newWorkloadStatus.Conditions, availableCondition)
290299

300+
newWorkloadStatus.Deployments = totalDeployments
291301
newWorkloadStatus.Replicas = totalReplicas
292302
newWorkloadStatus.CurrentReplicas = totalCurrentReplicas
293303
newWorkloadStatus.DesiredReplicas = totalDesiredReplicas
304+
newWorkloadStatus.ReadyReplicas = totalReadyReplicas
294305

295306
if equality.Semantic.DeepEqual(workload.Status, newWorkloadStatus) {
296307
return nil

0 commit comments

Comments
 (0)