chore: Exporting KubernetesClientProvider as requested in issue #10457 (#13225)

* chore: Exporting KubernetesClientProvider as requested in issue #10457

Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>

* chore: Adding changeset

Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>

* chore: Updating API reports

Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>

* chore: Export auth translator contents & updating API reports

Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>

* chore: Fix API reports warnings

Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>

Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>
Co-authored-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>
This commit is contained in:
Carlos Esteban Lopez Jaramillo
2022-09-02 12:34:58 -05:00
committed by GitHub
parent 68d48f463b
commit 8902c2e39d
12 changed files with 177 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes-backend': patch
---
chore: Exporting KubernetesClientProvider and everything in kubernetes-auth-translator as requested in issue #10457
+120 -1
View File
@@ -5,18 +5,24 @@
```ts
import { CatalogApi } from '@backstage/catalog-client';
import { Config } from '@backstage/config';
import { CoreV1Api } from '@kubernetes/client-node';
import { Credentials } from 'aws-sdk';
import { CustomObjectsApi } from '@kubernetes/client-node';
import { Duration } from 'luxon';
import { Entity } from '@backstage/catalog-model';
import express from 'express';
import type { FetchResponse } from '@backstage/plugin-kubernetes-common';
import type { JsonObject } from '@backstage/types';
import { KubeConfig } from '@kubernetes/client-node';
import type { KubernetesFetchError } from '@backstage/plugin-kubernetes-common';
import type { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
import type { KubernetesRequestBody } from '@backstage/plugin-kubernetes-common';
import { Logger } from 'winston';
import { Metrics } from '@kubernetes/client-node';
import type { ObjectsByEntityResponse } from '@backstage/plugin-kubernetes-common';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { PodStatus } from '@kubernetes/client-node/dist/top';
import { TokenCredential } from '@azure/identity';
// @alpha (undocumented)
export interface AWSClusterDetails extends ClusterDetails {
@@ -26,9 +32,45 @@ export interface AWSClusterDetails extends ClusterDetails {
externalId?: string;
}
// @alpha (undocumented)
export class AwsIamKubernetesAuthTranslator
implements KubernetesAuthTranslator
{
// (undocumented)
awsGetCredentials: () => Promise<Credentials>;
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: AWSClusterDetails,
): Promise<AWSClusterDetails>;
// (undocumented)
getBearerToken(
clusterName: string,
assumeRole?: string,
externalId?: string,
): Promise<string>;
// (undocumented)
getCredentials(
assumeRole?: string,
externalId?: string,
): Promise<SigningCreds>;
// (undocumented)
validCredentials(creds: SigningCreds): boolean;
}
// @alpha (undocumented)
export interface AzureClusterDetails extends ClusterDetails {}
// @alpha (undocumented)
export class AzureIdentityKubernetesAuthTranslator
implements KubernetesAuthTranslator
{
constructor(logger: Logger, tokenCredential?: TokenCredential);
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: AzureClusterDetails,
): Promise<AzureClusterDetails>;
}
// @alpha (undocumented)
export interface ClusterDetails {
// (undocumented)
@@ -82,6 +124,47 @@ export interface FetchResponseWrapper {
// @alpha (undocumented)
export interface GKEClusterDetails extends ClusterDetails {}
// @alpha (undocumented)
export class GoogleKubernetesAuthTranslator
implements KubernetesAuthTranslator
{
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: GKEClusterDetails,
authConfig: KubernetesRequestAuth,
): Promise<GKEClusterDetails>;
}
// @alpha (undocumented)
export class GoogleServiceAccountAuthTranslator
implements KubernetesAuthTranslator
{
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: GKEClusterDetails,
): Promise<GKEClusterDetails>;
}
// @alpha (undocumented)
export interface KubernetesAuthTranslator {
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: ClusterDetails,
authConfig: KubernetesRequestAuth,
): Promise<ClusterDetails>;
}
// @alpha (undocumented)
export class KubernetesAuthTranslatorGenerator {
// (undocumented)
static getKubernetesAuthTranslatorInstance(
authProvider: string,
options: {
logger: Logger;
},
): KubernetesAuthTranslator;
}
// @alpha (undocumented)
export class KubernetesBuilder {
constructor(env: KubernetesEnvironment);
@@ -152,6 +235,18 @@ export type KubernetesBuilderReturn = Promise<{
serviceLocator: KubernetesServiceLocator;
}>;
// @alpha (undocumented)
export class KubernetesClientProvider {
// (undocumented)
getCoreClientByClusterDetails(clusterDetails: ClusterDetails): CoreV1Api;
// (undocumented)
getCustomObjectsClient(clusterDetails: ClusterDetails): CustomObjectsApi;
// (undocumented)
getKubeConfig(clusterDetails: ClusterDetails): KubeConfig;
// (undocumented)
getMetricsClient(clusterDetails: ClusterDetails): Metrics;
}
// @alpha
export interface KubernetesClustersSupplier {
getClusters(): Promise<ClusterDetails[]>;
@@ -238,6 +333,14 @@ export interface KubernetesServiceLocator {
}>;
}
// @alpha (undocumented)
export class NoopKubernetesAuthTranslator implements KubernetesAuthTranslator {
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: ServiceAccountClusterDetails,
): Promise<ServiceAccountClusterDetails>;
}
// @alpha (undocumented)
export interface ObjectFetchParams {
// (undocumented)
@@ -273,6 +376,15 @@ export interface ObjectToFetch {
plural: string;
}
// @alpha (undocumented)
export class OidcKubernetesAuthTranslator implements KubernetesAuthTranslator {
// (undocumented)
decorateClusterDetailsWithAuth(
clusterDetails: ClusterDetails,
authConfig: KubernetesRequestAuth,
): Promise<ClusterDetails>;
}
// @alpha (undocumented)
export interface RouterOptions {
// (undocumented)
@@ -292,4 +404,11 @@ export interface ServiceAccountClusterDetails extends ClusterDetails {}
// @alpha (undocumented)
export type ServiceLocatorMethod = 'multiTenant' | 'http';
// @alpha (undocumented)
export type SigningCreds = {
accessKeyId: string | undefined;
secretAccessKey: string | undefined;
sessionToken: string | undefined;
};
```
+11
View File
@@ -20,8 +20,19 @@
* @packageDocumentation
*/
export * from './kubernetes-auth-translator/AwsIamKubernetesAuthTranslator';
export * from './kubernetes-auth-translator/AzureIdentityKubernetesAuthTranslator';
export * from './kubernetes-auth-translator/GoogleKubernetesAuthTranslator';
export * from './kubernetes-auth-translator/GoogleServiceAccountAuthProvider';
export * from './kubernetes-auth-translator/KubernetesAuthTranslatorGenerator';
export * from './kubernetes-auth-translator/NoopKubernetesAuthTranslator';
export * from './kubernetes-auth-translator/OidcKubernetesAuthTranslator';
export * from './kubernetes-auth-translator/types';
export * from './service/router';
export * from './service/KubernetesBuilder';
export * from './service/KubernetesClientProvider';
export * from './types/types';
export { DEFAULT_OBJECTS } from './service/KubernetesFanOutHandler';
@@ -18,12 +18,20 @@ import { sign } from 'aws4';
import { AWSClusterDetails } from '../types/types';
import { KubernetesAuthTranslator } from './types';
type SigningCreds = {
/**
*
* @alpha
*/
export type SigningCreds = {
accessKeyId: string | undefined;
secretAccessKey: string | undefined;
sessionToken: string | undefined;
};
/**
*
* @alpha
*/
export class AwsIamKubernetesAuthTranslator
implements KubernetesAuthTranslator
{
@@ -25,6 +25,10 @@ import {
const aksScope = '6dae42f8-4368-4678-94ff-3960e28e3630/.default'; // This scope is the same for all Azure Managed Kubernetes
/**
*
* @alpha
*/
export class AzureIdentityKubernetesAuthTranslator
implements KubernetesAuthTranslator
{
@@ -18,6 +18,10 @@ import { KubernetesAuthTranslator } from './types';
import { GKEClusterDetails } from '../types/types';
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
/**
*
* @alpha
*/
export class GoogleKubernetesAuthTranslator
implements KubernetesAuthTranslator
{
@@ -17,6 +17,10 @@ import { KubernetesAuthTranslator } from './types';
import { GKEClusterDetails } from '../types/types';
import * as container from '@google-cloud/container';
/**
*
* @alpha
*/
export class GoogleServiceAccountAuthTranslator
implements KubernetesAuthTranslator
{
@@ -23,6 +23,10 @@ import { GoogleServiceAccountAuthTranslator } from './GoogleServiceAccountAuthPr
import { AzureIdentityKubernetesAuthTranslator } from './AzureIdentityKubernetesAuthTranslator';
import { OidcKubernetesAuthTranslator } from './OidcKubernetesAuthTranslator';
/**
*
* @alpha
*/
export class KubernetesAuthTranslatorGenerator {
static getKubernetesAuthTranslatorInstance(
authProvider: string,
@@ -17,6 +17,10 @@
import { KubernetesAuthTranslator } from './types';
import { ServiceAccountClusterDetails } from '../types/types';
/**
*
* @alpha
*/
export class NoopKubernetesAuthTranslator implements KubernetesAuthTranslator {
async decorateClusterDetailsWithAuth(
clusterDetails: ServiceAccountClusterDetails,
@@ -18,6 +18,10 @@ import { KubernetesAuthTranslator } from './types';
import { ClusterDetails } from '../types/types';
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
/**
*
* @alpha
*/
export class OidcKubernetesAuthTranslator implements KubernetesAuthTranslator {
async decorateClusterDetailsWithAuth(
clusterDetails: ClusterDetails,
@@ -17,6 +17,10 @@
import { ClusterDetails } from '../types/types';
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
/**
*
* @alpha
*/
export interface KubernetesAuthTranslator {
decorateClusterDetailsWithAuth(
clusterDetails: ClusterDetails,
@@ -22,6 +22,10 @@ import {
} from '@kubernetes/client-node';
import { ClusterDetails } from '../types/types';
/**
*
* @alpha
*/
export class KubernetesClientProvider {
// visible for testing
getKubeConfig(clusterDetails: ClusterDetails) {