Skip to content

Commit

Permalink
More CronJob support; remove debugging code.
Browse files Browse the repository at this point in the history
  • Loading branch information
claudio4j committed Sep 20, 2024
1 parent 3e18e2e commit 849bbd5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 4 additions & 1 deletion plugin/src/components/ApplicationDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ const ApplicationDetailsCard: React.FC<{ application: Application }> = ({ applic
}

function getHealthStatus(application: Application): string | null {
return application.status.replicas === application.status.availableReplicas ? "Succeeded" : "Failed";
if (application.status) {
return application.status.replicas === application.status.availableReplicas ? "Succeeded" : "Failed";
}
return "Failed";
}

function checkMetricsEndpointStatus(application: Application) {
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useEffect, useState } from 'react';
import { NamespaceBar } from '@openshift-console/dynamic-plugin-sdk';
import ApplicationList from '../components/ApplicationList';
import { Application } from '../types';
import { fetchCronjobs, fetchDeployments, fetchDeploymentConfigs, populateAdddionalInfo } from '../services/CamelService';
import { fetchCronJobs, fetchDeployments, fetchDeploymentConfigs, populateAdddionalInfo } from '../services/CamelService';
import ApplicationsCPUGraph from '../components/ApplicationsCPUGraph';
import ApplicationsMemoryGraph from '../components/ApplicationsMemoryGraph';

Expand Down Expand Up @@ -56,7 +56,7 @@ export const CamelPage: React.FC<CamelHomePageProps> = ({ match }) => {
})
});

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

<Page>
<PageSection variant="light">
<Title headingLevel="h1">{t('Camel Applications 123')}</Title>
<Title headingLevel="h1">{t('Camel Applications')}</Title>
</PageSection>
<PageSection variant="light">
<Card>
Expand Down
20 changes: 14 additions & 6 deletions plugin/src/services/CamelService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { consoleFetchJSON } from '@openshift-console/dynamic-plugin-sdk';
import { ConfigMapKind, CronJobKind, DeploymentConfigKind, DeploymentKind, JobKind, PersistentVolumeClaimKind, PodKind, RouteKind, SecretKind } from '../k8s-types';
import { Application, cronjobToApplication, deploymentConfigToApplication, deploymentToApplication } from '../types';
import { Application, cronjobToApplication as cronJobToApplication, deploymentConfigToApplication, deploymentToApplication } from '../types';
import { sprintf } from 'sprintf-js';
import { camelApplicationStore } from '../state';

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

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

export async function fetchCronjobs(ns: string): Promise<Application[]> {
debugger;
export async function fetchCronJobs(ns: string): Promise<Application[]> {
let deploymentsUri = ns ? '/api/kubernetes/apis/batch/v1/namespaces/' + ns + '/cronjobs' : '/api/kubernetes/apis/batch/v1/cronjobs';
deploymentsUri += '?labelSelector=' + OPENSHIFT_RUNTIME_LABEL
return consoleFetchJSON(deploymentsUri).then(res => {
return res.items
.map((c: CronJobKind) => cronjobToApplication(c));
.map((c: CronJobKind) => cronJobToApplication(c));
});
}

Expand Down Expand Up @@ -53,6 +51,12 @@ async function fetchDeploymentConfig(ns: string, name: string): Promise<Applicat
});
}

async function fetchCronJob(ns: string, name: string): Promise<Application> {
return consoleFetchJSON('/api/kubernetes/apis/batch/v1/namespaces/' + ns + '/cronjobs/' + name).then(res => {
return cronJobToApplication(res);
});
}

export async function fetchSecret(ns: string, name: string): Promise<SecretKind> {
return consoleFetchJSON('/api/kubernetes/api/v1/namespaces/' + ns + '/secrets/' + name).then(res => {
return res.data;
Expand Down Expand Up @@ -308,14 +312,18 @@ export async function fetchApplicationWithMetrics(kind: string, ns: string, name
case 'DeploymentConfig':
app = fetchDeploymentConfig(ns, name);
break;
case 'CronJob':
app = fetchCronJob(ns, name);
break;
default:
throw new Error('Invalid kind: ' + kind);
}
return app.then(populateRoute).then(populateCpuMetrics).then(populateMemMetrics);
}

const CamelService = {
fetchCronjobs,
fetchCronjobs: fetchCronJobs,
fetchCronJob,
fetchDeployments,
fetchDeploymentConfigs,
fetchApplications,
Expand Down

0 comments on commit 849bbd5

Please sign in to comment.