feat: Make PodExecTerminal UI OptIn
Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
'@backstage/plugin-kubernetes-react': patch
|
||||
---
|
||||
|
||||
Make PodExecTerminal UI OptIn
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
import { PodExecTerminal } from './src/components/PodExecTerminal/PodExecTerminal';
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export interface Config {
|
||||
kubernetes?: {
|
||||
/**
|
||||
* Pod Exec Terminal config
|
||||
*/
|
||||
podExecTerminal?: {
|
||||
/**
|
||||
* Enable `PodExecTerminal` UI feature
|
||||
* @visibility frontend
|
||||
*/
|
||||
enable?: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
"role": "web-library"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"configSchema": "config.d.ts",
|
||||
"scripts": {
|
||||
"start": "backstage-cli package start",
|
||||
"build": "backstage-cli package build",
|
||||
@@ -60,6 +61,7 @@
|
||||
"msw": "^1.3.1"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"config.d.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import { IContainer, IContainerStatus } from 'kubernetes-models/v1';
|
||||
import { DateTime } from 'luxon';
|
||||
import React from 'react';
|
||||
|
||||
import { useIsPodExecTerminalEnabled } from '../../../hooks';
|
||||
import { bytesToMiB, formatMillicores } from '../../../utils/resources';
|
||||
import { PodExecTerminalDialog } from '../../PodExecTerminal/PodExecTerminalDialog';
|
||||
import { ResourceUtilization } from '../../ResourceUtilization';
|
||||
@@ -108,6 +109,8 @@ export const ContainerCard: React.FC<ContainerCardProps> = ({
|
||||
containerStatus,
|
||||
containerMetrics,
|
||||
}: ContainerCardProps) => {
|
||||
const isPodExecTerminalEnabled = useIsPodExecTerminalEnabled();
|
||||
|
||||
// This should never be undefined
|
||||
if (containerSpec === undefined) {
|
||||
return <Typography>error reading pod from cluster</Typography>;
|
||||
@@ -228,12 +231,14 @@ export const ContainerCard: React.FC<ContainerCardProps> = ({
|
||||
...podScope,
|
||||
}}
|
||||
/>
|
||||
<PodExecTerminalDialog
|
||||
clusterName={podScope.clusterName}
|
||||
containerName={containerStatus.name}
|
||||
podName={podScope.podName}
|
||||
podNamespace={podScope.podNamespace}
|
||||
/>
|
||||
{isPodExecTerminalEnabled && (
|
||||
<PodExecTerminalDialog
|
||||
clusterName={podScope.clusterName}
|
||||
containerName={containerStatus.name}
|
||||
podName={podScope.podName}
|
||||
podNamespace={podScope.podNamespace}
|
||||
/>
|
||||
)}
|
||||
</CardActions>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './useIsPodExecTerminalEnabled';
|
||||
export * from './useIsPodExecTerminalSupported';
|
||||
export * from './useKubernetesObjects';
|
||||
export * from './useCustomResources';
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ConfigReader } from '@backstage/core-app-api';
|
||||
import { configApiRef } from '@backstage/core-plugin-api';
|
||||
import { TestApiProvider } from '@backstage/test-utils';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { PropsWithChildren } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
import { useIsPodExecTerminalEnabled } from './useIsPodExecTerminalEnabled';
|
||||
|
||||
describe('useIsPodExecTerminalEnabled', () => {
|
||||
let isPodExecTerminalEnabled: boolean | undefined;
|
||||
|
||||
const apiWrapper = ({ children }: PropsWithChildren) => (
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[
|
||||
configApiRef,
|
||||
new ConfigReader({
|
||||
kubernetes: {
|
||||
podExecTerminal: { enable: isPodExecTerminalEnabled },
|
||||
},
|
||||
}),
|
||||
],
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
condition: 'missing config',
|
||||
returnValue: undefined,
|
||||
},
|
||||
{ condition: 'disabled', returnValue: false },
|
||||
{
|
||||
condition: 'enabled',
|
||||
returnValue: true,
|
||||
},
|
||||
])('Should return $returnValue if $condition', async ({ returnValue }) => {
|
||||
isPodExecTerminalEnabled = returnValue;
|
||||
|
||||
const { result } = renderHook(() => useIsPodExecTerminalEnabled(), {
|
||||
wrapper: apiWrapper,
|
||||
});
|
||||
|
||||
expect(result.current).toEqual(returnValue);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { configApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
|
||||
/**
|
||||
* Check if conditions for a pod exec call through the proxy endpoint are met
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const useIsPodExecTerminalEnabled = (): boolean | undefined => {
|
||||
const configApi = useApi(configApiRef);
|
||||
|
||||
return configApi.getOptionalBoolean('kubernetes.podExecTerminal.enable');
|
||||
};
|
||||
@@ -20,7 +20,7 @@ import { useIsPodExecTerminalSupported } from './useIsPodExecTerminalSupported';
|
||||
|
||||
jest.mock('@backstage/core-plugin-api');
|
||||
|
||||
describe('useIsClusterShellEnabled', () => {
|
||||
describe('useIsPodExecTerminalSupported', () => {
|
||||
let clusters: { authProvider: string }[] = [];
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import useAsync, { AsyncState } from 'react-use/lib/useAsync';
|
||||
|
||||
import { kubernetesApiRef } from '../api/types';
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user