Skip to content

Commit

Permalink
Merge pull request #26 from weaveworks/deployments-card
Browse files Browse the repository at this point in the history
Deployments Card
  • Loading branch information
AlinaGoaga authored Jul 13, 2023
2 parents ed32248 + 89e780b commit 4ec6d07
Show file tree
Hide file tree
Showing 16 changed files with 744 additions and 170 deletions.
40 changes: 40 additions & 0 deletions plugins/backstage-plugin-flux/dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
FluxEntityOCIRepositoriesCard,
FluxEntityHelmRepositoriesCard,
FluxEntityKustomizationsCard,
FluxEntityDeploymentsCard,
} from '../src/plugin';
import {
newTestHelmRelease,
Expand Down Expand Up @@ -397,5 +398,44 @@ createDevApp()
</TestApiProvider>
),
})
.addPage({
title: 'Deployments',
path: '/deployments',
element: (
<TestApiProvider
apis={[
[
configApiRef,
new ConfigReader({
gitops: { baseUrl: 'https://example.com/wego' },
}),
],
[
kubernetesApiRef,
new StubKubernetesClient([
newTestKustomization(
'flux-system',
'./clusters/my-cluster',
true,
),
newTestHelmRelease(
'prometheus1',
'kube-prometheus-stack',
'6.3.5',
),
]),
],

[kubernetesAuthProvidersApiRef, new StubKubernetesAuthProvidersApi()],
]}
>
<EntityProvider entity={fakeEntity}>
<Content>
<FluxEntityDeploymentsCard />
</Content>
</EntityProvider>
</TestApiProvider>
),
})
.registerPlugin(weaveworksFluxPlugin)
.render();
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from 'react';
import { TableColumn } from '@backstage/core-components';
import {
idColumn,
nameAndClusterNameColumn,
statusColumn,
updatedColumn,
syncColumn,
Deployment,
repoColumn,
referenceColumn,
typeColumn,
} from '../helpers';
import { HelmChart, HelmRelease, Kustomization } from '../../objects';
import { FluxEntityTable } from '../FluxEntityTable';

export const defaultColumns: TableColumn<Deployment>[] = [
idColumn(),
typeColumn(),
nameAndClusterNameColumn(),
repoColumn(),
referenceColumn(),
statusColumn(),
updatedColumn(),
syncColumn(),
];

type Props = {
deployments: Deployment[];
isLoading: boolean;
columns: TableColumn<Deployment>[];
kinds: string[];
};

export const FluxDeploymentsTable = ({
kinds,
deployments,
isLoading,
columns,
}: Props) => {
const getTitle = () => {
if (kinds.length === 1) {
return `${kinds[0]}s`;
}
return 'Deployments';
};

let helmChart = {} as HelmChart;
let path = '';

const data = deployments.map(d => {
const {
clusterName,
namespace,
name,
conditions,
suspended,
sourceRef,
type,
lastAppliedRevision,
} = d;
if (d instanceof Kustomization) {
path = d.path;
return {
id: `${clusterName}/${namespace}/${name}`,
conditions,
suspended,
name,
namespace,
lastAppliedRevision,
clusterName,
sourceRef,
type,
path,
} as Kustomization & { id: string };
} else if (d instanceof HelmRelease) {
helmChart = d.helmChart;
return {
id: `${clusterName}/${namespace}/${name}`,
conditions,
suspended,
name,
namespace,
lastAppliedRevision,
clusterName,
sourceRef,
type,
helmChart,
} as HelmRelease & { id: string };
}
return null;
});

return (
<FluxEntityTable
columns={columns}
title={getTitle()}
data={
data as (
| (HelmRelease & { id: string })
| (Kustomization & { id: string })
)[]
}
isLoading={isLoading}
/>
);
};
Loading

0 comments on commit 4ec6d07

Please sign in to comment.