Skip to content

Commit

Permalink
Add support to spring-boot and CronJobs
Browse files Browse the repository at this point in the history
  • Loading branch information
claudio4j committed Sep 19, 2024
1 parent 8fce8ad commit 3e18e2e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 19 deletions.
9 changes: 6 additions & 3 deletions plugin/src/components/ApplicationDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ const ApplicationDetailsCard: React.FC<{ application: Application }> = ({ applic
<Card>
<CardTitle>Frameworks</CardTitle>
<CardBody>
<TextContent><strong>Quarkus Platform: </strong> {application.metadata.annotations['camel/quarkus-platform']}</TextContent>
<TextContent><strong>Camel Quarkus: </strong> {application.metadata.annotations['camel/camel-quarkus']}</TextContent>
<TextContent><strong>Camel: </strong> {application.metadata.annotations['camel/camel-core-version']}</TextContent>
{application.metadata.annotations['camel/camel-core-version'] && <TextContent><strong>Camel: </strong> {application.metadata.annotations['camel/camel-core-version']}</TextContent>}
{application.metadata.annotations['camel/quarkus-platform'] && <TextContent><strong>Quarkus Platform: </strong> {application.metadata.annotations['camel/quarkus-platform']}</TextContent>}
{application.metadata.annotations['camel/camel-quarkus'] && <TextContent><strong>Camel Quarkus: </strong> {application.metadata.annotations['camel/camel-quarkus']}</TextContent>}

{application.metadata.annotations['camel/camel-spring-boot-version'] && <TextContent><strong>Camel Spring Boot: </strong> {application.metadata.annotations['camel/camel-spring-boot-version']}</TextContent>}
{application.metadata.annotations['camel/spring-boot-version'] && <TextContent><strong>Spring Boot: </strong> {application.metadata.annotations['camel/spring-boot-version']}</TextContent>}
</CardBody>
</Card>
</div>
Expand Down
11 changes: 9 additions & 2 deletions plugin/src/components/ApplicationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,17 @@ export const ApplicationList: React.FC<ApplicationListProps> = ({ apps }) => {
</Td>
<Td dataLabel={columnNames.kind}>{app.kind}</Td>
<Td dataLabel={columnNames.namespace}>{app.metadata.namespace}</Td>
<Td dataLabel={columnNames.status}><Status title={`${app.status.availableReplicas} of ${app.status.replicas} pods`} status={app.status.availableReplicas === app.status.replicas ? "Succeeded" : "Failed"}/></Td>
<Td dataLabel={columnNames.status}>
{(app.kind == 'Deployment' || app.kind == 'DeploymentConfig') &&
<Status title={`${app.status.availableReplicas} of ${app.status.replicas} pods`} status={app.status.availableReplicas === app.status.replicas ? "Succeeded" : "Failed"}/>
}
{app.kind == 'CronJob' &&
<Status title={`${app.cronStatus.lastSuccessfulTime}`} status={app.cronStatus.lastSuccessfulTime ? "Succeeded" : "Failed"}/>
}
</Td>
<Td dataLabel={columnNames.cpu}>{app.cpu}</Td>
<Td dataLabel={columnNames.memory}>{app.memory}</Td>
<Td dataLabel={columnNames.runtime}>Quarkus Platform: {app.metadata.annotations['camel/quarkus-platform']}<br/>Camel: {app.metadata.annotations['camel/camel-core-version']}<br/>Camel Quarkus: {app.metadata.annotations['camel/camel-quarkus']}</Td>
<Td dataLabel={columnNames.runtime}>Camel: {app.metadata.annotations['camel/camel-core-version']}</Td>
</Tr>
))}
</Tbody>
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/pages/ApplicationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ApplicationPage: React.FC<ApplicationPageProps> = ( {match} ) => {
</Helmet>
<Page>
<PageSection variant="light">
<Title headingLevel="h1">{t('Dashboard')}</Title>
<Title headingLevel="h1">{t('Dashboard')} - {selectedName}</Title>
</PageSection>
<PageSection variant="light">
<Tabs activeKey={activeTabKey} onSelect={handleTabClick}>
Expand Down
17 changes: 15 additions & 2 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 { 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 @@ -55,6 +55,19 @@ export const CamelPage: React.FC<CamelHomePageProps> = ({ match }) => {
});
})
});

