Skip to content

Commit 63d3b06

Browse files
committed
Support status field named "runnerCompletions" and addtional printer columns
Signed-off-by: Yoichi Kawasaki <[email protected]>
1 parent 131eedc commit 63d3b06

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

api/v1alpha1/gatling_types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
2323

24-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26-
2724
// GatlingSpec defines the desired state of Gatling
2825
type GatlingSpec struct {
2926
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
@@ -200,6 +197,10 @@ type GatlingStatus struct {
200197
// +optional
201198
RunnerCompleted bool `json:"runnerCompleted,omitempty"`
202199

200+
// The number of successfully completed runner pods. The format is (completed#/parallelism#)
201+
// +optional
202+
RunnerCompletions string `json:"runnerCompletions,omitempty"`
203+
203204
// Reporter job name
204205
// +optional
205206
ReporterJobName string `json:"reporterJobName,omitempty"`
@@ -231,6 +232,11 @@ type GatlingStatus struct {
231232

232233
//+kubebuilder:object:root=true
233234
//+kubebuilder:subresource:status
235+
//+kubebuilder:printcolumn:name="Runned",type=string,JSONPath=`.status.runnerCompletions`
236+
//+kubebuilder:printcolumn:name="Reported",type=boolean,JSONPath=`.status.reportCompleted`
237+
//+kubebuilder:printcolumn:name="Notified",type=boolean,JSONPath=`.status.notificationCompleted`
238+
//+kubebuilder:printcolumn:name="ReportURL",type=string,JSONPath=`.status.reportUrl`
239+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
234240

235241
// Gatling is the Schema for the gatlings API
236242
type Gatling struct {

config/crd/bases/gatling-operator.tech.zozo.com_gatlings.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ spec:
1616
singular: gatling
1717
scope: Namespaced
1818
versions:
19-
- name: v1alpha1
19+
- additionalPrinterColumns:
20+
- jsonPath: .status.runnerCompletions
21+
name: Runned
22+
type: string
23+
- jsonPath: .status.reportCompleted
24+
name: Reported
25+
type: boolean
26+
- jsonPath: .status.notificationCompleted
27+
name: Notified
28+
type: boolean
29+
- jsonPath: .status.reportUrl
30+
name: ReportURL
31+
type: string
32+
- jsonPath: .metadata.creationTimestamp
33+
name: Age
34+
type: date
35+
name: v1alpha1
2036
schema:
2137
openAPIV3Schema:
2238
description: Gatling is the Schema for the gatlings API
@@ -1339,6 +1355,10 @@ spec:
13391355
runnerCompleted:
13401356
description: Is runner job completed (default false)
13411357
type: boolean
1358+
runnerCompletions:
1359+
description: The number of successfully completed runner pods. The
1360+
format is (completed#/parallelism#)
1361+
type: string
13421362
runnerJobName:
13431363
description: Runner job name
13441364
type: string

controllers/gatling_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
205205
gatling.Status.Active = runnerJob.Status.Active
206206
gatling.Status.Failed = runnerJob.Status.Failed
207207
gatling.Status.Succeeded = runnerJob.Status.Succeeded
208+
gatling.Status.RunnerCompletions = r.getRunnerCompletionsStatus(gatling)
208209
gatling.Status.RunnerCompleted = false
209210
gatling.Status.ReportCompleted = false
210211
gatling.Status.NotificationCompleted = false
@@ -235,6 +236,7 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
235236
gatling.Status.Active = foundJob.Status.Active
236237
gatling.Status.Failed = foundJob.Status.Failed
237238
gatling.Status.Succeeded = foundJob.Status.Succeeded
239+
gatling.Status.RunnerCompletions = r.getRunnerCompletionsStatus(gatling)
238240

239241
// Check if the job runs out of time in running the job
240242
duration := utils.GetEpocTime() - gatling.Status.RunnerStartTime
@@ -838,10 +840,11 @@ func (r *GatlingReconciler) updateGatlingStatus(ctx context.Context, gatling *ga
838840
}
839841

840842
func (r *GatlingReconciler) dumpGatlingStatus(gatling *gatlingv1alpha1.Gatling, log logr.Logger) {
841-
log.Info(fmt.Sprintf("GatlingStatus: Active %d Succeeded %d Failed %d ReportCompleted %t NotificationCompleted %t ReportUrl %s Error %v",
843+
log.Info(fmt.Sprintf("GatlingStatus: Active %d Succeeded %d Failed %d RunnerCompletions %s ReportCompleted %t NotificationCompleted %t ReportUrl %s Error %v",
842844
gatling.Status.Active,
843845
gatling.Status.Succeeded,
844846
gatling.Status.Failed,
847+
gatling.Status.RunnerCompletions,
845848
gatling.Status.ReportCompleted,
846849
gatling.Status.NotificationCompleted,
847850
gatling.Status.ReportUrl,
@@ -1004,6 +1007,10 @@ func (r *GatlingReconciler) getGenerateLocalReport(gatling *gatlingv1alpha1.Gatl
10041007
return gatling.Spec.GenerateLocalReport
10051008
}
10061009

1010+
func (r *GatlingReconciler) getRunnerCompletionsStatus(gatling *gatlingv1alpha1.Gatling) string {
1011+
return fmt.Sprintf("%d/%d", gatling.Status.Succeeded, *(r.getGatlingRunnerJobParallelism(gatling)))
1012+
}
1013+
10071014
// SetupWithManager sets up the controller with the Manager.
10081015
func (r *GatlingReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
10091016
return ctrl.NewControllerManagedBy(mgr).

0 commit comments

Comments
 (0)