Skip to content

Commit e6f3d26

Browse files
committed
frontend: Fix wrong apiVersion used when CRUDing a CustomResource
Signed-off-by: Damien Dassieu <[email protected]>
1 parent 47c10d4 commit e6f3d26

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

frontend/src/lib/k8s/KubeObject.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type { QueryParameters } from './api/v1/queryParameters';
3131
import type { ApiError } from './api/v2/ApiError';
3232
import { useKubeObject } from './api/v2/hooks';
3333
import { makeListRequests, useKubeObjectList } from './api/v2/useKubeObjectList';
34+
import type CustomResourceDefinition from './crd';
3435
import type { KubeEvent } from './event';
3536
import type { KubeMetadata, KubeMetadataCreate } from './KubeMetadata';
3637

frontend/src/lib/k8s/crd.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class CustomResourceDefinition extends KubeObject<KubeCRD> {
103103
for (const versionItem of this.spec.versions) {
104104
if (!!versionItem.storage) {
105105
version = versionItem.name;
106+
break;
106107
} else if (!version) {
107108
version = versionItem.name;
108109
}
@@ -190,6 +191,22 @@ export function makeCustomResourceClass(
190191
static isNamespaced = objArgs.isNamespaced;
191192
static apiEndpoint = apiFunc(...apiInfoArgs);
192193
static customResourceDefinition = crClassArgs.customResourceDefinition;
194+
195+
static getBaseObject(): Omit<KubeObjectInterface, 'metadata'> & {
196+
metadata: Partial<import('./KubeMetadata').KubeMetadata>;
197+
} {
198+
// For custom resources, use the storage version from the CRD
199+
const [group, version] = crClassArgs.customResourceDefinition.getMainAPIGroup();
200+
const apiVersion = group ? `${group}/${version}` : version;
201+
202+
return {
203+
apiVersion,
204+
kind: this.kind,
205+
metadata: {
206+
name: '',
207+
},
208+
};
209+
}
193210
};
194211
}
195212

0 commit comments

Comments
 (0)