Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ kubernetes:
authProvider: 'serviceAccount'
skipTLSVerify: true
serviceAccountToken: ${K8S_CLUSTER_TOKEN}

ocm:
hub:
name: ${OCM_HUB_NAME}
url: ${OCM_HUB_URL}
serviceAccountToken: ${moc_infra_token}
2 changes: 2 additions & 0 deletions manifests/base/externalsecret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ spec:
- extract:
conversionStrategy: Default
key: moc/smaug/janus-idp/values-app-config
- extract:
key: moc/smaug/service-catalog/k8s-plugin-tokens
refreshInterval: 60s
secretStoreRef:
kind: SecretStore
Expand Down
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@backstage/plugin-techdocs-react": "^1.1.2",
"@backstage/plugin-user-settings": "^0.6.2",
"@backstage/theme": "^0.2.16",
"@janus-idp/backstage-plugin-ocm": "^1.1.1",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@roadiehq/backstage-plugin-argo-cd": "^2.2.6",
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { CssBaseline, ThemeProvider } from '@material-ui/core';
import { janusTheme } from './themes/janus';
import { HomePage } from './components/home/HomePage';
import { HomepageCompositionRoot } from '@backstage/plugin-home';
import { OcmPage } from '@janus-idp/backstage-plugin-ocm';
import Logo from './components/Root/LogoIcon';

