Bump @kubernetes/client-node to ^1.0.0-rc7

Signed-off-by: Corey Daley <cdaley@redhat.com>
This commit is contained in:
Corey Daley
2024-10-14 13:59:24 -04:00
parent 112fd691e4
commit 71b87043ef
15 changed files with 206 additions and 47 deletions
+1 -1
View File
@@ -78,7 +78,7 @@
"@backstage/types": "workspace:^",
"@google-cloud/container": "^5.0.0",
"@jest-mock/express": "^2.0.1",
"@kubernetes/client-node": "0.20.0",
"@kubernetes/client-node": "1.0.0-rc7",
"@types/express": "^4.17.6",
"@types/http-proxy-middleware": "^1.0.0",
"@types/luxon": "^3.0.0",
@@ -30,7 +30,6 @@ import {
mockServices,
registerMswTestHooks,
} from '@backstage/backend-test-utils';
import { Config } from '@kubernetes/client-node';
const mockCertDir = createMockDirectory({
content: {
@@ -651,6 +650,7 @@ describe('KubernetesFetcher', () => {
});
describe('when server uses TLS', () => {
let httpsRequest: jest.SpyInstance;
const initialCAPath = process.env.KUBERNETES_CA_FILE_PATH;
beforeAll(() => {
httpsRequest = jest.spyOn(
// this is pretty egregious reverse engineering of msw.
@@ -662,7 +662,13 @@ describe('KubernetesFetcher', () => {
});
beforeEach(() => {
httpsRequest.mockClear();
process.env.KUBERNETES_CA_FILE_PATH = mockCertDir.resolve('ca.crt');
});
afterEach(() => {
process.env.KUBERNETES_CA_FILE_PATH = initialCAPath;
});
it('should trust specified caData', async () => {
worker.use(
rest.get('https://localhost:9999/api/v1/pods', (req, res, ctx) =>
@@ -755,7 +761,7 @@ describe('KubernetesFetcher', () => {
name: 'cluster1',
url: 'https://localhost:9999',
authMetadata: {},
caFile: mockCertDir.resolve('ca.crt'),
caFile: process.env.KUBERNETES_CA_FILE_PATH,
},
credential: { type: 'bearer token', token: 'token' },
objectTypesToFetch: new Set<ObjectToFetch>([
@@ -1009,7 +1015,7 @@ describe('KubernetesFetcher', () => {
serviceId: 'some-service',
clusterDetails: {
name: 'unauthenticated-cluster',
url: 'http://ignored',
url: 'https://10.10.10.10',
authMetadata: {},
},
credential: { type: 'anonymous' },
@@ -1025,18 +1031,21 @@ describe('KubernetesFetcher', () => {
describe('Backstage running on k8s', () => {
const initialHost = process.env.KUBERNETES_SERVICE_HOST;
const initialPort = process.env.KUBERNETES_SERVICE_PORT;
const initialCaPath = Config.SERVICEACCOUNT_CA_PATH;
const initialCAPath = process.env.KUBERNETES_CA_FILE_PATH;
beforeEach(() => {
process.env.KUBERNETES_CA_FILE_PATH = mockCertDir.resolve('ca.crt');
});
afterEach(() => {
process.env.KUBERNETES_SERVICE_HOST = initialHost;
process.env.KUBERNETES_SERVICE_PORT = initialPort;
Config.SERVICEACCOUNT_CA_PATH = initialCaPath;
process.env.KUBERNETES_CA_FILE_PATH = initialCAPath;
});
it('makes in-cluster requests when cluster details has no token', async () => {
process.env.KUBERNETES_SERVICE_HOST = '10.10.10.10';
process.env.KUBERNETES_SERVICE_PORT = '443';
Config.SERVICEACCOUNT_CA_PATH = mockCertDir.resolve('ca.crt');
worker.use(
rest.get('https://10.10.10.10/api/v1/pods', (req, res, ctx) =>
res(
@@ -1052,7 +1061,7 @@ describe('KubernetesFetcher', () => {
serviceId: 'some-service',
clusterDetails: {
name: 'overridden-to-in-cluster',
url: 'http://ignored',
url: 'https://10.10.10.10',
authMetadata: {
[ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'serviceAccount',
},
@@ -17,7 +17,6 @@
import {
bufferFromFileOrString,
Cluster,
Config,
CoreV1Api,
KubeConfig,
Metrics,
@@ -31,6 +30,7 @@ import {
} from '../types/types';
import {
ANNOTATION_KUBERNETES_AUTH_PROVIDER,
SERVICEACCOUNT_CA_PATH,
FetchResponse,
KubernetesErrorTypes,
KubernetesFetchError,
@@ -156,8 +156,7 @@ export class KubernetesClientBasedFetcher implements KubernetesFetcher {
if (podMetrics.ok && podList.ok) {
return topPods(
{
listPodForAllNamespaces: () =>
podList.json().then(b => ({ body: b })),
listPodForAllNamespaces: () => podList.json(),
} as unknown as CoreV1Api,
{
getPodMetrics: () => podMetrics.json(),
@@ -249,7 +248,7 @@ export class KubernetesClientBasedFetcher implements KubernetesFetcher {
return (
authProvider === 'serviceAccount' &&
!clusterDetails.authMetadata.serviceAccountToken &&
fs.pathExistsSync(Config.SERVICEACCOUNT_CA_PATH)
fs.pathExistsSync(SERVICEACCOUNT_CA_PATH)
);
}
@@ -39,7 +39,6 @@ import { rest } from 'msw';
import { setupServer } from 'msw/node';
import request from 'supertest';
import { AddressInfo, WebSocket, WebSocketServer } from 'ws';
import { Config } from '@kubernetes/client-node';
import { LocalKubectlProxyClusterLocator } from '../cluster-locator/LocalKubectlProxyLocator';
import {
@@ -1014,23 +1013,26 @@ describe('KubernetesProxy', () => {
describe('Backstage running on k8s', () => {
const initialHost = process.env.KUBERNETES_SERVICE_HOST;
const initialPort = process.env.KUBERNETES_SERVICE_PORT;
const initialCaPath = Config.SERVICEACCOUNT_CA_PATH;
const initialCAPath = process.env.KUBERNETES_CA_FILE_PATH;
beforeEach(() => {
process.env.KUBERNETES_CA_FILE_PATH = mockCertDir.resolve('ca.crt');
});
afterEach(() => {
process.env.KUBERNETES_SERVICE_HOST = initialHost;
process.env.KUBERNETES_SERVICE_PORT = initialPort;
Config.SERVICEACCOUNT_CA_PATH = initialCaPath;
process.env.KUBERNETES_CA_FILE_PATH = initialCAPath;
});
it('makes in-cluster requests when cluster details has no token', async () => {
process.env.KUBERNETES_SERVICE_HOST = '10.10.10.10';
process.env.KUBERNETES_SERVICE_PORT = '443';
Config.SERVICEACCOUNT_CA_PATH = mockCertDir.resolve('ca.crt');
clusterSupplier.getClusters.mockResolvedValue([
{
name: 'cluster1',
url: 'http://ignored',
url: 'https://10.10.10.10',
authMetadata: {
[ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'serviceAccount',
},
@@ -22,6 +22,7 @@ import {
} from '@backstage/errors';
import {
ANNOTATION_KUBERNETES_AUTH_PROVIDER,
SERVICEACCOUNT_CA_PATH,
kubernetesProxyPermission,
KubernetesRequestAuth,
} from '@backstage/plugin-kubernetes-common';
@@ -29,7 +30,6 @@ import { AuthorizeResult } from '@backstage/plugin-permission-common';
import {
bufferFromFileOrString,
Cluster,
Config,
KubeConfig,
} from '@kubernetes/client-node';
import { createProxyMiddleware, RequestHandler } from 'http-proxy-middleware';
@@ -263,7 +263,7 @@ export class KubernetesProxy {
if (
authProvider === 'serviceAccount' &&
fs.pathExistsSync(Config.SERVICEACCOUNT_CA_PATH) &&
fs.pathExistsSync(SERVICEACCOUNT_CA_PATH) &&
!cluster.authMetadata.serviceAccountToken
) {
const kc = new KubeConfig();