From 9745ccf7d30bb8154ee30e9a170a6cb735b0c8a4 Mon Sep 17 00:00:00 2001 From: Sabrina Lo Date: Tue, 12 Sep 2023 15:31:01 -0700 Subject: [PATCH] chore: address PR comments about Updating new EKS name to eks and make the AwsEKSClusterProcessor constructor parameter nonoptional Signed-off-by: Sabrina Lo --- .../catalog-backend-module-aws/api-report.md | 8 ++-- .../src/lib/defaultTransformers.ts | 47 +++++++++---------- .../src/processors/AwsEKSClusterProcessor.ts | 18 +++---- .../src/processors/types.ts | 4 +- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/plugins/catalog-backend-module-aws/api-report.md b/plugins/catalog-backend-module-aws/api-report.md index 5fa59d417f..a7a3f6816a 100644 --- a/plugins/catalog-backend-module-aws/api-report.md +++ b/plugins/catalog-backend-module-aws/api-report.md @@ -32,16 +32,16 @@ export type AWSCredentialFactory = ( // @public export class AwsEKSClusterProcessor implements CatalogProcessor { - constructor(options?: { + constructor(options: { credentialsFactory?: AWSCredentialFactory; credentialsManager?: AwsCredentialsManager; - clusterEntityTransformer?: EKSClusterEntityTransformer; + clusterEntityTransformer?: EksClusterEntityTransformer; }); // (undocumented) static fromConfig( configRoot: Config, options?: { - clusterEntityTransformer?: EKSClusterEntityTransformer; + clusterEntityTransformer?: EksClusterEntityTransformer; }, ): AwsEKSClusterProcessor; // (undocumented) @@ -107,7 +107,7 @@ export class AwsS3EntityProvider implements EntityProvider { } // @public -export type EKSClusterEntityTransformer = ( +export type EksClusterEntityTransformer = ( cluster: Cluster, accountId: string, ) => Promise; diff --git a/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts b/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts index 9d1fef8ca8..9de79e9811 100644 --- a/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts +++ b/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts @@ -13,44 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { EKSClusterEntityTransformer } from '../processors/types'; import { type Cluster } from '@aws-sdk/client-eks'; import { ANNOTATION_KUBERNETES_API_SERVER, ANNOTATION_KUBERNETES_API_SERVER_CA, ANNOTATION_KUBERNETES_AUTH_PROVIDER, } from '@backstage/plugin-kubernetes-common'; +import type { EksClusterEntityTransformer } from '../processors/types'; import { ANNOTATION_AWS_ACCOUNT_ID, ANNOTATION_AWS_ARN } from '../constants'; /** * Default transformer for EKS Cluster to Resource Entity * @public */ -export const defaultEKSClusterTransformer: EKSClusterEntityTransformer = async ( - cluster: Cluster, - accountId: string, -) => { - const { arn, endpoint, certificateAuthority, name } = cluster; - return { - apiVersion: 'backstage.io/v1alpha1', - kind: 'Resource', - metadata: { - annotations: { - [ANNOTATION_AWS_ACCOUNT_ID]: accountId, - [ANNOTATION_AWS_ARN]: arn || '', - [ANNOTATION_KUBERNETES_API_SERVER]: endpoint || '', - [ANNOTATION_KUBERNETES_API_SERVER_CA]: certificateAuthority?.data || '', - [ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'aws', +export const defaultEksClusterEntityTransformer: EksClusterEntityTransformer = + async (cluster: Cluster, accountId: string) => { + const { arn, endpoint, certificateAuthority, name } = cluster; + return { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Resource', + metadata: { + annotations: { + [ANNOTATION_AWS_ACCOUNT_ID]: accountId, + [ANNOTATION_AWS_ARN]: arn || '', + [ANNOTATION_KUBERNETES_API_SERVER]: endpoint || '', + [ANNOTATION_KUBERNETES_API_SERVER_CA]: + certificateAuthority?.data || '', + [ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'aws', + }, + name: normalizeName(name as string), + namespace: 'default', }, - name: normalizeName(name as string), - namespace: 'default', - }, - spec: { - type: 'kubernetes-cluster', - owner: 'unknown', - }, + spec: { + type: 'kubernetes-cluster', + owner: 'unknown', + }, + }; }; -}; function normalizeName(name: string): string { return name diff --git a/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts b/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts index b7d5f620d0..a491dbab7d 100644 --- a/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts +++ b/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts @@ -28,8 +28,8 @@ import { } from '@backstage/integration-aws-node'; import { Config } from '@backstage/config'; -import type { EKSClusterEntityTransformer } from './types'; -import { defaultEKSClusterTransformer } from '../lib'; +import type { EksClusterEntityTransformer } from './types'; +import { defaultEksClusterEntityTransformer } from '../lib'; /** * A processor for automatic discovery of resources from EKS clusters. Handles the @@ -41,12 +41,12 @@ import { defaultEKSClusterTransformer } from '../lib'; export class AwsEKSClusterProcessor implements CatalogProcessor { private credentialsFactory?: AWSCredentialFactory; private credentialsManager?: AwsCredentialsManager; - private readonly clusterEntityTransformer: EKSClusterEntityTransformer; + private readonly clusterEntityTransformer: EksClusterEntityTransformer; static fromConfig( configRoot: Config, options?: { - clusterEntityTransformer?: EKSClusterEntityTransformer; + clusterEntityTransformer?: EksClusterEntityTransformer; }, ): AwsEKSClusterProcessor { const awsCredentaislManager = @@ -57,17 +57,17 @@ export class AwsEKSClusterProcessor implements CatalogProcessor { }); } - constructor(options?: { + constructor(options: { credentialsFactory?: AWSCredentialFactory; credentialsManager?: AwsCredentialsManager; - clusterEntityTransformer?: EKSClusterEntityTransformer; + clusterEntityTransformer?: EksClusterEntityTransformer; }) { - this.credentialsFactory = options?.credentialsFactory; - this.credentialsManager = options?.credentialsManager; + this.credentialsFactory = options.credentialsFactory; + this.credentialsManager = options.credentialsManager; // If the callback function is not passed in, then default to the one upstream is using this.clusterEntityTransformer = - options?.clusterEntityTransformer || defaultEKSClusterTransformer; + options.clusterEntityTransformer || defaultEksClusterEntityTransformer; } getProcessorName(): string { diff --git a/plugins/catalog-backend-module-aws/src/processors/types.ts b/plugins/catalog-backend-module-aws/src/processors/types.ts index f8c3b05efe..22e9e4982d 100644 --- a/plugins/catalog-backend-module-aws/src/processors/types.ts +++ b/plugins/catalog-backend-module-aws/src/processors/types.ts @@ -17,11 +17,11 @@ import type { Cluster } from '@aws-sdk/client-eks'; import type { Entity } from '@backstage/catalog-model'; /** - * Options for the eks cluster entity callback function + * Options for the EKS cluster entity callback function * * @public */ -export type EKSClusterEntityTransformer = ( +export type EksClusterEntityTransformer = ( cluster: Cluster, accountId: string, ) => Promise;