Skip to content

Commit

Permalink
Merge pull request #2511 from headlamp-k8s/testClusterHealth-multi
Browse files Browse the repository at this point in the history
frontend: clusterApi: Fix testClusterHealth for multi cluster
  • Loading branch information
illume authored Nov 7, 2024
2 parents 7bff9a3 + a55f35d commit cb9ab6c
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 cb9ab6c

Please sign in to comment.