From a81b1ba7dda2871a07d8ea3ca296c533107f4edc Mon Sep 17 00:00:00 2001 From: Jamie Klassen Date: Fri, 19 Jan 2024 15:25:20 -0500 Subject: [PATCH] update default EKS cluster entity transformer This change has no functional effect, but it seems like a helpful illustration for adopters embarking on writing the first EKS cluster entity transformer of their own. Signed-off-by: Jamie Klassen --- .changeset/dull-dolphins-explain.md | 6 ++++++ .../src/lib/defaultTransformers.ts | 5 ++++- .../src/processors/AwsEKSClusterProcessor.test.ts | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/dull-dolphins-explain.md diff --git a/.changeset/dull-dolphins-explain.md b/.changeset/dull-dolphins-explain.md new file mode 100644 index 0000000000..d8864e72e8 --- /dev/null +++ b/.changeset/dull-dolphins-explain.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-backend-module-aws': patch +--- + +The default EKS cluster entity transformer now sets the new +`kubernetes.io/x-k8s-aws-id` annotation. diff --git a/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts b/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts index 9de79e9811..07862bb298 100644 --- a/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts +++ b/plugins/catalog-backend-module-aws/src/lib/defaultTransformers.ts @@ -18,6 +18,7 @@ import { ANNOTATION_KUBERNETES_API_SERVER, ANNOTATION_KUBERNETES_API_SERVER_CA, ANNOTATION_KUBERNETES_AUTH_PROVIDER, + ANNOTATION_KUBERNETES_AWS_CLUSTER_ID, } from '@backstage/plugin-kubernetes-common'; import type { EksClusterEntityTransformer } from '../processors/types'; import { ANNOTATION_AWS_ACCOUNT_ID, ANNOTATION_AWS_ARN } from '../constants'; @@ -29,6 +30,7 @@ import { ANNOTATION_AWS_ACCOUNT_ID, ANNOTATION_AWS_ARN } from '../constants'; export const defaultEksClusterEntityTransformer: EksClusterEntityTransformer = async (cluster: Cluster, accountId: string) => { const { arn, endpoint, certificateAuthority, name } = cluster; + const normalizedName = normalizeName(name as string); return { apiVersion: 'backstage.io/v1alpha1', kind: 'Resource', @@ -40,8 +42,9 @@ export const defaultEksClusterEntityTransformer: EksClusterEntityTransformer = [ANNOTATION_KUBERNETES_API_SERVER_CA]: certificateAuthority?.data || '', [ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'aws', + [ANNOTATION_KUBERNETES_AWS_CLUSTER_ID]: normalizedName, }, - name: normalizeName(name as string), + name: normalizedName, namespace: 'default', }, spec: { diff --git a/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.test.ts b/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.test.ts index 6cec6ed66d..a07f775fb9 100644 --- a/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.test.ts +++ b/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.test.ts @@ -67,6 +67,7 @@ describe('AwsEKSClusterProcessor', () => { 'kubernetes.io/api-server-certificate-authority': cluster.cluster?.certificateAuthority?.data, 'kubernetes.io/auth-provider': 'aws', + 'kubernetes.io/x-k8s-aws-id': 'backstage-test', }, name: 'backstage-test', namespace: 'default',