@@ -1209,68 +1209,51 @@ func (h *Handler) GetScenarioRunLogs(w http.ResponseWriter, r *http.Request) {
12091209}
12101210
12111211// ListScenarioRuns handles GET /api/v1/scenarios/run endpoint
1212- // It returns a list of all scenario jobs
1212+ // It returns a list of all scenario runs (KrknScenarioRun CRs)
12131213func (h * Handler ) ListScenarioRuns (w http.ResponseWriter , r * http.Request ) {
12141214 ctx := context .Background ()
12151215
12161216 // Parse query parameters for filtering
1217- statusFilter := r .URL .Query ().Get ("status" )
1217+ phaseFilter := r .URL .Query ().Get ("phase" ) // e.g., Running, Succeeded, Failed
12181218 scenarioNameFilter := r .URL .Query ().Get ("scenarioName" )
1219- clusterNameFilter := r .URL .Query ().Get ("clusterName" )
12201219
1221- // List all pods with krkn-scenario label
1222- var podList corev1.PodList
1223- err := h .client .List (ctx , & podList , client .InNamespace (h .namespace ), client.MatchingLabels {
1224- "app" : "krkn-scenario" ,
1225- })
1226-
1227- if err != nil {
1220+ // List all KrknScenarioRun CRs in the namespace
1221+ var scenarioRunList krknv1alpha1.KrknScenarioRunList
1222+ if err := h .client .List (ctx , & scenarioRunList , client .InNamespace (h .namespace )); err != nil {
12281223 writeJSONError (w , http .StatusInternalServerError , ErrorResponse {
12291224 Error : "internal_error" ,
1230- Message : "Failed to list pods : " + err .Error (),
1225+ Message : "Failed to list scenario runs : " + err .Error (),
12311226 })
12321227 return
12331228 }
12341229
1235- var jobs []JobStatusResponse
1236-
1237- for _ , pod := range podList .Items {
1238- jobId := pod .Labels ["krkn-job-id" ]
1239- clusterName := pod .Labels ["krkn-cluster-name" ]
1240- scenarioName := pod .Labels ["krkn-scenario-name" ]
1241-
1242- if (statusFilter != "" && string (pod .Status .Phase ) != statusFilter ) ||
1243- (scenarioNameFilter != "" && scenarioName != scenarioNameFilter ) ||
1244- (clusterNameFilter != "" && clusterName != clusterNameFilter ) {
1230+ // Convert to response format with optional filtering
1231+ var runs []ScenarioRunListItem
1232+ for _ , sr := range scenarioRunList .Items {
1233+ // Apply filters
1234+ if phaseFilter != "" && sr .Status .Phase != phaseFilter {
12451235 continue
12461236 }
1247-
1248- jobStatus := JobStatusResponse {
1249- JobId : jobId ,
1250- ClusterName : clusterName ,
1251- ScenarioName : scenarioName ,
1252- Status : string (pod .Status .Phase ),
1253- PodName : pod .Name ,
1254- }
1255-
1256- if pod .Status .StartTime != nil {
1257- startTime := pod .Status .StartTime .Time
1258- jobStatus .StartTime = & startTime
1237+ if scenarioNameFilter != "" && sr .Spec .ScenarioName != scenarioNameFilter {
1238+ continue
12591239 }
12601240
1261- for _ , condition := range pod .Status .Conditions {
1262- if condition .Type == corev1 .PodReady && condition .Status == corev1 .ConditionFalse &&
1263- (pod .Status .Phase == "Succeeded" || pod .Status .Phase == "Failed" ) {
1264- completionTime := condition .LastTransitionTime .Time
1265- jobStatus .CompletionTime = & completionTime
1266- }
1241+ run := ScenarioRunListItem {
1242+ ScenarioRunName : sr .Name ,
1243+ ScenarioName : sr .Spec .ScenarioName ,
1244+ Phase : sr .Status .Phase ,
1245+ TotalTargets : sr .Status .TotalTargets ,
1246+ SuccessfulJobs : sr .Status .SuccessfulJobs ,
1247+ FailedJobs : sr .Status .FailedJobs ,
1248+ RunningJobs : sr .Status .RunningJobs ,
1249+ CreatedAt : sr .CreationTimestamp .Time ,
12671250 }
12681251
1269- jobs = append (jobs , jobStatus )
1252+ runs = append (runs , run )
12701253 }
12711254
1272- response := JobsListResponse {
1273- Jobs : jobs ,
1255+ response := ScenarioRunListResponse {
1256+ ScenarioRuns : runs ,
12741257 }
12751258
12761259 writeJSON (w , http .StatusOK , response )
0 commit comments