mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Catch metadata being undefined at KubeObject creation
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4af796c532
commit
f3e32eaf70
@ -98,6 +98,12 @@ export interface KubeObjectStatus {
|
|||||||
|
|
||||||
export type KubeMetaField = keyof KubeObjectMetadata;
|
export type KubeMetaField = keyof KubeObjectMetadata;
|
||||||
|
|
||||||
|
export class KubeCreationError extends Error {
|
||||||
|
constructor(message: string, public data: any) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class KubeObject<Metadata extends KubeObjectMetadata = KubeObjectMetadata, Status = any, Spec = any> implements ItemObject {
|
export class KubeObject<Metadata extends KubeObjectMetadata = KubeObjectMetadata, Status = any, Spec = any> implements ItemObject {
|
||||||
static readonly kind: string;
|
static readonly kind: string;
|
||||||
static readonly namespaced: boolean;
|
static readonly namespaced: boolean;
|
||||||
@ -213,6 +219,10 @@ export class KubeObject<Metadata extends KubeObjectMetadata = KubeObjectMetadata
|
|||||||
throw new TypeError(`Cannot create a KubeObject from ${typeof data}`);
|
throw new TypeError(`Cannot create a KubeObject from ${typeof data}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!data.metadata || typeof data.metadata !== "object") {
|
||||||
|
throw new KubeCreationError(`Cannot create a KubeObject from an object without metadata`, data);
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(this, data);
|
Object.assign(this, data);
|
||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
@ -274,7 +284,7 @@ export class KubeObject<Metadata extends KubeObjectMetadata = KubeObjectMetadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
getOwnerRefs() {
|
getOwnerRefs() {
|
||||||
const refs = this.metadata?.ownerReferences || [];
|
const refs = this.metadata.ownerReferences || [];
|
||||||
const namespace = this.getNs();
|
const namespace = this.getNs();
|
||||||
|
|
||||||
return refs.map(ownerRef => ({ ...ownerRef, namespace }));
|
return refs.map(ownerRef => ({ ...ownerRef, namespace }));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user