remove backend-common from plugin-kubernetes-node

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2025-04-28 17:09:46 +02:00
parent 3551662f98
commit 9cdf00128c
7 changed files with 16 additions and 24 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes-node': minor
---
The `PinnipedHelper` class now expects a regular `LoggerService` instance from the new backend system, instead of a Winston logger.
@@ -182,7 +182,7 @@ Let's create a new file to house the Pinniped authentication strategy which will
```ts title="plugins/kubernetes-backend-module-pinniped/src/PinnipedStrategy.ts"
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import {
AuthMetadata,
AuthenticationStrategy,
@@ -197,7 +197,7 @@ import { JsonObject } from '@backstage/types';
export class PinnipedStrategy implements AuthenticationStrategy {
private pinnipedHelper: PinnipedHelper;
constructor(private readonly logger: Logger) {
constructor(private readonly logger: LoggerService) {
this.pinnipedHelper = new PinnipedHelper(logger);
}
@@ -239,7 +239,7 @@ export class PinnipedStrategy implements AuthenticationStrategy {
}
```
The `PinnipedStrategy` implements the `AuthenticationStrategy` interface, it uses the PinnipedHelper class to exchange the clusterIdToken ( created by a custom Pinniped client-side `KubernetesAuthProvider` ) for a x509 certificate, certificate that will allow us to consume the kubernetes cluster. It also returns the audience value to the front-end through `presentAuthMetadata`.
The `PinnipedStrategy` implements the `AuthenticationStrategy` interface, it uses the `PinnipedHelper` class to exchange the `clusterIdToken` ( created by a custom Pinniped client-side `KubernetesAuthProvider` ) for a x509 certificate, certificate that will allow us to consume the kubernetes cluster. It also returns the audience value to the front-end through `presentAuthMetadata`.
> Notice that the PinnipedHelper class will help you only to exchange the token, It doesn't introduce a cache layer, something that your strategy could introduce.
@@ -250,12 +250,8 @@ import {
coreServices,
createBackendModule,
} from '@backstage/backend-plugin-api';
import {
AuthenticationStrategy,
kubernetesAuthStrategyExtensionPoint,
} from '@backstage/plugin-kubernetes-node';
import { kubernetesAuthStrategyExtensionPoint } from '@backstage/plugin-kubernetes-node';
import { PinnipedStrategy } from './PinnipedStrategy';
import { loggerToWinstonLogger } from '@backstage/backend-common';
export const kubernetesModulePinniped = createBackendModule({
pluginId: 'kubernetes',
@@ -267,11 +263,7 @@ export const kubernetesModulePinniped = createBackendModule({
authStrategy: kubernetesAuthStrategyExtensionPoint,
},
async init({ logger, authStrategy }) {
const winstonLogger = loggerToWinstonLogger(logger);
const pinnipedStrategy: AuthenticationStrategy = new PinnipedStrategy(
winstonLogger,
);
authStrategy.addAuthStrategy('pinniped', pinnipedStrategy);
authStrategy.addAuthStrategy('pinniped', new PinnipedStrategy(logger));
},
});
},
@@ -288,7 +280,6 @@ import { KubernetesBuilder } from '@backstage/plugin-kubernetes-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { CatalogClient } from '@backstage/catalog-client';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { AuthenticationStrategy } from '@backstage/plugin-kubernetes-node';
import { PinnipedStrategy } from '@internal/plugin-kubernetes-backend-module-pinniped';
@@ -296,9 +287,8 @@ export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const catalogApi = new CatalogClient({ discoveryApi: env.discovery });
const winstonLogger = loggerToWinstonLogger(env.logger);
const pinnipedStrategy: AuthenticationStrategy = new PinnipedStrategy(
winstonLogger,
env.logger,
);
const { router } = await KubernetesBuilder.createBuilder({
logger: env.logger,
-1
View File
@@ -48,7 +48,6 @@
},
"devDependencies": {
"@backstage/backend-app-api": "workspace:^",
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-defaults": "workspace:^",
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^",
+2 -2
View File
@@ -17,7 +17,7 @@ import { KubernetesFetchError } from '@backstage/plugin-kubernetes-common';
import { KubernetesObjectsProvider as KubernetesObjectsProvider_2 } from '@backstage/plugin-kubernetes-node';
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
import { KubernetesServiceLocator as KubernetesServiceLocator_2 } from '@backstage/plugin-kubernetes-node';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { ObjectsByEntityResponse } from '@backstage/plugin-kubernetes-common';
// @public (undocumented)
@@ -253,7 +253,7 @@ export type PinnipedClientCerts = {
// @public (undocumented)
export class PinnipedHelper {
constructor(logger: Logger);
constructor(logger: LoggerService);
// (undocumented)
tokenCredentialRequest(
clusterDetails: ClusterDetails_2,
@@ -35,14 +35,13 @@ import { HEADER_KUBERNETES_CLUSTER } from '@backstage/plugin-kubernetes-backend'
import { JsonObject } from '@backstage/types';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { ExtendedHttpServer } from '@backstage/backend-defaults/rootHttpRouter';
jest.setTimeout(60_000);
describe('Pinniped - tokenCredentialRequest', () => {
let app: ExtendedHttpServer;
const logger = loggerToWinstonLogger(mockServices.logger.mock());
const logger = mockServices.logger.mock();
let httpsRequest: jest.SpyInstance;
const worker = setupServer();
registerMswTestHooks(worker);
@@ -14,10 +14,10 @@
* limitations under the License.
*/
import { LoggerService } from '@backstage/backend-plugin-api';
import { ClusterDetails } from '@backstage/plugin-kubernetes-node';
import * as https from 'https';
import fetch, { RequestInit } from 'node-fetch';
import { Logger } from 'winston';
/**
*
@@ -50,7 +50,7 @@ export type PinnipedParameters = {
* @public
*/
export class PinnipedHelper {
constructor(private readonly logger: Logger) {}
constructor(private readonly logger: LoggerService) {}
public async tokenCredentialRequest(
clusterDetails: ClusterDetails,
-1
View File
@@ -6882,7 +6882,6 @@ __metadata:
resolution: "@backstage/plugin-kubernetes-node@workspace:plugins/kubernetes-node"
dependencies:
"@backstage/backend-app-api": "workspace:^"
"@backstage/backend-common": "npm:^0.25.0"
"@backstage/backend-defaults": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"