Skip to content

Commit

Permalink
frontend: Do not use isNamespaced for adding namespace to API calls
Browse files Browse the repository at this point in the history
This isNamespaced will not work in the case of CRDs for example.

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
  • Loading branch information
joaquimrocha committed May 27, 2024
1 parent 93053fb commit 16b8f7a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frontend/src/lib/k8s/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(

const args: any[] = [(list: T[]) => onList(list.map((item: T) => createInstance(item) as U))];

if (this.apiEndpoint.isNamespaced) {
const namespace = opts?.namespace;
if (!!namespace) {
args.unshift(opts?.namespace || null);
}

Expand Down Expand Up @@ -585,7 +586,7 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(
const createInstance = (item: T) => this.create(item) as U;
const args: any[] = [name, (obj: T) => onGet(createInstance(obj))];

if (this.apiEndpoint.isNamespaced) {
if (!!namespace) {
args.unshift(namespace);
}

Expand Down Expand Up @@ -659,8 +660,9 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(

delete() {
const args: string[] = [this.getName()];
if (this.isNamespaced) {
args.unshift(this.getNamespace()!);
const namespace = this.getNamespace();
if (!!namespace) {
args.unshift(namespace);
}

return this._class().apiEndpoint.delete(...args, {}, this._clusterName);
Expand Down Expand Up @@ -706,8 +708,9 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(
const patchMethod = this._class().apiEndpoint.patch;
const args: Parameters<typeof patchMethod> = [body];

if (this.isNamespaced) {
args.push(this.getNamespace());
const namespace = this.getNamespace();
if (!!namespace) {
args.push(namespace);
}

args.push(this.getName());
Expand Down

0 comments on commit 16b8f7a

Please sign in to comment.