From 6a4c15fb59439356638f608a701efaad75a03f21 Mon Sep 17 00:00:00 2001 From: Jonah Back Date: Sun, 26 Jun 2022 13:18:53 -0700 Subject: [PATCH] address review comments Signed-off-by: Jonah Back --- .../catalog-model/src/entity/constants.ts | 23 +++++++++++++++++++ packages/catalog-model/src/entity/index.ts | 3 +++ .../src/processors/AwsEKSClusterProcessor.ts | 15 ++++++------ .../cluster-locator/CatalogClusterLocator.ts | 23 ++++++++----------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/packages/catalog-model/src/entity/constants.ts b/packages/catalog-model/src/entity/constants.ts index 5dc21683bd..ac9e813394 100644 --- a/packages/catalog-model/src/entity/constants.ts +++ b/packages/catalog-model/src/entity/constants.ts @@ -34,3 +34,26 @@ export const ANNOTATION_VIEW_URL = 'backstage.io/view-url'; * @public */ export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url'; + +/** + * Annotation for specifying the API server of a Kubernetes cluster + * + * @public + */ +export const ANNOTATION_KUBERNETES_API_SERVER = 'kubernetes.io/api-server'; + +/** + * Annotation for specifying the Certificate Authority of an API server for a Kubernetes cluster + * + * @public + */ +export const ANNOTATION_KUBERNETES_API_SERVER_CA = + 'kubernetes.io/api-server-certificate-authority'; + +/** + * Annotation for specifying the auth provider for a Kubernetes cluster + * + * @public + */ +export const ANNOTATION_KUBERNETES_AUTH_PROVIDER = + 'kubernetes.io/auth-provider'; diff --git a/packages/catalog-model/src/entity/index.ts b/packages/catalog-model/src/entity/index.ts index 45ee673167..7aa5424e5b 100644 --- a/packages/catalog-model/src/entity/index.ts +++ b/packages/catalog-model/src/entity/index.ts @@ -18,6 +18,9 @@ export { DEFAULT_NAMESPACE, ANNOTATION_EDIT_URL, ANNOTATION_VIEW_URL, + ANNOTATION_KUBERNETES_API_SERVER, + ANNOTATION_KUBERNETES_API_SERVER_CA, + ANNOTATION_KUBERNETES_AUTH_PROVIDER, } from './constants'; export type { AlphaEntity, diff --git a/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts b/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts index d74462693f..ca45b28f5d 100644 --- a/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts +++ b/plugins/catalog-backend-module-aws/src/processors/AwsEKSClusterProcessor.ts @@ -18,15 +18,16 @@ import { CatalogProcessorEmit, LocationSpec, } from '@backstage/plugin-catalog-backend'; +import { + ANNOTATION_KUBERNETES_API_SERVER, + ANNOTATION_KUBERNETES_API_SERVER_CA, + ANNOTATION_KUBERNETES_AUTH_PROVIDER, +} from '@backstage/catalog-model'; import { Credentials, EKS } from 'aws-sdk'; import { AWSCredentialFactory } from '../types'; const ACCOUNTID_ANNOTATION: string = 'amazonaws.com/account-id'; const ARN_ANNOTATION: string = 'amazonaws.com/arn'; -const KUBERNETES_API_SERVER_ANNOTATION = 'kubernetes.io/api-server'; -const KUBERNETES_API_SERVER_CA_ANNOTATION = - 'kubernetes.io/api-server-certificate-authority'; -const KUBERNETES_AUTH_METHOD_ANNOTATION = 'kubernetes.io/auth-provider'; export class AwsEKSClusterProcessor implements CatalogProcessor { private credentialsFactory?: AWSCredentialFactory; @@ -82,11 +83,11 @@ export class AwsEKSClusterProcessor implements CatalogProcessor { annotations: { [ACCOUNTID_ANNOTATION]: accountId, [ARN_ANNOTATION]: describedCluster.cluster.arn || '', - [KUBERNETES_API_SERVER_ANNOTATION]: + [ANNOTATION_KUBERNETES_API_SERVER]: describedCluster.cluster.endpoint || '', - [KUBERNETES_API_SERVER_CA_ANNOTATION]: + [ANNOTATION_KUBERNETES_API_SERVER_CA]: describedCluster.cluster.certificateAuthority?.data || '', - [KUBERNETES_AUTH_METHOD_ANNOTATION]: 'aws', + [ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'aws', }, name: this.normalizeName(describedCluster.cluster.name as string), namespace: 'default', diff --git a/plugins/kubernetes-backend/src/cluster-locator/CatalogClusterLocator.ts b/plugins/kubernetes-backend/src/cluster-locator/CatalogClusterLocator.ts index c762dc6fb6..124a53a72a 100644 --- a/plugins/kubernetes-backend/src/cluster-locator/CatalogClusterLocator.ts +++ b/plugins/kubernetes-backend/src/cluster-locator/CatalogClusterLocator.ts @@ -16,6 +16,11 @@ import { ClusterDetails, KubernetesClustersSupplier } from '../types/types'; import { CATALOG_FILTER_EXISTS, CatalogApi } from '@backstage/catalog-client'; +import { + ANNOTATION_KUBERNETES_API_SERVER, + ANNOTATION_KUBERNETES_API_SERVER_CA, + ANNOTATION_KUBERNETES_AUTH_PROVIDER, +} from '@backstage/catalog-model'; export class CatalogClusterLocator implements KubernetesClustersSupplier { private catalogClient: CatalogApi; @@ -31,16 +36,13 @@ export class CatalogClusterLocator implements KubernetesClustersSupplier { async getClusters(): Promise { const clusters = await this.catalogClient.getEntities({ filter: [ - { 'spec.type': 'kubernetes-cluster' }, { + kind: 'Resource', + 'spec.type': 'kubernetes-cluster', 'metadata.annotations.kubernetes.io/api-server': CATALOG_FILTER_EXISTS, - }, - { 'metadata.annotations.kubernetes.io/api-server-certificate-authority': CATALOG_FILTER_EXISTS, - }, - { 'metadata.annotations.kubernetes.io/auth-provider': CATALOG_FILTER_EXISTS, }, @@ -49,16 +51,11 @@ export class CatalogClusterLocator implements KubernetesClustersSupplier { return clusters.items.map(entity => { const clusterDetails: ClusterDetails = { name: entity.metadata.name, - // @ts-ignore filtered out by catalog-client query. - url: entity.metadata.annotations['kubernetes.io/api-server'], + url: entity.metadata.annotations![ANNOTATION_KUBERNETES_API_SERVER]!, caData: - // @ts-ignore filtered out by catalog-client query. - entity.metadata.annotations[ - 'kubernetes.io/api-server-certificate-authority' - ], + entity.metadata.annotations![ANNOTATION_KUBERNETES_API_SERVER_CA]!, authProvider: - // @ts-ignore filtered out by catalog-client query. - entity.metadata.annotations['kubernetes.io/auth-provider'], + entity.metadata.annotations![ANNOTATION_KUBERNETES_AUTH_PROVIDER]!, }; return clusterDetails;