Skip to content

Commit

Permalink
Merge pull request #2419 from headlamp-k8s/clusters-field
Browse files Browse the repository at this point in the history
frontend: k8s/cluster: Add clusters field to ApiListOptions
  • Loading branch information
illume authored Oct 15, 2024
2 parents e9a831d + 3201723 commit 3ba84e0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions frontend/src/lib/k8s/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import helpers from '../../helpers';
import { createRouteURL } from '../router';
import { getCluster, timeAgo } from '../util';
import { useConnectApi } from '.';
import { useCluster } from './';
import { useKubeObject, useKubeObjectList } from './api/v2/hooks';
import { ApiError, apiFactory, apiFactoryWithNamespace, post, QueryParameters } from './apiProxy';
import CronJob from './cronJob';
Expand Down Expand Up @@ -237,9 +238,16 @@ export interface KubeOwnerReference {
}

export interface ApiListOptions extends QueryParameters {
/**
* The clusters to list objects from. By default uses the current clusters being viewed.
*/
clusters?: string[];
/** The namespace to list objects from. */
namespace?: string | string[];
/** The cluster to list objects from. By default uses the current cluster being viewed. */
/**
* The cluster to list objects from. By default uses the current cluster being viewed.
* If clusters is set, then we use that and "cluster" is ignored.
*/
cluster?: string;
}

Expand Down Expand Up @@ -547,7 +555,7 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(
let namespaces: string[] = [];
unset(queryParams, 'namespace');

const cluster = opts?.cluster;
const cluster = opts?.clusters?.[0] || opts?.cluster;

if (!!opts?.namespace) {
if (typeof opts.namespace === 'string') {
Expand Down Expand Up @@ -588,17 +596,15 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(

static useList<U extends KubeObjectClass>(
this: U,
{
cluster,
namespace,
...queryParams
}: { cluster?: string; namespace?: string } & QueryParameters = {}
{ cluster, namespace, clusters, ...queryParams }: ApiListOptions & QueryParameters = {}
) {
const currentCluster = useCluster();

return useKubeObjectList({
queryParams: queryParams,
kubeObjectClass: this,
cluster: cluster,
namespace: namespace,
cluster: clusters?.[0] || cluster || currentCluster || undefined,
namespace: Array.isArray(namespace) ? namespace[0] : namespace,
});
}

Expand Down

0 comments on commit 3ba84e0

Please sign in to comment.