const app = createApp({
apis,
Expand Down Expand Up @@ -110,6 +112,7 @@ const routes = (
</Route>
<Route path="/settings" element={<UserSettingsPage />} />
<Route path="/catalog-graph" element={<CatalogGraphPage />} />
<Route path="/ocm" element={<OcmPage logo={<Logo />} />} />
</FlatRoutes>
);

Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/components/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core';
import AppsIcon from '@material-ui/icons/Apps';
import HomeIcon from '@material-ui/icons/Home';
import ExtensionIcon from '@material-ui/icons/Extension';
import StorageIcon from '@material-ui/icons/Storage';
import MapIcon from '@material-ui/icons/MyLocation';
import LibraryBooks from '@material-ui/icons/LibraryBooks';
import CreateComponentIcon from '@material-ui/icons/AddCircleOutline';
Expand Down Expand Up @@ -70,6 +71,7 @@ export const Root = ({ children }: PropsWithChildren<{}>) => (
<SidebarItem icon={AppsIcon} to="catalog" text="Catalog" />
<SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
<SidebarItem icon={StorageIcon} to="ocm" text="Clusters" />
<SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
{/* End global nav */}
<SidebarDivider />
Expand Down
52 changes: 52 additions & 0 deletions packages/app/src/components/catalog/EntityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ import {
EntityArgoCDOverviewCard,
EntityArgoCDHistoryCard,
} from '@roadiehq/backstage-plugin-argo-cd';
import {
ClusterAllocatableResourceCard,
ClusterAvailableResourceCard,
ClusterContextProvider,
ClusterInfoCard,
ClusterStatusCard,
} from '@janus-idp/backstage-plugin-ocm';
import { isType } from './utils';

const techdocsContent = (
<EntityTechdocsContent>
Expand Down Expand Up @@ -420,6 +428,49 @@ const domainPage = (
</EntityLayout>
);

const resourcePage = (
<EntityLayout>
<EntityLayout.Route path="/" title="Overview">
<Grid container spacing={3} alignItems="stretch">
{entityWarningContent}
<Grid item md={6}>
<EntityAboutCard variant="gridItem" />
</Grid>
<Grid item md={6} xs={12}>
<EntityCatalogGraphCard variant="gridItem" height={400} />
</Grid>
<Grid item md={6}>
<EntityHasSystemsCard variant="gridItem" />
</Grid>
</Grid>
</EntityLayout.Route>
<EntityLayout.Route path="/status" title="status">
<EntitySwitch>
<EntitySwitch.Case if={isType('kubernetes-cluster')}>
<ClusterContextProvider>
<Grid container>
<Grid container item direction="column" xs={3}>
<Grid item>
<ClusterStatusCard />
</Grid>
<Grid item>
<ClusterAllocatableResourceCard />
</Grid>
<Grid item>
<ClusterAvailableResourceCard />
</Grid>
</Grid>
<Grid item xs>
<ClusterInfoCard />
</Grid>
</Grid>
</ClusterContextProvider>
</EntitySwitch.Case>
</EntitySwitch>
</EntityLayout.Route>
</EntityLayout>
);

export const entityPage = (
<EntitySwitch>
<EntitySwitch.Case if={isKind('component')} children={componentPage} />
Expand All @@ -428,6 +479,7 @@ export const entityPage = (
<EntitySwitch.Case if={isKind('user')} children={userPage} />
<EntitySwitch.Case if={isKind('system')} children={systemPage} />
<EntitySwitch.Case if={isKind('domain')} children={domainPage} />
<EntitySwitch.Case if={isKind('resource')} children={resourcePage} />

<EntitySwitch.Case>{defaultEntityPage}</EntitySwitch.Case>
</EntitySwitch>
Expand Down
10 changes: 10 additions & 0 deletions packages/app/src/components/catalog/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Entity } from '@backstage/catalog-model';

export const isType = (types: string | string[]) => (entity: Entity) => {
if (!entity?.spec?.type) {
return false;
}
return typeof types === 'string'
? entity?.spec?.type === types
: types.includes(entity.spec.type as string);
};
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@backstage/plugin-search-backend-module-pg": "^0.5.2",
"@backstage/plugin-search-backend-node": "^1.1.2",
"@backstage/plugin-techdocs-backend": "^1.5.2",
"@janus-idp/backstage-plugin-ocm-backend": "^1.3.0",
"app": "link:../app",
"better-sqlite3": "^8.0.0",
"dockerode": "^3.3.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kubernetes from './plugins/kubernetes';
import { PluginEnvironment } from './types';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import ocm from './plugins/ocm';

function makeCreateEnv(config: Config) {
const root = getRootLogger();
Expand Down Expand Up @@ -87,6 +88,7 @@ async function main() {
const searchEnv = useHotMemoize(module, () => createEnv('search'));
const appEnv = useHotMemoize(module, () => createEnv('app'));
const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes'));
const ocmEnv = useHotMemoize(module, () => createEnv('ocm'));

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
Expand All @@ -96,6 +98,7 @@ async function main() {
apiRouter.use('/proxy', await proxy(proxyEnv));
apiRouter.use('/search', await search(searchEnv));
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
apiRouter.use('/ocm', await ocm(ocmEnv));

// Add backends ABOVE this line; this 404 handler is the catch-all fallback
apiRouter.use(notFoundHandler());
Expand Down
13 changes: 13 additions & 0 deletions packages/backend/src/plugins/catalog.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { CatalogBuilder } from '@backstage/plugin-catalog-backend';
import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
import { ManagedClusterProvider } from '@janus-idp/backstage-plugin-ocm-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = await CatalogBuilder.create(env);
const ocm = ManagedClusterProvider.fromConfig(env.config, {
logger: env.logger,
});
builder.addEntityProvider(ocm);
builder.addProcessor(new ScaffolderEntitiesProcessor());
const { processingEngine, router } = await builder.build();
await processingEngine.start();
await env.scheduler.scheduleTask({
id: 'run_ocm_refresh',
fn: async () => {
await ocm.run();
},
frequency: { minutes: 30 },
timeout: { minutes: 10 },
Comment on lines 23 to 24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this in the app-config.yaml?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can put this into the app-config.yaml at this time, this would require some additional changes to the source code. However we can talk about this more and maybe implement it in the future.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem. I just wanted to keep track here.
Will merge later today. Need the environment up for a recording.

});
return router;
}
12 changes: 12 additions & 0 deletions packages/backend/src/plugins/ocm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createRouter } from '@janus-idp/backstage-plugin-ocm-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return await createRouter({
logger: env.logger,
config: env.config,
});
}
Loading