mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix crash when finding CRD's preferred version (#4332)
This commit is contained in:
parent
4c83f5becf
commit
e51ff5051f
@ -51,7 +51,7 @@ describe("Crds", () => {
|
|||||||
expect(() => crd.getVersion()).toThrowError("Failed to find a version for CustomResourceDefinition foo");
|
expect(() => crd.getVersion()).toThrowError("Failed to find a version for CustomResourceDefinition foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should should get the version that is both served and stored", () => {
|
it("should get the version that is both served and stored", () => {
|
||||||
const crd = new CustomResourceDefinition({
|
const crd = new CustomResourceDefinition({
|
||||||
apiVersion: "apiextensions.k8s.io/v1",
|
apiVersion: "apiextensions.k8s.io/v1",
|
||||||
kind: "CustomResourceDefinition",
|
kind: "CustomResourceDefinition",
|
||||||
@ -79,7 +79,35 @@ describe("Crds", () => {
|
|||||||
expect(crd.getVersion()).toBe("123");
|
expect(crd.getVersion()).toBe("123");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should should get the version that is both served and stored even with version field", () => {
|
it("should get the version that is only stored", () => {
|
||||||
|
const crd = new CustomResourceDefinition({
|
||||||
|
apiVersion: "apiextensions.k8s.io/v1",
|
||||||
|
kind: "CustomResourceDefinition",
|
||||||
|
metadata: {
|
||||||
|
name: "foo",
|
||||||
|
resourceVersion: "12345",
|
||||||
|
uid: "12345",
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
versions: [
|
||||||
|
{
|
||||||
|
name: "123",
|
||||||
|
served: false,
|
||||||
|
storage: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "1234",
|
||||||
|
served: false,
|
||||||
|
storage: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(crd.getVersion()).toBe("123");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should get the version that is both served and stored even with version field", () => {
|
||||||
const crd = new CustomResourceDefinition({
|
const crd = new CustomResourceDefinition({
|
||||||
apiVersion: "apiextensions.k8s.io/v1",
|
apiVersion: "apiextensions.k8s.io/v1",
|
||||||
kind: "CustomResourceDefinition",
|
kind: "CustomResourceDefinition",
|
||||||
|
|||||||
@ -153,11 +153,7 @@ export class CustomResourceDefinition extends KubeObject {
|
|||||||
// Prefer the modern `versions` over the legacy `version`
|
// Prefer the modern `versions` over the legacy `version`
|
||||||
if (this.spec.versions) {
|
if (this.spec.versions) {
|
||||||
for (const version of this.spec.versions) {
|
for (const version of this.spec.versions) {
|
||||||
/**
|
if (version.storage) {
|
||||||
* If the version is not served then 404 errors will occur
|
|
||||||
* We should also prefer the storage version
|
|
||||||
*/
|
|
||||||
if (version.served && version.storage) {
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,6 +78,17 @@ export class CrdResources extends React.Component<Props> {
|
|||||||
sortingCallbacks[column.name] = item => jsonPath.value(item, parseJsonPath(column.jsonPath.slice(1)));
|
sortingCallbacks[column.name] = item => jsonPath.value(item, parseJsonPath(column.jsonPath.slice(1)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const version = crd.getPreferedVersion();
|
||||||
|
const loadFailedPrefix = <p>Failed to load {crd.getPluralName()}</p>;
|
||||||
|
const failedToLoadMessage = version.served
|
||||||
|
? loadFailedPrefix
|
||||||
|
: (
|
||||||
|
<>
|
||||||
|
{loadFailedPrefix}
|
||||||
|
<p>Prefered version ({crd.getGroup()}/{version.name}) is not served</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KubeObjectListLayout
|
<KubeObjectListLayout
|
||||||
isConfigurable
|
isConfigurable
|
||||||
@ -129,6 +140,7 @@ export class CrdResources extends React.Component<Props> {
|
|||||||
}),
|
}),
|
||||||
crdInstance.getAge(),
|
crdInstance.getAge(),
|
||||||
]}
|
]}
|
||||||
|
failedToLoadMessage={failedToLoadMessage}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -98,6 +98,13 @@ export interface ItemListLayoutProps<I extends ItemObject> {
|
|||||||
customizeRemoveDialog?: (selectedItems: I[]) => Partial<ConfirmDialogParams>;
|
customizeRemoveDialog?: (selectedItems: I[]) => Partial<ConfirmDialogParams>;
|
||||||
renderFooter?: (parent: ItemListLayout<I>) => React.ReactNode;
|
renderFooter?: (parent: ItemListLayout<I>) => React.ReactNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message to display when a store failed to load
|
||||||
|
*
|
||||||
|
* @default "Failed to load items"
|
||||||
|
*/
|
||||||
|
failedToLoadMessage?: React.ReactNode;
|
||||||
|
|
||||||
filterCallbacks?: ItemsFilters<I>;
|
filterCallbacks?: ItemsFilters<I>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +121,8 @@ const defaultProps: Partial<ItemListLayoutProps<ItemObject>> = {
|
|||||||
hasDetailsView: true,
|
hasDetailsView: true,
|
||||||
onDetails: noop,
|
onDetails: noop,
|
||||||
virtual: true,
|
virtual: true,
|
||||||
customizeTableRowProps: () => ({} as TableRowProps),
|
customizeTableRowProps: () => ({}),
|
||||||
|
failedToLoadMessage: "Failed to load items",
|
||||||
};
|
};
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -322,7 +330,7 @@ export class ItemListLayout<I extends ItemObject> extends React.Component<ItemLi
|
|||||||
|
|
||||||
renderNoItems() {
|
renderNoItems() {
|
||||||
if (this.failedToLoad) {
|
if (this.failedToLoad) {
|
||||||
return <NoItems>Failed to load items.</NoItems>;
|
return <NoItems>{this.props.failedToLoadMessage}</NoItems>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isReady) {
|
if (!this.isReady) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user