Skip to content

Commit 67c18a8

Browse files
authored
sync with community-plugins (#1038)
Signed-off-by: Yaron Dayagi <ydayagi@redhat.com>
1 parent f87e495 commit 67c18a8

File tree

6 files changed

+253
-6
lines changed

6 files changed

+253
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@red-hat-developer-hub/plugin-redhat-resource-optimization-backend': major
3+
'@red-hat-developer-hub/plugin-redhat-resource-optimization-common': major
4+
'@red-hat-developer-hub/plugin-redhat-resource-optimization': major
5+
---
6+
7+
sync with original repo

workspaces/redhat-resource-optimization/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ coverage
1515
# Dependencies
1616
node_modules/
1717

18+
# NPM directories
19+
.npm/
20+
.npm-global/
21+
22+
# Corepack cache directory
23+
.cache/
24+
1825
# Yarn 3 files
1926
.pnp.*
2027
.yarn/*
Lines changed: 156 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,159 @@
11
# Welcome to the Resource Optimization plugin workspace
22

3-
Follow these links to learn more about this plugin:
3+
## Resource Optimization
44

5-
1. [Front-end](./plugins/redhat-resource-optimization/README.md)
6-
2. [Backend-end](./plugins/redhat-resource-optimization-backend/README.md)
7-
3. [Common](./plugins/redhat-resource-optimization-common/README.md)
8-
4. [RBAC](./docs/rbac.md)
5+
Welcome to the Resource Optimization plugin!
6+
7+
Resource Optimization plugin allows users to visualize usage trends and receive optimization recommendations for workloads running on OpenShift clusters.
8+
There is also an option to automatically apply recommendations. Refer to [Optimizer App](#optimizer-app) section
9+
10+
## Getting started
11+
12+
### Prerequisite
13+
14+
The plugin consumes services from [Red Hat Hybrid Cloud Console](https://console.redhat.com/openshift/cost-management/optimizations), therefore your clusters [must be configured to receive optimization recommendations](https://docs.redhat.com/en/documentation/cost_management_service/1-latest/html-single/getting_started_with_resource_optimization_for_openshift/index).
15+
16+
#### Service Account Details
17+
18+
You will need to two service accounts from Red Hat Hybrid Cloud Console.
19+
20+
- [Use this link](https://console.redhat.com/iam/service-accounts/) to create service accounts
21+
22+
- [please go through this guide](https://docs.redhat.com/en/documentation/cost_management_service/1-latest/html/limiting_access_to_cost_management_resources/assembly-limiting-access-cost-resources-rbac) and assign below roles to your `service accounts`
23+
24+
1. Service account with `Cloud Administrator` role for configuring `Cost Management Metrics Operator`
25+
2. Service account with `Cost OpenShift Viewer` role for viewing the optimization data in the RHDH Resource Optimization plugin
26+
27+
## Setup
28+
29+
You can follow one of these options for installing `Resource Optimization` depending on your environment.
30+
31+
### Option 1: Dynamic plugin - on a Red Hat Developer Hub(RHDH) instance
32+
33+
[Follow this link](./docs/dynamic-plugin.md) for installing plugin as Dynamic Plugin
34+
35+
#### Dependency on Orchestrator plugin and Workflow details
36+
37+
The Resource Optimization plugin is dependent on [Orchestrator plugin](https://www.rhdhorchestrator.io/main/docs/) to run the workflow for applying the recommendation. Make sure you have installed the [Orchestrator plugin](https://www.rhdhorchestrator.io/main/docs/) by following one of these options depending on your environment:
38+
39+
- [Install Orchestrator plugin on an exisiting RHDH instance](https://www.rhdhorchestrator.io/main/docs/installation/installation-on-existing-rhdh/)
40+
- [Install Orchestrator plugin with an RHDH instance](https://www.rhdhorchestrator.io/main/docs/installation/orchestrator/)
41+
42+
This method requires vanilla backstage to be used:
43+
44+
- [Install as a static plugin for local development](https://github.com/redhat-developer/rhdh-plugins/tree/main/workspaces/orchestrator#install-as-a-static-plugin)
45+
46+
**Workflow details** : [Here is the link to the workflow](https://github.com/rhdhorchestrator/serverless-workflows/tree/main/workflows/patch-k8s-resource) which is being used for manually applying the recommendation from the Resource Optimization plugin.
47+
48+
### Option 2: Static plugin - on Vanilla Backstage
49+
50+
1. Add the dependencies
51+
52+
```sh
53+
# From your Backstage root directory
54+
yarn --cwd packages/app add @backstage-community/plugin-redhat-resource-optimization
55+
yarn --cwd packages/backend add @backstage-community/plugin-redhat-resource-optimization-backend
56+
```
57+
58+
1. Update your `app-config.yaml` file
59+
60+
```yaml
61+
# app-config.yaml
62+
63+
proxy:
64+
endpoints:
65+
'/cost-management/v1':
66+
target: https://console.redhat.com/api/cost-management/v1
67+
allowedHeaders: ['Authorization']
68+
# See: https://backstage.io/docs/releases/v1.28.0/#breaking-proxy-backend-plugin-protected-by-default
69+
credentials: dangerously-allow-unauthenticated
70+
71+
# Replace `${RHHCC_SA_CLIENT_ID}` and `${RHHCC_SA_CLIENT_SECRET}` with the service account credentials.
72+
resourceOptimization:
73+
clientId: ${RHHCC_SA_CLIENT_ID}
74+
clientSecret: ${RHHCC_SA_CLIENT_SECRET}
75+
optimizationWorkflowId: 'patch-k8s-resource'
76+
```
77+
78+
1. Add the back-end plugin to `packages/backend/src/index.ts`
79+
80+
```ts
81+
backend.add(
82+
import('@backstage-community/plugin-redhat-resource-optimization-backend'),
83+
);
84+
```
85+
86+
1. Add the `ResourceOptimizationPage` extension to your `App.tsx` routes
87+
88+
```ts
89+
// packages/app/src/App.tsx
90+
91+
import { ResourceOptimizationPage } from '@backstage-community/plugin-redhat-resource-optimization';
92+
93+
<FlatRoutes>
94+
...
95+
<Route
96+
path="/redhat-resource-optimization"
97+
element={<ResourceOptimizationPage />}
98+
/>
99+
...
100+
</FlatRoutes>;
101+
```
102+
103+
1. Add a link to the Resource Optimization page in the side bar
104+
105+
```diff
106+
// packages/app/src/components/Root/Root.tsx
107+
108+
+ import { ResourceOptimizationIconOutlined } from '@backstage-community/plugin-redhat-resource-optimization';
109+
110+
export const Root = ({ children }: PropsWithChildren<{}>) => (
111+
<SidebarPage>
112+
<Sidebar>
113+
<SidebarLogo />
114+
<SidebarGroup label="Search" icon={<SearchIcon />} to="/search">
115+
<SidebarSearchModal />
116+
</SidebarGroup>
117+
<SidebarDivider />
118+
<SidebarGroup label="Menu" icon={<MenuIcon />}>
119+
{/* Global nav, not org-specific */}
120+
<SidebarItem icon={HomeIcon} to="catalog" text="Home" />
121+
<SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
122+
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
123+
<SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
124+
{/* End global nav */}
125+
<SidebarDivider />
126+
<SidebarScrollWrapper>
127+
<SidebarItem icon={MapIcon} to="tech-radar" text="Tech Radar" />
128+
</SidebarScrollWrapper>
129+
+ <SidebarItem
130+
+ icon={ResourceOptimizationIconOutlined}
131+
+ to="/redhat-resource-optimization"
132+
+ text="Optimizations"
133+
+ />
134+
</SidebarGroup>
135+
<SidebarSpace />
136+
<SidebarDivider />
137+
<SidebarGroup
138+
label="Settings"
139+
icon={<UserSettingsSignInAvatar />}
140+
to="/settings"
141+
>
142+
<SidebarSettings />
143+
</SidebarGroup>
144+
</Sidebar>
145+
{children}
146+
</SidebarPage>
147+
);
148+
```
149+
150+
## RBAC Permissions
151+
152+
The HTTP endpoints exposed by the redhat-resource-optimization-backend can enforce authorization if the [RBAC plugin](https://github.com/backstage/community-plugins/tree/main/workspaces/rbac/plugins) is deployed. Please refer the RBAC plugin documentation for the setup steps (mind they rely on the [Backstage authentication and identity](https://backstage.io/docs/auth/)).
153+
154+
- More detailed info about Resource Optimization plugin RBAC permissions can be found in [docs/rbac.md](./docs/rbac.md)
155+
- More detailed info about Orcestrator plugin RBAC for setting up permission for workflow can be [found here](https://github.com/redhat-developer/rhdh-plugins/blob/main/workspaces/orchestrator/docs/Permissions.md).
156+
157+
## Optimizer App
158+
159+
An application for applying the recommendations automatically. The application makes use of OSL (OpenShift Serverless Logic, a.k.a. SonataFlow) which is part of the Orchestrator installation. If you already have the [Orchestrator plugin and the workflow](#dependency-on-orchestrator-plugin-and-workflow-details) installed then you are ready for installing the Optimizer application. Follow the [application instructions](https://github.com/rhdhorchestrator/optimizer/tree/main) for installing and configuring it.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## Installing as Dynamic Plugin
2+
3+
Unlike static plugins that necessitate source code modifications, dynamic plugins can be seamlessly integrated through configuration entries in the `app-config.yaml` file.
4+
Red Hat Developer Hub (RHDH) leverages dynamic plugins to efficiently deploy plugins on a Backstage instance.
5+
6+
The procedure involves the following steps:
7+
8+
1. Ensure you are familiar with the [RHDH configuration docs](https://docs.redhat.com/en/documentation/red_hat_developer_hub/1.6/html/configuring_red_hat_developer_hub/index) and [RHDH plugin installation guide](https://docs.redhat.com/en/documentation/red_hat_developer_hub/1.6/html/installing_and_viewing_plugins_in_red_hat_developer_hub/index)
9+
10+
2. The plugin consumes services from [Red Hat Hybrid Cloud Console](https://console.redhat.com/openshift/cost-management/optimizations), therefore your clusters [must be configured to receive optimization recommendations](https://docs.redhat.com/en/documentation/cost_management_service/1-latest/html-single/getting_started_with_resource_optimization_for_openshift/index).
11+
Copy and save the `CLIENT_ID` & `CLIENT_SECRET` from service account you created earlier with `Cost OpenShift Viewer` role. This will be needed during configuration step below.
12+
13+
3. Specially, make sure you have configured
14+
15+
- ConfigMaps: `app-config-rhdh`, `dynamic-plugins-rhdh`
16+
- Secrets: `secrets-rhdh`
17+
18+
4. Add the following configuration to each one of the objects mentioned above respectively
19+
20+
```yaml
21+
# Add to secrets-rhdh Secret
22+
# replace the CLIENT_ID and CLIENT_SECRET which you have saved from the previous step from your service account
23+
# with `Cost OpenShift Viewer` role
24+
25+
ROS_CLIENT_ID: # <as base64 string>
26+
ROS_CLIENT_SECRET: # <as base64 string>
27+
```
28+
29+
```yaml
30+
# Add to app-config-rhdh ConfigMap
31+
32+
proxy:
33+
endpoints:
34+
'/cost-management/v1':
35+
target: https://console.redhat.com/api/cost-management/v1
36+
allowedHeaders: ['Authorization']
37+
credentials: dangerously-allow-unauthenticated
38+
resourceOptimization:
39+
clientId: '${ROS_CLIENT_ID}'
40+
clientSecret: '${ROS_CLIENT_SECRET}'
41+
```
42+
43+
```yaml
44+
# Add to dynamic-plugins-rhdh ConfigMap
45+
46+
- package: oci://quay.io/redhat-resource-optimization/dynamic-plugins:1.1.0!backstage-community-plugin-redhat-resource-optimization
47+
disabled: false
48+
pluginConfig:
49+
dynamicPlugins:
50+
frontend:
51+
backstage-community.plugin-redhat-resource-optimization:
52+
appIcons:
53+
- name: resourceOptimizationIconOutlined
54+
importName: ResourceOptimizationIconOutlined
55+
dynamicRoutes:
56+
- path: /redhat-resource-optimization
57+
importName: ResourceOptimizationPage
58+
menuItem:
59+
icon: resourceOptimizationIconOutlined
60+
text: Optimizations
61+
- package: oci://quay.io/redhat-resource-optimization/dynamic-plugins:1.1.0!backstage-community-plugin-redhat-resource-optimization-backend
62+
disabled: false
63+
pluginConfig:
64+
proxy:
65+
endpoints:
66+
'/cost-management/v1':
67+
target: https://console.redhat.com/api/cost-management/v1
68+
allowedHeaders: ['Authorization']
69+
credentials: dangerously-allow-unauthenticated
70+
resourceOptimization:
71+
clientId: ${ROS_CLIENT_ID}
72+
clientSecret: ${ROS_CLIENT_SECRET}
73+
optimizationWorkflowId: 'patch-k8s-resource'
74+
```
75+
76+
### References
77+
78+
- [Installing ROS-OCP RHDH plugin on Red Hat Developer Hub on a Openshift Cluster](https://docs.google.com/document/d/1tExe7cEBYMJplkk9ppSdBINwE-14KmxURczGjloHqZ4/edit?usp=sharing)
79+
80+
- [Documentation to understand how to export this plugin as a dynamic plugin](https://github.com/janus-idp/backstage-showcase/blob/main/docs/dynamic-plugins/export-derived-package.md)

workspaces/redhat-resource-optimization/docs/rbac.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ permission:
6464
users:
6565
- name: user:default/YOUR_USER
6666
```
67+
68+
[Refer to this link](https://docs.redhat.com/en/documentation/red_hat_developer_hub/1.6/html/authorization_in_red_hat_developer_hub/index) to configure and enable RBAC for Red Hat Developer Hub.

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization/src/pages/optimizations/OptimizationsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export function OptimizationsPage() {
252252
}}
253253
localization={{
254254
toolbar: {
255-
searchPlaceholder: 'Search Container',
255+
searchPlaceholder: 'Search container name',
256256
},
257257
}}
258258
data={data}

0 commit comments

Comments
 (0)