Skip to content

Commit 849bbd5

Browse files
committed
More CronJob support; remove debugging code.
1 parent 3e18e2e commit 849bbd5

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

plugin/src/components/ApplicationDetailsCard.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ const ApplicationDetailsCard: React.FC<{ application: Application }> = ({ applic
5454
}
5555

5656
function getHealthStatus(application: Application): string | null {
57-
return application.status.replicas === application.status.availableReplicas ? "Succeeded" : "Failed";
57+
if (application.status) {
58+
return application.status.replicas === application.status.availableReplicas ? "Succeeded" : "Failed";
59+
}
60+
return "Failed";
5861
}
5962

6063
function checkMetricsEndpointStatus(application: Application) {

plugin/src/pages/HomePage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useEffect, useState } from 'react';
1414
import { NamespaceBar } from '@openshift-console/dynamic-plugin-sdk';
1515
import ApplicationList from '../components/ApplicationList';
1616
import { Application } from '../types';
17-
import { fetchCronjobs, fetchDeployments, fetchDeploymentConfigs, populateAdddionalInfo } from '../services/CamelService';
17+
import { fetchCronJobs, fetchDeployments, fetchDeploymentConfigs, populateAdddionalInfo } from '../services/CamelService';
1818
import ApplicationsCPUGraph from '../components/ApplicationsCPUGraph';
1919
import ApplicationsMemoryGraph from '../components/ApplicationsMemoryGraph';
2020

@@ -56,7 +56,7 @@ export const CamelPage: React.FC<CamelHomePageProps> = ({ match }) => {
5656
})
5757
});
5858

59-
fetchCronjobs(activeNamespace).then((apps: Application[]) => {
59+
fetchCronJobs(activeNamespace).then((apps: Application[]) => {
6060
apps.forEach(app => {
6161
setApplications((existing: Application[]) => {
6262
return [...existing.filter(e => !matching(e, app)), app];
@@ -79,7 +79,7 @@ export const CamelPage: React.FC<CamelHomePageProps> = ({ match }) => {
7979

8080
<Page>
8181
<PageSection variant="light">
82-
<Title headingLevel="h1">{t('Camel Applications 123')}</Title>
82+
<Title headingLevel="h1">{t('Camel Applications')}</Title>
8383
</PageSection>
8484
<PageSection variant="light">
8585
<Card>

plugin/src/services/CamelService.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { consoleFetchJSON } from '@openshift-console/dynamic-plugin-sdk';
22
import { ConfigMapKind, CronJobKind, DeploymentConfigKind, DeploymentKind, JobKind, PersistentVolumeClaimKind, PodKind, RouteKind, SecretKind } from '../k8s-types';
3-
import { Application, cronjobToApplication, deploymentConfigToApplication, deploymentToApplication } from '../types';
3+
import { Application, cronjobToApplication as cronJobToApplication, deploymentConfigToApplication, deploymentToApplication } from '../types';
44
import { sprintf } from 'sprintf-js';
55
import { camelApplicationStore } from '../state';
66

@@ -9,7 +9,6 @@ const PROMETHEUS_API_QUERY_PATH = '/api/prometheus/api/v1/query';
99
const PROMETHEUS_API_QUERYRANGE_PATH = '/api/prometheus/api/v1/query_range';
1010

1111
export async function fetchDeployments(ns: string): Promise<Application[]> {
12-
debugger;
1312
let deploymentsUri = ns ? '/api/kubernetes/apis/apps/v1/namespaces/' + ns + '/deployments' : '/api/kubernetes/apis/apps/v1/deployments';
1413
deploymentsUri += '?labelSelector=' + OPENSHIFT_RUNTIME_LABEL
1514
return consoleFetchJSON(deploymentsUri).then(res => {
@@ -18,13 +17,12 @@ export async function fetchDeployments(ns: string): Promise<Application[]> {
1817
});
1918
}
2019

21-
export async function fetchCronjobs(ns: string): Promise<Application[]> {
22-
debugger;
20+
export async function fetchCronJobs(ns: string): Promise<Application[]> {
2321
let deploymentsUri = ns ? '/api/kubernetes/apis/batch/v1/namespaces/' + ns + '/cronjobs' : '/api/kubernetes/apis/batch/v1/cronjobs';
2422
deploymentsUri += '?labelSelector=' + OPENSHIFT_RUNTIME_LABEL
2523
return consoleFetchJSON(deploymentsUri).then(res => {
2624
return res.items
27-
.map((c: CronJobKind) => cronjobToApplication(c));
25+
.map((c: CronJobKind) => cronJobToApplication(c));
2826
});
2927
}
3028

@@ -53,6 +51,12 @@ async function fetchDeploymentConfig(ns: string, name: string): Promise<Applicat
5351
});
5452
}
5553

54+
async function fetchCronJob(ns: string, name: string): Promise<Application> {
55+
return consoleFetchJSON('/api/kubernetes/apis/batch/v1/namespaces/' + ns + '/cronjobs/' + name).then(res => {
56+
return cronJobToApplication(res);
57+
});
58+
}
59+
5660
export async function fetchSecret(ns: string, name: string): Promise<SecretKind> {
5761
return consoleFetchJSON('/api/kubernetes/api/v1/namespaces/' + ns + '/secrets/' + name).then(res => {
5862
return res.data;
@@ -308,14 +312,18 @@ export async function fetchApplicationWithMetrics(kind: string, ns: string, name
308312
case 'DeploymentConfig':
309313
app = fetchDeploymentConfig(ns, name);
310314
break;
315+
case 'CronJob':
316+
app = fetchCronJob(ns, name);
317+
break;
311318
default:
312319
throw new Error('Invalid kind: ' + kind);
313320
}
314321
return app.then(populateRoute).then(populateCpuMetrics).then(populateMemMetrics);
315322
}
316323

317324
const CamelService = {
318-
fetchCronjobs,
325+
fetchCronjobs: fetchCronJobs,
326+
fetchCronJob,
319327
fetchDeployments,
320328
fetchDeploymentConfigs,
321329
fetchApplications,

0 commit comments

Comments
 (0)