From 2a50cbf40558e508a8abce025e8b95f096bf11a2 Mon Sep 17 00:00:00 2001 From: armandocomellas1 Date: Tue, 30 Jan 2024 20:37:18 -0600 Subject: [PATCH] Add key and values to the GkeClusterLocator.ts script and add an unit test to check if those are there Signed-off-by: armandocomellas1 --- .changeset/mighty-tomatoes-visit.md | 5 +++++ .../cluster-locator/GkeClusterLocator.test.ts | 19 +++++++++++++++++++ .../src/cluster-locator/GkeClusterLocator.ts | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/mighty-tomatoes-visit.md diff --git a/.changeset/mighty-tomatoes-visit.md b/.changeset/mighty-tomatoes-visit.md new file mode 100644 index 0000000000..08e443d932 --- /dev/null +++ b/.changeset/mighty-tomatoes-visit.md @@ -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` diff --git a/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.test.ts b/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.test.ts index 849a7839e2..ba46e03ae2 100644 --- a/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.test.ts +++ b/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.test.ts @@ -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); + }); }); }); diff --git a/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.ts b/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.ts index 03f5bda103..33b9ee74b9 100644 --- a/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.ts +++ b/plugins/kubernetes-backend/src/cluster-locator/GkeClusterLocator.ts @@ -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, ); }