1.0.1 • Published 10 months ago

@marek.libra/plugin-redhat-resource-optimization-dynamic v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

Resource Optimization

Welcome to the Resource Optimization plugin!

Based on Project Koku, the Resource Optimization plugin allows users to visualize usage trends and receive optimization recommendations for containers running on OpenShift clusters.

Getting started

Install

# From your Backstage root directory
yarn --cwd packages/app add @marek.libra/plugin-redhat-resource-optimization

Setup

  1. Configure app-config.yaml, see Configuration.
  2. You can follow one of these options depending on your environment and how you choose to deploy Backstage.

Option 1: Static plugin

  1. Add the ResourceOptimizationPage extension to your App.tsx routes
// packages/app/src/App.tsx

import { ResourceOptimizationPage } from '@marek.libra/plugin-redhat-resource-optimization';

<FlatRoutes>
  ...
  <Route
    path="/redhat-resource-optimization"
    element={<ResourceOptimizationPage />}
  />
  ...
</FlatRoutes>;
  1. Add a link to the Resource Optimization page in the side bar
// packages/app/src/components/Root/Root.tsx

+ import { ResourceOptimizationIconOutlined } from '@marek.libra/plugin-redhat-resource-optimization';

export const Root = ({ children }: PropsWithChildren<{}>) => (
  <SidebarPage>
    <Sidebar>
      <SidebarLogo />
      <SidebarGroup label="Search" icon={<SearchIcon />} to="/search">
        <SidebarSearchModal />
      </SidebarGroup>
      <SidebarDivider />
      <SidebarGroup label="Menu" icon={<MenuIcon />}>
        {/* Global nav, not org-specific */}
        <SidebarItem icon={HomeIcon} to="catalog" text="Home" />
        <SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
        <SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
        <SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
        {/* End global nav */}
        <SidebarDivider />
        <SidebarScrollWrapper>
          <SidebarItem icon={MapIcon} to="tech-radar" text="Tech Radar" />
        </SidebarScrollWrapper>
+       <SidebarItem
+         icon={ResourceOptimizationIconOutlined}
+         to="/redhat-resource-optimization"
+         text="Optimizations"
+       />
      </SidebarGroup>
      <SidebarSpace />
      <SidebarDivider />
      <SidebarGroup
        label="Settings"
        icon={<UserSettingsSignInAvatar />}
        to="/settings"
      >
        <SidebarSettings />
      </SidebarGroup>
    </Sidebar>
    {children}
  </SidebarPage>
);

Option 2: Dynamic plugin

This option describes how to install this plugin in Red Hat Developer Hub (RHDH). It is advised to review the official documentation corresponding to your deployment.

  1. Open Red Hat Developer Hub:
  2. Navigate to the Helm Chart:
    • Go to the Helm tab in your Red Hat OpenShift console.
  3. Edit the Helm Chart Values:
    • Include the plugin in the Helm chart values as shown in the example below:
global:
  dynamic:
    plugins:
      - package: '@marek.libra/plugin-redhat-resource-optimization-dynamic@1.0.0'
        integrity: 'sha512-Qd8pniy1yRx+x7LnwjzQ6k9zP+C1yex24MaCcx7dGDPT/XbTokwoSZr4baSSn8jUA6P45NUUevu1d629mG4JGQ=='
      - package: '@marek.libra/plugin-redhat-resource-optimization-backend-dynamic@1.0.0'
        integrity: 'sha512-Q1d629mG4JGd8pniy1yRx+x7LnwjzQ6k9zP+C1yex24MaCcx7dGDPT/XbTokwoSZr4baSSn8jUA6P45NUUevud8pniy1yRQx=='
  1. Include the below configuration in the app-config.yaml ConfigMap to setup the front-end side of the plugin
dynamicPlugins:
  frontend:
    backstage-community.plugin-redhat-resource-optimization:
      appIcons:
        - name: resourceOptimizationIconOutlined
          importName: ResourceOptimizationIconOutlined
      routeBindings:
        targets:
          - name: resourceOptimizationPlugin
      dynamicRoutes:
        - path: /redhat-resource-optimization
          importName: ResourceOptimizationPage
          menuItem:
            icon: resourceOptimizationIconOutlined
            text: Optimizations

Configuration

Step 1: Create a service account in Red Hat Hybrid Cloud Console (RHHCC)

The plugin consumes services from Red Hat Hybrid Cloud Console, therefore your clusters must be registered in the Red Hat Hybrid Cloud Console and the service account you'll create must be assigned the Cost OpenShift Viewer role. Follow this link to learn more on how to create the service account.

Step 2: Update the app-config.yaml

The settings below the proxy key configure Backstage's internal proxy to make calls on-behalf of the service account to the upstream API. Replace ${RHHCC_SA_CLIENT_ID} and ${RHHCC_SA_CLIENT_SECRET} in the snippet below with the credentials you obtained after creating the service account.

# app-config.yaml

# Other config...

proxy:
  endpoints:
    '/cost-management/v1':
      target: https://console.redhat.com/api/cost-management/v1
      allowedHeaders: ['Authorization']
      # See: https://backstage.io/docs/releases/v1.28.0/#breaking-proxy-backend-plugin-protected-by-default
      credentials: dangerously-allow-unauthenticated

resourceOptimization:
  clientId: ${RHHCC_SA_CLIENT_ID}
  clientSecret: ${RHHCC_SA_CLIENT_SECRET}

Contributing