mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Update CRD api to use preferred version and implement v1 differences (#718)
* Update CRD api to use preferred version and implement v1 differences Signed-off-by: Trevor Nichols <trevor@nichols.id.au> * Fix unit test failure Signed-off-by: Trevor Nichols <trevor@nichols.id.au> * Register alternate API base URL if preferred version changes. Signed-off-by: Trevor Nichols <trevor@nichols.id.au> * Adjust for validation moving to the version.schema Signed-off-by: Trevor Nichols <trevor@nichols.id.au>
This commit is contained in:
1 parent
38ba9cd383
commit
26e031fc58
6 files changed
+95
-31
No files matched your search
@@ -1,13 +1,28 @@
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { VersionedKubeApi } from "../kube-api-versioned";
|
||||
import { crdResourcesURL } from "../../components/+custom-resources/crd.route";
|
||||
|
||||
type AdditionalPrinterColumnsCommon = {
|
||||
name: string;
|
||||
type: "integer" | "number" | "string" | "boolean" | "date";
|
||||
priority: number;
|
||||
description: string;
|
||||
}
|
||||
|
||||
type AdditionalPrinterColumnsV1 = AdditionalPrinterColumnsCommon & {
|
||||
jsonPath: string;
|
||||
}
|
||||
|
||||
type AdditionalPrinterColumnsV1Beta = AdditionalPrinterColumnsCommon & {
|
||||
JSONPath: string;
|
||||
}
|
||||
|
||||
export class CustomResourceDefinition extends KubeObject {
|
||||
static kind = "CustomResourceDefinition";
|
||||
|
||||
spec: {
|
||||
group: string;
|
||||
version: string;
|
||||
version?: string; // deprecated in v1 api
|
||||
names: {
|
||||
plural: string;
|
||||
singular: string;
|
||||
@@ -20,18 +35,14 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
name: string;
|
||||
served: boolean;
|
||||
storage: boolean;
|
||||
schema?: unknown; // required in v1 but not present in v1beta
|
||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1[]
|
||||
}[];
|
||||
conversion: {
|
||||
strategy?: string;
|
||||
webhook?: any;
|
||||
};
|
||||
additionalPrinterColumns?: {
|
||||
name: string;
|
||||
type: "integer" | "number" | "string" | "boolean" | "date";
|
||||
priority: number;
|
||||
description: string;
|
||||
JSONPath: string;
|
||||
}[];
|
||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[]; // removed in v1
|
||||
}
|
||||
status: {
|
||||
conditions: {
|
||||
@@ -61,8 +72,8 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
}
|
||||
|
||||
getResourceApiBase() {
|
||||
const { version, group } = this.spec;
|
||||
return `/apis/${group}/${version}/${this.getPluralName()}`
|
||||
const { group } = this.spec;
|
||||
return `/apis/${group}/${this.getVersion()}/${this.getPluralName()}`
|
||||
}
|
||||
|
||||
getPluralName() {
|
||||
@@ -87,7 +98,8 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
return this.spec.version;
|
||||
// v1 has removed the spec.version property, if it is present it must match the first version
|
||||
return this.spec.versions[0]?.name ?? this.spec.version;
|
||||
}
|
||||
|
||||
isNamespaced() {
|
||||
@@ -107,14 +119,16 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
}
|
||||
|
||||
getPrinterColumns(ignorePriority = true) {
|
||||
const columns = this.spec.additionalPrinterColumns || [];
|
||||
const columns = this.spec.versions.find(a => this.getVersion() == a.name)?.additionalPrinterColumns
|
||||
?? this.spec.additionalPrinterColumns?.map(({JSONPath, ...rest}) => ({ ...rest, jsonPath: JSONPath })) // map to V1 shape
|
||||
?? [];
|
||||
return columns
|
||||
.filter(column => column.name != "Age")
|
||||
.filter(column => ignorePriority ? true : !column.priority);
|
||||
}
|
||||
|
||||
getValidation() {
|
||||
return JSON.stringify(this.spec.validation, null, 2);
|
||||
return JSON.stringify(this.spec.validation ?? this.spec.versions?.[0]?.schema, null, 2);
|
||||
}
|
||||
|
||||
getConditions() {
|
||||
@@ -130,16 +144,10 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const crdBetaApi = new KubeApi<CustomResourceDefinition>({
|
||||
kind: CustomResourceDefinition.kind,
|
||||
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
||||
isNamespaced: false,
|
||||
objectConstructor: CustomResourceDefinition,
|
||||
});
|
||||
|
||||
export const crdApi = new KubeApi<CustomResourceDefinition>({
|
||||
export const crdApi = new VersionedKubeApi<CustomResourceDefinition>({
|
||||
kind: CustomResourceDefinition.kind,
|
||||
apiBase: "/apis/apiextensions.k8s.io/v1/customresourcedefinitions",
|
||||
isNamespaced: false,
|
||||
objectConstructor: CustomResourceDefinition,
|
||||
objectConstructor: CustomResourceDefinition
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user