Add key and values to the GkeClusterLocator.ts script and add an unit test to check if those are there
Signed-off-by: armandocomellas1 <cgarmando@google.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': minor
|
||||
---
|
||||
|
||||
At Line 91, in the second parameter enter a value for the property libName and libVersion to post headers to the key `x-goog-api-client`
|
||||
@@ -18,6 +18,7 @@ import { ANNOTATION_KUBERNETES_AUTH_PROVIDER } from '@backstage/plugin-kubernete
|
||||
import '@backstage/backend-common';
|
||||
import { ConfigReader, Config } from '@backstage/config';
|
||||
import { GkeClusterLocator } from './GkeClusterLocator';
|
||||
import { Duration } from 'luxon';
|
||||
|
||||
const mockedListClusters = jest.fn();
|
||||
|
||||
@@ -485,5 +486,23 @@ describe('GkeClusterLocator', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('Check if new container.v1.ClusterManagerClient has key and values as parameter', async () => {
|
||||
const configs: Config = new ConfigReader({
|
||||
type: 'gke',
|
||||
projectId: 'some-project',
|
||||
});
|
||||
|
||||
const refreshIntervals: Duration | undefined = undefined;
|
||||
const getHeaders: GkeClusterLocator = GkeClusterLocator.fromConfig(
|
||||
configs,
|
||||
refreshIntervals,
|
||||
);
|
||||
const getKeyName = getHeaders.client._opts.hasOwnProperty(['libName']);
|
||||
const getKeyVersion = getHeaders.client._opts.hasOwnProperty([
|
||||
'libVersion',
|
||||
]);
|
||||
expect(getKeyName).toBe(true);
|
||||
expect(getKeyVersion).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,6 +21,7 @@ import * as container from '@google-cloud/container';
|
||||
import { Duration } from 'luxon';
|
||||
import { runPeriodically } from '../service/runPeriodically';
|
||||
import { ClusterDetails, KubernetesClustersSupplier } from '../types/types';
|
||||
import packageinfo from '../../package.json';
|
||||
|
||||
interface MatchResourceLabelEntry {
|
||||
key: string;
|
||||
@@ -80,13 +81,17 @@ export class GkeClusterLocator implements KubernetesClustersSupplier {
|
||||
return gkeClusterLocator;
|
||||
}
|
||||
|
||||
// At Line 91, in the second parameter enter a value for the property libName and libVersion to post headers to the key 'x-goog-api-client'
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
refreshInterval: Duration | undefined = undefined,
|
||||
): GkeClusterLocator {
|
||||
return GkeClusterLocator.fromConfigWithClient(
|
||||
config,
|
||||
new container.v1.ClusterManagerClient(),
|
||||
new container.v1.ClusterManagerClient({
|
||||
libName: 'backstage/gke',
|
||||
libVersion: packageinfo.version,
|
||||
}),
|
||||
refreshInterval,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user