mirror of
https://github.com/lensapp/lens.git
synced 2024-09-11 09:25:26 +03:00
fix: Remove incorrect KubeObject validations
- Default to using the ensured selfLink for ID if UID is not present Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
90c449cc0d
commit
18b89d9a85
@ -25,8 +25,8 @@ export interface KubeJsonApiData<
|
||||
Status = unknown,
|
||||
Spec = unknown,
|
||||
> {
|
||||
kind: string;
|
||||
apiVersion: string;
|
||||
readonly kind: string;
|
||||
readonly apiVersion: string;
|
||||
metadata: Metadata;
|
||||
status?: Status;
|
||||
spec?: Spec;
|
||||
@ -227,9 +227,6 @@ export type KubeJsonApiObjectMetadata<Namespaced extends KubeObjectScope = KubeO
|
||||
export type KubeObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> =
|
||||
KubeJsonApiObjectMetadata<Namespaced> & {
|
||||
readonly selfLink: string;
|
||||
readonly uid: string;
|
||||
readonly name: string;
|
||||
readonly resourceVersion: string;
|
||||
};
|
||||
|
||||
export type NamespaceScopedMetadata = KubeObjectMetadata<KubeObjectScope.Namespace>;
|
||||
|
116
packages/kube-object/src/kube-object.test.ts
Normal file
116
packages/kube-object/src/kube-object.test.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import { KubeObject } from "./kube-object";
|
||||
|
||||
describe("kube object tests", () => {
|
||||
it("should allow an object to be created when missing uid", () => {
|
||||
expect(
|
||||
() =>
|
||||
new KubeObject({
|
||||
apiVersion: "metrics.k8s.io/v1beta1",
|
||||
containers: [
|
||||
{
|
||||
name: "cert-manager",
|
||||
usage: {
|
||||
cpu: "472721n",
|
||||
memory: "74404Ki",
|
||||
},
|
||||
},
|
||||
],
|
||||
kind: "PodMetrics",
|
||||
metadata: {
|
||||
creationTimestamp: "2023-05-24T14:17:01Z",
|
||||
labels: {
|
||||
app: "cert-manager",
|
||||
"app.kubernetes.io/component": "controller",
|
||||
"app.kubernetes.io/instance": "cert-manager",
|
||||
"app.kubernetes.io/managed-by": "Helm",
|
||||
"app.kubernetes.io/name": "cert-manager",
|
||||
"app.kubernetes.io/version": "v1.5.5",
|
||||
"helm.sh/chart": "cert-manager-v1.5.5",
|
||||
"pod-template-hash": "54cbdfb45c",
|
||||
},
|
||||
name: "cert-manager-54cbdfb45c-n4kp9",
|
||||
namespace: "cert-manager",
|
||||
selfLink: "/apis/metrics.k8s.io/v1beta1/namespaces/cert-manager/pods/cert-manager-54cbdfb45c-n4kp9",
|
||||
resourceVersion: "123",
|
||||
},
|
||||
timestamp: "2023-05-24T14:16:39Z",
|
||||
window: "16s",
|
||||
}),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("should allow an object to be created when missing resourceVersion", () => {
|
||||
expect(
|
||||
() =>
|
||||
new KubeObject({
|
||||
apiVersion: "metrics.k8s.io/v1beta1",
|
||||
containers: [
|
||||
{
|
||||
name: "cert-manager",
|
||||
usage: {
|
||||
cpu: "472721n",
|
||||
memory: "74404Ki",
|
||||
},
|
||||
},
|
||||
],
|
||||
kind: "PodMetrics",
|
||||
metadata: {
|
||||
creationTimestamp: "2023-05-24T14:17:01Z",
|
||||
labels: {
|
||||
app: "cert-manager",
|
||||
"app.kubernetes.io/component": "controller",
|
||||
"app.kubernetes.io/instance": "cert-manager",
|
||||
"app.kubernetes.io/managed-by": "Helm",
|
||||
"app.kubernetes.io/name": "cert-manager",
|
||||
"app.kubernetes.io/version": "v1.5.5",
|
||||
"helm.sh/chart": "cert-manager-v1.5.5",
|
||||
"pod-template-hash": "54cbdfb45c",
|
||||
},
|
||||
name: "cert-manager-54cbdfb45c-n4kp9",
|
||||
namespace: "cert-manager",
|
||||
selfLink: "/apis/metrics.k8s.io/v1beta1/namespaces/cert-manager/pods/cert-manager-54cbdfb45c-n4kp9",
|
||||
uid: "123",
|
||||
},
|
||||
timestamp: "2023-05-24T14:16:39Z",
|
||||
window: "16s",
|
||||
}),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("should allow an object to be created when missing resourceVersion and uid", () => {
|
||||
expect(
|
||||
() =>
|
||||
new KubeObject({
|
||||
apiVersion: "metrics.k8s.io/v1beta1",
|
||||
containers: [
|
||||
{
|
||||
name: "cert-manager",
|
||||
usage: {
|
||||
cpu: "472721n",
|
||||
memory: "74404Ki",
|
||||
},
|
||||
},
|
||||
],
|
||||
kind: "PodMetrics",
|
||||
metadata: {
|
||||
creationTimestamp: "2023-05-24T14:17:01Z",
|
||||
labels: {
|
||||
app: "cert-manager",
|
||||
"app.kubernetes.io/component": "controller",
|
||||
"app.kubernetes.io/instance": "cert-manager",
|
||||
"app.kubernetes.io/managed-by": "Helm",
|
||||
"app.kubernetes.io/name": "cert-manager",
|
||||
"app.kubernetes.io/version": "v1.5.5",
|
||||
"helm.sh/chart": "cert-manager-v1.5.5",
|
||||
"pod-template-hash": "54cbdfb45c",
|
||||
},
|
||||
name: "cert-manager-54cbdfb45c-n4kp9",
|
||||
namespace: "cert-manager",
|
||||
selfLink: "/apis/metrics.k8s.io/v1beta1/namespaces/cert-manager/pods/cert-manager-54cbdfb45c-n4kp9",
|
||||
},
|
||||
timestamp: "2023-05-24T14:16:39Z",
|
||||
window: "16s",
|
||||
}),
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
@ -111,20 +111,6 @@ export class KubeObject<
|
||||
);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.uid)) {
|
||||
throw new KubeCreationError(
|
||||
`Cannot create a KubeObject from an object without metadata.uid being a string`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.resourceVersion)) {
|
||||
throw new KubeCreationError(
|
||||
`Cannot create a KubeObject from an object without metadata.resourceVersion being a string`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.selfLink)) {
|
||||
throw new KubeCreationError(
|
||||
`Cannot create a KubeObject from an object without metadata.selfLink being a string`,
|
||||
@ -136,23 +122,23 @@ export class KubeObject<
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
get selfLink() {
|
||||
get selfLink(): string {
|
||||
return this.metadata.selfLink;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.metadata.uid;
|
||||
getId(): string {
|
||||
return this.metadata.uid ?? this.metadata.selfLink;
|
||||
}
|
||||
|
||||
getResourceVersion() {
|
||||
return this.metadata.resourceVersion;
|
||||
getResourceVersion(): string {
|
||||
return this.metadata.resourceVersion ?? "";
|
||||
}
|
||||
|
||||
getScopedName() {
|
||||
return [this.getNs(), this.getName()].filter(Boolean).join("/");
|
||||
}
|
||||
|
||||
getName() {
|
||||
getName(): string {
|
||||
return this.metadata.name;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user