ClusterLocator now takes CRD defined at the cluster level and returns in clusterDetails

Signed-off-by: Ruben Vallejo <rvallejo@vmware.com>
This commit is contained in:
Ruben Vallejo
2023-06-07 10:39:17 -04:00
parent 258556062b
commit 8d663f143c
2 changed files with 56 additions and 0 deletions
@@ -271,4 +271,47 @@ describe('ConfigClusterLocator', () => {
expect(result).toMatchObject([cluster]);
});
it('has cluster level defined customResources returns clusterDetails with those CRDs', async () => {
const config: Config = new ConfigReader({
clusters: [
{
name: 'cluster1',
url: 'http://localhost:8080',
authProvider: 'serviceAccount',
customResources: [
{
group: 'argoproj.io',
apiVersion: 'v1alpha1',
plural: 'rollouts',
},
],
},
],
});
const sut = ConfigClusterLocator.fromConfig(config);
const result = await sut.getClusters();
expect(result).toStrictEqual([
{
name: 'cluster1',
serviceAccountToken: undefined,
url: 'http://localhost:8080',
authProvider: 'serviceAccount',
skipMetricsLookup: false,
skipTLSVerify: false,
caData: undefined,
caFile: undefined,
customResources: [
{
group: 'argoproj.io',
apiVersion: 'v1alpha1',
plural: 'rollouts',
},
],
},
]);
});
});
@@ -16,6 +16,7 @@
import { Config } from '@backstage/config';
import { ClusterDetails, KubernetesClustersSupplier } from '../types/types';
import { CustomResourceMatcher } from '@backstage/plugin-kubernetes-common';
export class ConfigClusterLocator implements KubernetesClustersSupplier {
private readonly clusterDetails: ClusterDetails[];
@@ -40,6 +41,18 @@ export class ConfigClusterLocator implements KubernetesClustersSupplier {
caFile: c.getOptionalString('caFile'),
authProvider: authProvider,
};
const customResources = c.getOptionalConfigArray('customResources');
if (customResources) {
clusterDetails.customResources = customResources.map(cr => {
return {
group: cr.getString('group'),
apiVersion: cr.getString('apiVersion'),
plural: cr.getString('plural'),
};
});
}
const dashboardUrl = c.getOptionalString('dashboardUrl');
if (dashboardUrl) {
clusterDetails.dashboardUrl = dashboardUrl;