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:
1 parent
4c83f5becf
commit
e51ff5051f
4 files changed
+53
-9
No files matched your search
@@ -51,7 +51,7 @@ describe("Crds", () => {
|
||||
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({
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
@@ -79,7 +79,35 @@ describe("Crds", () => {
|
||||
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({
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
|
||||
@@ -153,11 +153,7 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
// Prefer the modern `versions` over the legacy `version`
|
||||
if (this.spec.versions) {
|
||||
for (const version of this.spec.versions) {
|
||||
/**
|
||||
* If the version is not served then 404 errors will occur
|
||||
* We should also prefer the storage version
|
||||
*/
|
||||
if (version.served && version.storage) {
|
||||
if (version.storage) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user