Skip to content

Commit

Permalink
frontend: clusterApi: Fix testClusterHealth for multi cluster
Browse files Browse the repository at this point in the history
Also fix test so it follows docs, and how the code is used.
All it cares about is if it raises an error when there is an
error condition.

Signed-off-by: René Dudfield <renedudfield@microsoft.com>
  • Loading branch information
illume committed Nov 3, 2024
1 parent 2596766 commit a55f35d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 2 additions & 4 deletions frontend/src/lib/k8s/api/v1/apiProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,8 @@ describe('apiProxy', () => {
nock.cleanAll();
});

it('Successfully checks cluster health', async () => {
const response = await apiProxy.testClusterHealth(clusterName);
const body = await response.text();
expect(body).toEqual('ok');
it('Should not raise an error on success', async () => {
await apiProxy.testClusterHealth(clusterName);
});

it.each([
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/lib/k8s/api/v1/clusterApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
findKubeconfigByClusterName,
storeStatelessClusterKubeconfig,
} from '../../../../stateless';
import { getCluster } from '../../../util';
import { getCluster, getClusterGroup } from '../../../util';
import { ClusterRequest, clusterRequest, post, request } from './clusterRequests';
import { JSON_HEADERS } from './constants';

Expand All @@ -29,8 +29,15 @@ export async function testAuth(cluster = '', namespace = 'default') {
* Will throw an error if the cluster is not healthy.
*/
export async function testClusterHealth(cluster?: string) {
const clusterName = cluster || getCluster() || '';
return clusterRequest('/healthz', { isJSON: false, cluster: clusterName });
const clusterNames = cluster ? [cluster] : getClusterGroup();

const healthChecks = clusterNames.map(clusterName => {
return clusterRequest('/healthz', { isJSON: false, cluster: clusterName }).catch(error => {
throw new Error(`Cluster ${clusterName} is not healthy: ${error.message}`);
});
});

return Promise.all(healthChecks);
}

export async function setCluster(clusterReq: ClusterRequest) {
Expand Down

0 comments on commit a55f35d

Please sign in to comment.