(deployedResource *operator.DeployedResource)
| 192 | } |
| 193 | |
| 194 | func GetAPIByName(deployedResource *operator.DeployedResource) ([]schema.APIResponse, error) { |
| 195 | metadata, err := spec.MetadataFromVirtualService(deployedResource.VirtualService) |
| 196 | if err != nil { |
| 197 | return nil, err |
| 198 | } |
| 199 | |
| 200 | api, err := operator.DownloadAPISpec(deployedResource.Name, metadata.APIID) |
| 201 | if err != nil { |
| 202 | return nil, err |
| 203 | } |
| 204 | |
| 205 | ctx := context.Background() |
| 206 | batchJobList := batch.BatchJobList{} |
| 207 | if err = config.K8s.List( |
| 208 | ctx, &batchJobList, |
| 209 | client.InNamespace(config.K8s.Namespace), |
| 210 | client.MatchingLabels{"apiName": deployedResource.Name}, |
| 211 | ); err != nil { |
| 212 | return nil, err |
| 213 | } |
| 214 | |
| 215 | endpoint, err := operator.APIEndpoint(api) |
| 216 | if err != nil { |
| 217 | return nil, err |
| 218 | } |
| 219 | |
| 220 | var jobStatuses []status.BatchJobStatus |
| 221 | jobIDSet := strset.New() |
| 222 | for _, batchJob := range batchJobList.Items { |
| 223 | jobStatus, err := getJobStatusFromBatchJob(batchJob) |
| 224 | if err != nil { |
| 225 | return nil, err |
| 226 | } |
| 227 | jobStatuses = append(jobStatuses, *jobStatus) |
| 228 | jobIDSet.Add(batchJob.Name) |
| 229 | } |
| 230 | |
| 231 | if len(jobStatuses) < 10 { |
| 232 | jobStates, err := job.GetMostRecentlySubmittedJobStates(deployedResource.Name, 10+len(jobStatuses), userconfig.BatchAPIKind) |
| 233 | if err != nil { |
| 234 | return nil, err |
| 235 | } |
| 236 | for _, jobState := range jobStates { |
| 237 | if jobIDSet.Has(jobState.ID) { |
| 238 | continue |
| 239 | } |
| 240 | jobIDSet.Add(jobState.ID) |
| 241 | |
| 242 | jobStatus, err := getJobStatusFromJobState(jobState) |
| 243 | if err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | |
| 247 | if jobStatus != nil { |
| 248 | jobStatuses = append(jobStatuses, *jobStatus) |
| 249 | if len(jobStatuses) == 10 { |
| 250 | break |
| 251 | } |
no test coverage detected