1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Reverted "use {useDefineForClassFields: true} in tsconfig.json" (various app-crash fixes)

This flag seems to be not possible to use with class-inheritance in some cases.

Example / demo:
`KubeObject` class has initial type definitions for the fields like: "metadata", "kind", etc.
and constructor() has Object.assign(this, data);
Meanwhile child class, e.g. KubeEvent inherited from KubeObject and has it's own extra type definitions for underlying resource, e.g. "involvedObject", "source", etc.

So calling super(data) doesn't work as expected for child class as it's own type definitions overwrites data from parent's constructor with `undefined` at later point.

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-05-12 16:32:18 +03:00
parent 0c83513e51
commit df686a64b9
27 changed files with 44 additions and 52 deletions

View File

@ -54,7 +54,7 @@ export class Cluster extends KubeObject {
static kind = "Cluster"; static kind = "Cluster";
static apiBase = "/apis/cluster.k8s.io/v1alpha1/clusters"; static apiBase = "/apis/cluster.k8s.io/v1alpha1/clusters";
declare spec: { spec: {
clusterNetwork?: { clusterNetwork?: {
serviceDomain?: string; serviceDomain?: string;
pods?: { pods?: {
@ -70,7 +70,7 @@ export class Cluster extends KubeObject {
}; };
}; };
}; };
declare status?: { status?: {
apiEndpoints: { apiEndpoints: {
host: string; host: string;
port: string; port: string;

View File

@ -22,7 +22,7 @@ export class CustomResourceDefinition extends KubeObject {
static namespaced = false; static namespaced = false;
static apiBase = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions"; static apiBase = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions";
declare spec: { spec: {
group: string; group: string;
version?: string; // deprecated in v1 api version?: string; // deprecated in v1 api
names: { names: {
@ -46,7 +46,7 @@ export class CustomResourceDefinition extends KubeObject {
}; };
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[]; // removed in v1 additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[]; // removed in v1
}; };
declare status: { status: {
conditions: { conditions: {
lastTransitionTime: string; lastTransitionTime: string;
message: string; message: string;

View File

@ -48,7 +48,7 @@ export class CronJob extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
schedule: string; schedule: string;
concurrencyPolicy: string; concurrencyPolicy: string;
suspend: boolean; suspend: boolean;
@ -81,7 +81,7 @@ export class CronJob extends KubeObject {
successfulJobsHistoryLimit: number; successfulJobsHistoryLimit: number;
failedJobsHistoryLimit: number; failedJobsHistoryLimit: number;
}; };
declare status: { status: {
lastScheduleTime?: string; lastScheduleTime?: string;
}; };

View File

@ -15,7 +15,7 @@ export class DaemonSet extends WorkloadKubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
selector: { selector: {
matchLabels: { matchLabels: {
[name: string]: string; [name: string]: string;
@ -57,7 +57,7 @@ export class DaemonSet extends WorkloadKubeObject {
}; };
revisionHistoryLimit: number; revisionHistoryLimit: number;
}; };
declare status: { status: {
currentNumberScheduled: number; currentNumberScheduled: number;
numberMisscheduled: number; numberMisscheduled: number;
desiredNumberScheduled: number; desiredNumberScheduled: number;

View File

@ -77,7 +77,7 @@ export class Deployment extends WorkloadKubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
replicas: number; replicas: number;
selector: { matchLabels: { [app: string]: string } }; selector: { matchLabels: { [app: string]: string } };
template: { template: {
@ -156,7 +156,7 @@ export class Deployment extends WorkloadKubeObject {
}; };
}; };
}; };
declare status: { status: {
observedGeneration: number; observedGeneration: number;
replicas: number; replicas: number;
updatedReplicas: number; updatedReplicas: number;

View File

@ -1,21 +1,13 @@
import moment from "moment"; import moment from "moment";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration"; import { formatDuration } from "../../utils/formatDuration";
import { autoBind } from "../../utils";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { KubeJsonApiData } from "../kube-json-api";
export class KubeEvent extends KubeObject { export class KubeEvent extends KubeObject {
static kind = "Event"; static kind = "Event";
static namespaced = true; static namespaced = true;
static apiBase = "/api/v1/events"; static apiBase = "/api/v1/events";
constructor(data: KubeJsonApiData) {
super(data);
autoBind(this);
Object.assign(this, data); // TODO: figure out why this doesn't work from super()
}
involvedObject: { involvedObject: {
kind: string; kind: string;
namespace: string; namespace: string;

View File

@ -43,7 +43,7 @@ export class HorizontalPodAutoscaler extends KubeObject {
static namespaced = true; static namespaced = true;
static apiBase = "/apis/autoscaling/v2beta1/horizontalpodautoscalers"; static apiBase = "/apis/autoscaling/v2beta1/horizontalpodautoscalers";
declare spec: { spec: {
scaleTargetRef: { scaleTargetRef: {
kind: string; kind: string;
name: string; name: string;
@ -53,7 +53,7 @@ export class HorizontalPodAutoscaler extends KubeObject {
maxReplicas: number; maxReplicas: number;
metrics: IHpaMetric[]; metrics: IHpaMetric[];
}; };
declare status: { status: {
currentReplicas: number; currentReplicas: number;
desiredReplicas: number; desiredReplicas: number;
currentMetrics: IHpaMetric[]; currentMetrics: IHpaMetric[];

View File

@ -72,7 +72,7 @@ export class Ingress extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
tls: { tls: {
secretName: string; secretName: string;
}[]; }[];
@ -96,7 +96,7 @@ export class Ingress extends KubeObject {
} }
} }
}; };
declare status: { status: {
loadBalancer: { loadBalancer: {
ingress: ILoadBalancerIngress[]; ingress: ILoadBalancerIngress[];
}; };

View File

@ -16,7 +16,7 @@ export class Job extends WorkloadKubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
parallelism?: number; parallelism?: number;
completions?: number; completions?: number;
backoffLimit?: number; backoffLimit?: number;
@ -62,7 +62,7 @@ export class Job extends WorkloadKubeObject {
serviceAccount?: string; serviceAccount?: string;
schedulerName?: string; schedulerName?: string;
}; };
declare status: { status: {
conditions: { conditions: {
type: string; type: string;
status: string; status: string;

View File

@ -40,7 +40,7 @@ export class LimitRange extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
limits: LimitRangeItem[]; limits: LimitRangeItem[];
}; };

View File

@ -18,7 +18,7 @@ export class Namespace extends KubeObject {
autoBind(this); autoBind(this);
} }
declare status?: { status?: {
phase: string; phase: string;
}; };

View File

@ -46,7 +46,7 @@ export class NetworkPolicy extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
podSelector: { podSelector: {
matchLabels: { matchLabels: {
[label: string]: string; [label: string]: string;

View File

@ -39,7 +39,7 @@ export class Node extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
podCIDR: string; podCIDR: string;
externalID: string; externalID: string;
taints?: { taints?: {
@ -49,7 +49,7 @@ export class Node extends KubeObject {
}[]; }[];
unschedulable?: boolean; unschedulable?: boolean;
}; };
declare status: { status: {
capacity: { capacity: {
cpu: string; cpu: string;
memory: string; memory: string;

View File

@ -32,7 +32,7 @@ export class PersistentVolumeClaim extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
accessModes: string[]; accessModes: string[];
storageClassName: string; storageClassName: string;
selector: { selector: {
@ -51,7 +51,7 @@ export class PersistentVolumeClaim extends KubeObject {
}; };
}; };
}; };
declare status: { status: {
phase: string; // Pending phase: string; // Pending
}; };

View File

@ -14,7 +14,7 @@ export class PersistentVolume extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
capacity: { capacity: {
storage: string; // 8Gi storage: string; // 8Gi
}; };
@ -45,7 +45,7 @@ export class PersistentVolume extends KubeObject {
}; };
}; };
declare status: { status: {
phase: string; phase: string;
reason?: string; reason?: string;
}; };

View File

@ -13,12 +13,12 @@ export class PodDisruptionBudget extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
minAvailable: string; minAvailable: string;
maxUnavailable: string; maxUnavailable: string;
selector: { matchLabels: { [app: string]: string } }; selector: { matchLabels: { [app: string]: string } };
}; };
declare status: { status: {
currentHealthy: number currentHealthy: number
desiredHealthy: number desiredHealthy: number
disruptionsAllowed: number disruptionsAllowed: number

View File

@ -192,7 +192,7 @@ export class Pod extends WorkloadKubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
volumes?: { volumes?: {
name: string; name: string;
persistentVolumeClaim: { persistentVolumeClaim: {
@ -249,7 +249,7 @@ export class Pod extends WorkloadKubeObject {
}; };
affinity?: IAffinity; affinity?: IAffinity;
}; };
declare status?: { status?: {
phase: string; phase: string;
conditions: { conditions: {
type: string; type: string;

View File

@ -13,7 +13,7 @@ export class PodSecurityPolicy extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
allowPrivilegeEscalation?: boolean; allowPrivilegeEscalation?: boolean;
allowedCSIDrivers?: { allowedCSIDrivers?: {
name: string; name: string;

View File

@ -38,7 +38,7 @@ export class ReplicaSet extends WorkloadKubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
replicas?: number; replicas?: number;
selector: { matchLabels: { [app: string]: string } }; selector: { matchLabels: { [app: string]: string } };
template?: { template?: {
@ -51,7 +51,7 @@ export class ReplicaSet extends WorkloadKubeObject {
}; };
minReadySeconds?: number; minReadySeconds?: number;
}; };
declare status: { status: {
replicas: number; replicas: number;
fullyLabeledReplicas?: number; fullyLabeledReplicas?: number;
readyReplicas?: number; readyReplicas?: number;

View File

@ -40,7 +40,7 @@ export class ResourceQuota extends KubeObject {
this.spec = this.spec || {} as any; this.spec = this.spec || {} as any;
} }
declare spec: { spec: {
hard: IResourceQuotaValues; hard: IResourceQuotaValues;
scopeSelector?: { scopeSelector?: {
matchExpressions: { matchExpressions: {
@ -51,7 +51,7 @@ export class ResourceQuota extends KubeObject {
}; };
}; };
declare status: { status: {
hard: IResourceQuotaValues; hard: IResourceQuotaValues;
used: IResourceQuotaValues; used: IResourceQuotaValues;
}; };

View File

@ -25,12 +25,12 @@ export class SelfSubjectRulesReview extends KubeObject {
static namespaced = false; static namespaced = false;
static apiBase = "/apis/authorization.k8s.io/v1/selfsubjectrulesreviews"; static apiBase = "/apis/authorization.k8s.io/v1/selfsubjectrulesreviews";
declare spec: { spec: {
// todo: add more types from api docs // todo: add more types from api docs
namespace?: string; namespace?: string;
}; };
declare status: { status: {
resourceRules: ISelfSubjectReviewRule[]; resourceRules: ISelfSubjectReviewRule[];
nonResourceRules: ISelfSubjectReviewRule[]; nonResourceRules: ISelfSubjectReviewRule[];
incomplete: boolean; incomplete: boolean;

View File

@ -40,7 +40,7 @@ export class Service extends KubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
type: string; type: string;
clusterIP: string; clusterIP: string;
externalTrafficPolicy?: string; externalTrafficPolicy?: string;
@ -51,7 +51,7 @@ export class Service extends KubeObject {
externalIPs?: string[]; // https://kubernetes.io/docs/concepts/services-networking/service/#external-ips externalIPs?: string[]; // https://kubernetes.io/docs/concepts/services-networking/service/#external-ips
}; };
declare status: { status: {
loadBalancer?: { loadBalancer?: {
ingress?: { ingress?: {
ip?: string; ip?: string;

View File

@ -38,7 +38,7 @@ export class StatefulSet extends WorkloadKubeObject {
autoBind(this); autoBind(this);
} }
declare spec: { spec: {
serviceName: string; serviceName: string;
replicas: number; replicas: number;
selector: { selector: {
@ -91,7 +91,7 @@ export class StatefulSet extends WorkloadKubeObject {
}; };
}[]; }[];
}; };
declare status: { status: {
observedGeneration: number; observedGeneration: number;
replicas: number; replicas: number;
currentReplicas: number; currentReplicas: number;

View File

@ -145,7 +145,7 @@ export class KubeObject implements ItemObject {
kind: string; kind: string;
metadata: IKubeObjectMetadata; metadata: IKubeObjectMetadata;
status?: any; status?: any;
spec: any = {}; spec?: any;
get selfLink() { get selfLink() {
return this.metadata.selfLink; return this.metadata.selfLink;

View File

@ -326,7 +326,7 @@ export class MenuItem extends React.Component<MenuItemProps> {
static defaultProps = defaultPropsMenuItem as object; static defaultProps = defaultPropsMenuItem as object;
static contextType = MenuContext; static contextType = MenuContext;
declare context: MenuContextValue; public context: MenuContextValue;
public elem: HTMLElement; public elem: HTMLElement;
constructor(props: MenuItemProps) { constructor(props: MenuItemProps) {

View File

@ -62,7 +62,7 @@ export interface TabProps<D = any> extends DOMAttributes<HTMLElement> {
export class Tab extends React.PureComponent<TabProps> { export class Tab extends React.PureComponent<TabProps> {
static contextType = TabsContext; static contextType = TabsContext;
declare context: TabsContextValue; public context: TabsContextValue;
public elem: HTMLElement; public elem: HTMLElement;
get isActive() { get isActive() {

View File

@ -23,7 +23,7 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"traceResolution": false, "traceResolution": false,
"resolveJsonModule": true, "resolveJsonModule": true,
"useDefineForClassFields": true, "useDefineForClassFields": false,
"paths": { "paths": {
"*": [ "*": [
"node_modules/*", "node_modules/*",