feat: initial port of EKS Cluster Processor and CatalogClusterLocator into upstream

Signed-off-by: Jonah Back <jonah@jonahback.com>
This commit is contained in:
Jonah Back
2022-06-01 20:06:59 -07:00
parent e15c24ddb5
commit 22c1fc0f6d
4 changed files with 202 additions and 0 deletions
@@ -0,0 +1,71 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ClusterDetails, KubernetesClustersSupplier } from '../types/types';
import {
CATALOG_FILTER_EXISTS,
CatalogClient,
} from '@backstage/catalog-client';
import { DiscoveryApi } from '@backstage/core-plugin-api';
export class CatalogClusterLocator implements KubernetesClustersSupplier {
private catalogClient: CatalogClient;
constructor(catalogClient: CatalogClient) {
this.catalogClient = catalogClient;
}
static fromConfig(discoveryApi: DiscoveryApi): CatalogClusterLocator {
return new CatalogClusterLocator(new CatalogClient({ discoveryApi }));
}
async getClusters(): Promise<ClusterDetails[]> {
const clusters = await this.catalogClient.getEntities({
filter: [
{ '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,
},
],
});
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'],
// @ts-ignore filtered out by catalog-client query.
caData:
entity.metadata.annotations[
'kubernetes.io/api-server-certificate-authority'
],
// @ts-ignore filtered out by catalog-client query.
authProvider:
entity.metadata.annotations['kubernetes.io/auth-provider'],
};
return clusterDetails;
});
}
}