address review comments

Signed-off-by: Jonah Back <jonah@jonahback.com>
This commit is contained in:
Jonah Back
2022-06-26 13:18:53 -07:00
parent c8764b7fd7
commit 6a4c15fb59
4 changed files with 44 additions and 20 deletions
@@ -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';
@@ -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,
@@ -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',
@@ -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<ClusterDetails[]> {
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;