chore: address PR comments about Updating new EKS name to eks and make the AwsEKSClusterProcessor constructor parameter nonoptional

Signed-off-by: Sabrina Lo <sabrina.lo@segment.com>
This commit is contained in:
Sabrina Lo
2023-09-12 15:31:01 -07:00
parent 3d1b747edb
commit 9745ccf7d3
4 changed files with 38 additions and 39 deletions
@@ -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<Entity>;
@@ -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
@@ -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 {
@@ -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<Entity>;