fetchCronjobs(activeNamespace).then((apps: Application[]) => {
apps.forEach(app => {
setApplications((existing: Application[]) => {
return [...existing.filter(e => !matching(e, app)), app];
});
populateAdddionalInfo(app).then(appWithInfo => {
setApplications((existing: Application[]) => {
return [...existing.filter(e => !matching(e, appWithInfo)), appWithInfo];
});
});
})
});
}, [activeNamespace]);

return (
Expand All @@ -66,7 +79,7 @@ export const CamelPage: React.FC<CamelHomePageProps> = ({ match }) => {

<Page>
<PageSection variant="light">
<Title headingLevel="h1">{t('Camel Applications')}</Title>
<Title headingLevel="h1">{t('Camel Applications 123')}</Title>
</PageSection>
<PageSection variant="light">
<Card>
Expand Down
13 changes: 8 additions & 5 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, DeploymentConfigKind, DeploymentKind, JobKind, PersistentVolumeClaimKind, PodKind, RouteKind, SecretKind } from '../k8s-types';
import { Application, deploymentConfigToApplication, deploymentToApplication } from '../types';
import { ConfigMapKind, CronJobKind, DeploymentConfigKind, DeploymentKind, JobKind, PersistentVolumeClaimKind, PodKind, RouteKind, SecretKind } from '../k8s-types';
import { Application, cronjobToApplication, deploymentConfigToApplication, deploymentToApplication } from '../types';
import { sprintf } from 'sprintf-js';
import { camelApplicationStore } from '../state';

Expand All @@ -9,6 +9,7 @@ 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 @@ -17,15 +18,16 @@ export async function fetchDeployments(ns: string): Promise<Application[]> {
});
}

/* export async function fetchCronjobs(ns: string): Promise<Application[]> {
export async function fetchCronjobs(ns: string): Promise<Application[]> {
debugger;
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((d: CronJobKind) => deploymentToApplication(d));
.map((c: CronJobKind) => cronjobToApplication(c));
});
}
*/

async function fetchDeployment(ns: string, name: string): Promise<Application> {
return consoleFetchJSON('/api/kubernetes/apis/apps/v1/namespaces/' + ns + '/deployments/' + name).then(res => {
return deploymentToApplication(res);
Expand Down Expand Up @@ -313,6 +315,7 @@ export async function fetchApplicationWithMetrics(kind: string, ns: string, name
}

const CamelService = {
fetchCronjobs,
fetchDeployments,
fetchDeploymentConfigs,
fetchApplications,
Expand Down
32 changes: 26 additions & 6 deletions plugin/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { K8sResourceCommon } from "@openshift-console/dynamic-plugin-sdk";
import { DeploymentCondition, DeploymentKind, DeploymentConfigKind, PodSpec } from "k8s-types";
import { CronJobKind, DeploymentCondition, DeploymentKind, DeploymentConfigKind, PodSpec, PodTemplate } from "k8s-types";

export type Snapshot = {
name: string;
Expand All @@ -21,7 +21,16 @@ export type Application = {
memory?: string;
url?: string;
metrics?: Metrics;
spec: PodSpec;
spec?: PodSpec;
cronSpec?: {
activeDeadlineSeconds?: number;
backoffLimit?: number;
completions?: number;
manualSelector?: boolean;
parallelism?: boolean;
template: PodTemplate;
ttlSecondsAfterFinished?: number;
};
status?: {
availableReplicas?: number;
collisionCount?: number;
Expand All @@ -32,6 +41,18 @@ export type Application = {
unavailableReplicas?: number;
updatedReplicas?: number;
};
cronStatus?: {
active?: {
apiVersion?: string;
fieldPath?: string;
kind?: string;
name?: string;
namespace?: string;
resourceVersion?: string;
uid?: string;
}[];
lastScheduleTime?: string;
};
} & K8sResourceCommon;

export function deploymentToApplication(deployment: DeploymentKind): Application {
Expand Down Expand Up @@ -76,13 +97,13 @@ export function deploymentConfigToApplication(deployment: DeploymentConfigKind):
};
};

/* export function cronjobToApplication(cronjob: CronJobKind): Application {
export function cronjobToApplication(cronjob: CronJobKind): Application {
return {
kind: 'CronJob',
metadata: {
...cronjob.metadata,
},
spec: {
cronSpec: {
...cronjob.spec.jobTemplate.spec,
},
metrics: {
Expand All @@ -91,9 +112,8 @@ export function deploymentConfigToApplication(deployment: DeploymentConfigKind):
gcPause: [],
gcOverhead: [],
},
status: {
cronStatus: {
...cronjob.status,
},
};
};
*/

0 comments on commit 3e18e2e

Please sign in to comment.