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

Fix breaking changes in extension API types (#5797)

This commit is contained in:
Sebastian Malton 2022-07-06 12:00:31 -07:00 committed by GitHub
parent 2a37d6bfac
commit d44599af00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 234 additions and 93 deletions

View File

@ -5,7 +5,7 @@
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { RoleRef } from "./types/role-ref"; import type { RoleRef } from "./types/role-ref";
import type { Subject } from "./types/subject"; import type { Subject } from "./types/subject";
@ -15,7 +15,11 @@ export interface ClusterRoleBindingData extends KubeJsonApiData<KubeObjectMetada
roleRef: RoleRef; roleRef: RoleRef;
} }
export class ClusterRoleBinding extends KubeObject<void, void, KubeObjectScope.Cluster> { export class ClusterRoleBinding extends KubeObject<
ClusterScopedMetadata,
void,
void
> {
static kind = "ClusterRoleBinding"; static kind = "ClusterRoleBinding";
static namespaced = false; static namespaced = false;
static apiBase = "/apis/rbac.authorization.k8s.io/v1/clusterrolebindings"; static apiBase = "/apis/rbac.authorization.k8s.io/v1/clusterrolebindings";

View File

@ -6,7 +6,7 @@
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { AggregationRule } from "./types/aggregation-rule"; import type { AggregationRule } from "./types/aggregation-rule";
import type { PolicyRule } from "./types/policy-rule"; import type { PolicyRule } from "./types/policy-rule";
@ -16,7 +16,11 @@ export interface ClusterRoleData extends KubeJsonApiData<KubeObjectMetadata<Kube
aggregationRule?: AggregationRule; aggregationRule?: AggregationRule;
} }
export class ClusterRole extends KubeObject<void, void, KubeObjectScope.Cluster> { export class ClusterRole extends KubeObject<
ClusterScopedMetadata,
void,
void
> {
static kind = "ClusterRole"; static kind = "ClusterRole";
static namespaced = false; static namespaced = false;
static apiBase = "/apis/rbac.authorization.k8s.io/v1/clusterroles"; static apiBase = "/apis/rbac.authorization.k8s.io/v1/clusterroles";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
@ -16,7 +16,11 @@ export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<KubeOb
immutable?: boolean; immutable?: boolean;
} }
export class ConfigMap extends KubeObject<void, void, KubeObjectScope.Namespace> { export class ConfigMap extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static kind = "ConfigMap"; static kind = "ConfigMap";
static namespaced = true; static namespaced = true;
static apiBase = "/api/v1/configmaps"; static apiBase = "/api/v1/configmaps";

View File

@ -4,7 +4,7 @@
*/ */
import moment from "moment"; import moment from "moment";
import type { KubeObjectScope, ObjectReference } from "../kube-object"; import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration"; import { formatDuration } from "../../utils/formatDuration";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
@ -66,7 +66,11 @@ export interface CronJobStatus {
active?: ObjectReference[]; active?: ObjectReference[];
} }
export class CronJob extends KubeObject<CronJobStatus, CronJobSpec, KubeObjectScope.Namespace> { export class CronJob extends KubeObject<
NamespaceScopedMetadata,
CronJobStatus,
CronJobSpec
> {
static readonly kind = "CronJob"; static readonly kind = "CronJob";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/batch/v1beta1/cronjobs"; static readonly apiBase = "/apis/batch/v1beta1/cronjobs";

View File

@ -6,7 +6,7 @@
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable"; import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
import { buildURL } from "../../utils/buildUrl"; import { buildURL } from "../../utils/buildUrl";
import type { BaseKubeObjectCondition, KubeObjectScope } from "../kube-object"; import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -107,7 +107,11 @@ export interface CustomResourceDefinitionStatus {
storedVersions: string[]; storedVersions: string[];
} }
export class CustomResourceDefinition extends KubeObject<CustomResourceDefinitionStatus, CustomResourceDefinitionSpec, KubeObjectScope.Cluster> { export class CustomResourceDefinition extends KubeObject<
ClusterScopedMetadata,
CustomResourceDefinitionStatus,
CustomResourceDefinitionSpec
> {
static kind = "CustomResourceDefinition"; static kind = "CustomResourceDefinition";
static namespaced = false; static namespaced = false;
static apiBase = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions"; static apiBase = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions";

View File

@ -7,7 +7,7 @@ import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pod.api"; import type { PodMetricData } from "./pod.api";
import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { PodTemplateSpec } from "./types/pod-template-spec"; import type { PodTemplateSpec } from "./types/pod-template-spec";
@ -41,7 +41,11 @@ export interface DaemonSetStatus extends KubeObjectStatus {
updatedNumberScheduled?: number; updatedNumberScheduled?: number;
} }
export class DaemonSet extends KubeObject<DaemonSetStatus, DaemonSetSpec, KubeObjectScope.Namespace> { export class DaemonSet extends KubeObject<
NamespaceScopedMetadata,
DaemonSetStatus,
DaemonSetSpec
> {
static kind = "DaemonSet"; static kind = "DaemonSet";
static namespaced = true; static namespaced = true;
static apiBase = "/apis/apps/v1/daemonsets"; static apiBase = "/apis/apps/v1/daemonsets";

View File

@ -9,7 +9,7 @@ import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData, PodSpec } from "./pod.api"; import type { PodMetricData, PodSpec } from "./pod.api";
import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { hasTypedProperty, isNumber, isObject } from "../../utils"; import { hasTypedProperty, isNumber, isObject } from "../../utils";
@ -116,7 +116,11 @@ export interface DeploymentStatus extends KubeObjectStatus {
unavailableReplicas?: number; unavailableReplicas?: number;
} }
export class Deployment extends KubeObject<DeploymentStatus, DeploymentSpec, KubeObjectScope.Namespace> { export class Deployment extends KubeObject<
NamespaceScopedMetadata,
DeploymentStatus,
DeploymentSpec
> {
static kind = "Deployment"; static kind = "Deployment";
static namespaced = true; static namespaced = true;
static apiBase = "/apis/apps/v1/deployments"; static apiBase = "/apis/apps/v1/deployments";

View File

@ -4,7 +4,7 @@
*/ */
import { autoBind } from "../../utils"; import { autoBind } from "../../utils";
import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -75,7 +75,11 @@ export interface EndpointsData extends KubeJsonApiData<KubeObjectMetadata<KubeOb
subsets?: EndpointSubset[]; subsets?: EndpointSubset[];
} }
export class Endpoints extends KubeObject<void, void, KubeObjectScope.Namespace> { export class Endpoints extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static kind = "Endpoints"; static kind = "Endpoints";
static namespaced = true; static namespaced = true;
static apiBase = "/api/v1/endpoints"; static apiBase = "/api/v1/endpoints";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { BaseKubeObjectCondition, KubeObjectScope, LabelSelector } from "../kube-object"; import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -97,7 +97,11 @@ interface MetricCurrentTarget {
target?: string; target?: string;
} }
export class HorizontalPodAutoscaler extends KubeObject<HorizontalPodAutoscalerStatus, HorizontalPodAutoscalerSpec, KubeObjectScope.Namespace> { export class HorizontalPodAutoscaler extends KubeObject<
NamespaceScopedMetadata,
HorizontalPodAutoscalerStatus,
HorizontalPodAutoscalerSpec
> {
static readonly kind = "HorizontalPodAutoscaler"; static readonly kind = "HorizontalPodAutoscaler";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/autoscaling/v2beta1/horizontalpodautoscalers"; static readonly apiBase = "/apis/autoscaling/v2beta1/horizontalpodautoscalers";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope, TypedLocalObjectReference } from "../kube-object"; import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { hasTypedProperty, isString, iter } from "../../utils"; import { hasTypedProperty, isString, iter } from "../../utils";
import type { MetricData } from "./metrics.api"; import type { MetricData } from "./metrics.api";
@ -140,7 +140,11 @@ export interface IngressStatus {
}; };
} }
export class Ingress extends KubeObject<IngressStatus, IngressSpec, KubeObjectScope.Namespace> { export class Ingress extends KubeObject<
NamespaceScopedMetadata,
IngressStatus,
IngressSpec
> {
static readonly kind = "Ingress"; static readonly kind = "Ingress";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/networking.k8s.io/v1/ingresses"; static readonly apiBase = "/apis/networking.k8s.io/v1/ingresses";

View File

@ -7,7 +7,7 @@ import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodContainer, PodMetricData, PodSpec } from "./pod.api"; import type { PodContainer, PodMetricData, PodSpec } from "./pod.api";
import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
export interface JobSpec { export interface JobSpec {
@ -38,7 +38,11 @@ export interface JobStatus extends KubeObjectStatus {
succeeded: number; succeeded: number;
} }
export class Job extends KubeObject<JobStatus, JobSpec, KubeObjectScope.Namespace> { export class Job extends KubeObject<
NamespaceScopedMetadata,
JobStatus,
JobSpec
> {
static readonly kind = "Job"; static readonly kind = "Job";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/batch/v1/jobs"; static readonly apiBase = "/apis/batch/v1/jobs";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope } from "../kube-object"; import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -39,7 +39,11 @@ export interface LimitRangeSpec {
limits: LimitRangeItem[]; limits: LimitRangeItem[];
} }
export class LimitRange extends KubeObject<void, LimitRangeSpec, KubeObjectScope.Namespace> { export class LimitRange extends KubeObject<
NamespaceScopedMetadata,
void,
LimitRangeSpec
> {
static readonly kind = "LimitRange"; static readonly kind = "LimitRange";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/api/v1/limitranges"; static readonly apiBase = "/api/v1/limitranges";

View File

@ -5,7 +5,7 @@
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { KubeObjectScope, KubeObjectStatus } from "../kube-object"; import type { ClusterScopedMetadata, KubeObjectStatus } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pod.api"; import type { PodMetricData } from "./pod.api";
@ -23,7 +23,11 @@ export interface NamespaceStatus extends KubeObjectStatus {
phase?: string; phase?: string;
} }
export class Namespace extends KubeObject<NamespaceStatus, NamespaceSpec, KubeObjectScope.Cluster> { export class Namespace extends KubeObject<
ClusterScopedMetadata,
NamespaceStatus,
NamespaceSpec
> {
static readonly kind = "Namespace"; static readonly kind = "Namespace";
static readonly namespaced = false; static readonly namespaced = false;
static readonly apiBase = "/api/v1/namespaces"; static readonly apiBase = "/api/v1/namespaces";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope, LabelSelector } from "../kube-object"; import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -99,11 +99,11 @@ export interface NetworkPolicySpec {
egress?: IPolicyEgress[]; egress?: IPolicyEgress[];
} }
export interface NetworkPolicy { export class NetworkPolicy extends KubeObject<
spec: NetworkPolicySpec; NamespaceScopedMetadata,
} void,
NetworkPolicySpec
export class NetworkPolicy extends KubeObject<void, NetworkPolicySpec, KubeObjectScope.Namespace> { > {
static readonly kind = "NetworkPolicy"; static readonly kind = "NetworkPolicy";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/networking.k8s.io/v1/networkpolicies"; static readonly apiBase = "/apis/networking.k8s.io/v1/networkpolicies";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { BaseKubeObjectCondition, KubeObjectScope } from "../kube-object"; import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils"; import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
import type { MetricData } from "./metrics.api"; import type { MetricData } from "./metrics.api";
@ -176,7 +176,11 @@ export interface NodeStatus {
volumesAttached?: AttachedVolume[]; volumesAttached?: AttachedVolume[];
} }
export class Node extends KubeObject<NodeStatus, NodeSpec, KubeObjectScope.Cluster> { export class Node extends KubeObject<
ClusterScopedMetadata,
NodeStatus,
NodeSpec
> {
static readonly kind = "Node"; static readonly kind = "Node";
static readonly namespaced = false; static readonly namespaced = false;
static readonly apiBase = "/api/v1/nodes"; static readonly apiBase = "/api/v1/nodes";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope, LabelSelector, TypedLocalObjectReference } from "../kube-object"; import type { LabelSelector, NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { MetricData } from "./metrics.api"; import type { MetricData } from "./metrics.api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
@ -53,7 +53,11 @@ export interface PersistentVolumeClaimStatus {
phase: string; // Pending phase: string; // Pending
} }
export class PersistentVolumeClaim extends KubeObject<PersistentVolumeClaimStatus, PersistentVolumeClaimSpec, KubeObjectScope.Namespace> { export class PersistentVolumeClaim extends KubeObject<
NamespaceScopedMetadata,
PersistentVolumeClaimStatus,
PersistentVolumeClaimSpec
> {
static readonly kind = "PersistentVolumeClaim"; static readonly kind = "PersistentVolumeClaim";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/api/v1/persistentvolumeclaims"; static readonly apiBase = "/api/v1/persistentvolumeclaims";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object"; import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { unitsToBytes } from "../../utils"; import { unitsToBytes } from "../../utils";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
@ -64,7 +64,11 @@ export interface PersistentVolumeStatus {
reason?: string; reason?: string;
} }
export class PersistentVolume extends KubeObject<PersistentVolumeStatus, PersistentVolumeSpec, KubeObjectScope.Cluster> { export class PersistentVolume extends KubeObject<
ClusterScopedMetadata,
PersistentVolumeStatus,
PersistentVolumeSpec
> {
static kind = "PersistentVolume"; static kind = "PersistentVolume";
static namespaced = false; static namespaced = false;
static apiBase = "/api/v1/persistentvolumes"; static apiBase = "/api/v1/persistentvolumes";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope, LabelSelector } from "../kube-object"; import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -21,7 +21,11 @@ export interface PodDisruptionBudgetStatus {
expectedPods: number; expectedPods: number;
} }
export class PodDisruptionBudget extends KubeObject<PodDisruptionBudgetStatus, PodDisruptionBudgetSpec, KubeObjectScope.Namespace> { export class PodDisruptionBudget extends KubeObject<
NamespaceScopedMetadata,
PodDisruptionBudgetStatus,
PodDisruptionBudgetSpec
> {
static readonly kind = "PodDisruptionBudget"; static readonly kind = "PodDisruptionBudget";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/policy/v1beta1/poddisruptionbudgets"; static readonly apiBase = "/apis/policy/v1beta1/poddisruptionbudgets";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -25,7 +25,11 @@ export interface PodMetricsContainer {
usage: PodMetricsContainerUsage; usage: PodMetricsContainerUsage;
} }
export class PodMetrics extends KubeObject<void, void, KubeObjectScope.Namespace> { export class PodMetrics extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static readonly kind = "PodMetrics"; static readonly kind = "PodMetrics";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/metrics.k8s.io/v1beta1/pods"; static readonly apiBase = "/apis/metrics.k8s.io/v1beta1/pods";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope } from "../kube-object"; import type { ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -80,7 +80,11 @@ export interface PodSecurityPolicySpec {
volumes?: string[]; volumes?: string[];
} }
export class PodSecurityPolicy extends KubeObject<void, PodSecurityPolicySpec, KubeObjectScope.Cluster> { export class PodSecurityPolicy extends KubeObject<
ClusterScopedMetadata,
void,
PodSecurityPolicySpec
> {
static readonly kind = "PodSecurityPolicy"; static readonly kind = "PodSecurityPolicy";
static readonly namespaced = false; static readonly namespaced = false;
static readonly apiBase = "/apis/policy/v1beta1/podsecuritypolicies"; static readonly apiBase = "/apis/policy/v1beta1/podsecuritypolicies";

View File

@ -8,7 +8,7 @@ import { metricsApi } from "./metrics.api";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions, ResourceDescriptor } from "../kube-api"; import type { DerivedKubeApiOptions, IgnoredKubeApiOptions, ResourceDescriptor } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { RequireExactlyOne } from "type-fest"; import type { RequireExactlyOne } from "type-fest";
import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, LabelSelector, KubeObjectScope } from "../kube-object"; import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import type { SecretReference } from "./secret.api"; import type { SecretReference } from "./secret.api";
import type { PersistentVolumeClaimSpec } from "./persistent-volume-claim.api"; import type { PersistentVolumeClaimSpec } from "./persistent-volume-claim.api";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
@ -776,7 +776,11 @@ export interface PodStatus {
reason?: string; reason?: string;
} }
export class Pod extends KubeObject<PodStatus, PodSpec, KubeObjectScope.Namespace> { export class Pod extends KubeObject<
NamespaceScopedMetadata,
PodStatus,
PodSpec
> {
static kind = "Pod"; static kind = "Pod";
static namespaced = true; static namespaced = true;
static apiBase = "/api/v1/pods"; static apiBase = "/api/v1/pods";

View File

@ -7,7 +7,7 @@ import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pod.api"; import type { PodMetricData } from "./pod.api";
import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { PodTemplateSpec } from "./types/pod-template-spec"; import type { PodTemplateSpec } from "./types/pod-template-spec";
@ -73,7 +73,11 @@ export interface ReplicaSetStatus extends KubeObjectStatus {
observedGeneration?: number; observedGeneration?: number;
} }
export class ReplicaSet extends KubeObject<ReplicaSetStatus, ReplicaSetSpec, KubeObjectScope.Namespace> { export class ReplicaSet extends KubeObject<
NamespaceScopedMetadata,
ReplicaSetStatus,
ReplicaSetSpec
> {
static kind = "ReplicaSet"; static kind = "ReplicaSet";
static namespaced = true; static namespaced = true;
static apiBase = "/apis/apps/v1/replicasets"; static apiBase = "/apis/apps/v1/replicasets";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope } from "../kube-object"; import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -50,7 +50,11 @@ export interface ResourceQuotaStatus {
used: IResourceQuotaValues; used: IResourceQuotaValues;
} }
export class ResourceQuota extends KubeObject<ResourceQuotaStatus, ResourceQuotaSpec, KubeObjectScope.Namespace> { export class ResourceQuota extends KubeObject<
NamespaceScopedMetadata,
ResourceQuotaStatus,
ResourceQuotaSpec
> {
static readonly kind = "ResourceQuota"; static readonly kind = "ResourceQuota";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/api/v1/resourcequotas"; static readonly apiBase = "/api/v1/resourcequotas";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -16,7 +16,11 @@ export interface RoleBindingData extends KubeJsonApiData<KubeObjectMetadata<Kube
roleRef: RoleRef; roleRef: RoleRef;
} }
export class RoleBinding extends KubeObject<void, void, KubeObjectScope.Namespace> { export class RoleBinding extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static readonly kind = "RoleBinding"; static readonly kind = "RoleBinding";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/rbac.authorization.k8s.io/v1/rolebindings"; static readonly apiBase = "/apis/rbac.authorization.k8s.io/v1/rolebindings";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -14,7 +14,11 @@ export interface RoleData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectS
rules?: PolicyRule[]; rules?: PolicyRule[];
} }
export class Role extends KubeObject<void, void, KubeObjectScope.Namespace> { export class Role extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static readonly kind = "Role"; static readonly kind = "Role";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/rbac.authorization.k8s.io/v1/roles"; static readonly apiBase = "/apis/rbac.authorization.k8s.io/v1/roles";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import { autoBind } from "../../utils"; import { autoBind } from "../../utils";
@ -42,7 +42,11 @@ export interface SecretData extends KubeJsonApiData<KubeObjectMetadata<KubeObjec
data?: Partial<Record<string, string>>; data?: Partial<Record<string, string>>;
} }
export class Secret extends KubeObject<void, void, KubeObjectScope.Namespace> { export class Secret extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static readonly kind = "Secret"; static readonly kind = "Secret";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/api/v1/secrets"; static readonly apiBase = "/api/v1/secrets";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectMetadata, KubeObjectScope, LocalObjectReference, ObjectReference } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, LocalObjectReference, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -15,7 +15,11 @@ export interface ServiceAccountData extends KubeJsonApiData<KubeObjectMetadata<K
secrets?: ObjectReference[]; secrets?: ObjectReference[];
} }
export class ServiceAccount extends KubeObject<void, void, KubeObjectScope.Namespace> { export class ServiceAccount extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static readonly kind = "ServiceAccount"; static readonly kind = "ServiceAccount";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/api/v1/serviceaccounts"; static readonly apiBase = "/api/v1/serviceaccounts";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { KubeObjectScope } from "../kube-object"; import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -60,7 +60,11 @@ export interface ServiceStatus {
}; };
} }
export class Service extends KubeObject<ServiceStatus, ServiceSpec, KubeObjectScope.Namespace> { export class Service extends KubeObject<
NamespaceScopedMetadata,
ServiceStatus,
ServiceSpec
> {
static readonly kind = "Service"; static readonly kind = "Service";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/api/v1/services"; static readonly apiBase = "/api/v1/services";

View File

@ -7,7 +7,7 @@ import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pod.api"; import type { PodMetricData } from "./pod.api";
import type { KubeObjectScope, LabelSelector } from "../kube-object"; import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { PodTemplateSpec } from "./types/pod-template-spec"; import type { PodTemplateSpec } from "./types/pod-template-spec";
import type { PersistentVolumeClaimTemplateSpec } from "./types/persistent-volume-claim-template-spec"; import type { PersistentVolumeClaimTemplateSpec } from "./types/persistent-volume-claim-template-spec";
@ -81,7 +81,11 @@ export interface StatefulSetStatus {
collisionCount: number; collisionCount: number;
} }
export class StatefulSet extends KubeObject<StatefulSetStatus, StatefulSetSpec, KubeObjectScope.Namespace> { export class StatefulSet extends KubeObject<
NamespaceScopedMetadata,
StatefulSetStatus,
StatefulSetSpec
> {
static readonly kind = "StatefulSet"; static readonly kind = "StatefulSet";
static readonly namespaced = true; static readonly namespaced = true;
static readonly apiBase = "/apis/apps/v1/statefulsets"; static readonly apiBase = "/apis/apps/v1/statefulsets";

View File

@ -4,7 +4,7 @@
*/ */
import { autoBind } from "../../utils"; import { autoBind } from "../../utils";
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
@ -29,7 +29,11 @@ export interface StorageClassData extends KubeJsonApiData<KubeObjectMetadata<Kub
volumeBindingMode?: string; volumeBindingMode?: string;
} }
export class StorageClass extends KubeObject<void, void, KubeObjectScope.Cluster> { export class StorageClass extends KubeObject<
ClusterScopedMetadata,
void,
void
> {
static readonly kind = "StorageClass"; static readonly kind = "StorageClass";
static readonly namespaced = false; static readonly namespaced = false;
static readonly apiBase = "/apis/storage.k8s.io/v1/storageclasses"; static readonly apiBase = "/apis/storage.k8s.io/v1/storageclasses";

View File

@ -10,7 +10,7 @@ import { stringify } from "querystring";
import { apiKubePrefix, isDevelopment } from "../../common/vars"; import { apiKubePrefix, isDevelopment } from "../../common/vars";
import { apiBase, apiKube } from "./index"; import { apiBase, apiKube } from "./index";
import { createKubeApiURL, parseKubeApi } from "./kube-api-parse"; import { createKubeApiURL, parseKubeApi } from "./kube-api-parse";
import type { KubeObjectConstructor, KubeJsonApiDataFor, KubeObjectMetadata, KubeObjectScope } from "./kube-object"; import type { KubeObjectConstructor, KubeJsonApiDataFor, KubeObjectMetadata } from "./kube-object";
import { KubeObject, KubeStatus, isKubeStatusData } from "./kube-object"; import { KubeObject, KubeStatus, isKubeStatusData } from "./kube-object";
import byline from "byline"; import byline from "byline";
import type { IKubeWatchEvent } from "./kube-watch-event"; import type { IKubeWatchEvent } from "./kube-watch-event";
@ -32,7 +32,7 @@ import autoRegistrationEmitterInjectable from "./api-manager/auto-registration-e
/** /**
* The options used for creating a `KubeApi` * The options used for creating a `KubeApi`
*/ */
export interface KubeApiOptions<T extends KubeObject<any, any, KubeObjectScope>, Data extends KubeJsonApiDataFor<T> = KubeJsonApiDataFor<T>> extends DerivedKubeApiOptions { export interface KubeApiOptions<T extends KubeObject, Data extends KubeJsonApiDataFor<T> = KubeJsonApiDataFor<T>> extends DerivedKubeApiOptions {
/** /**
* base api-path for listing all resources, e.g. "/api/v1/pods" * base api-path for listing all resources, e.g. "/api/v1/pods"
* *
@ -179,17 +179,17 @@ export interface IRemoteKubeApiConfig {
} }
export function forCluster< export function forCluster<
Object extends KubeObject<any, any, KubeObjectScope>, Object extends KubeObject,
Api extends KubeApi<Object>, Api extends KubeApi<Object>,
Data extends KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object>,
>(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: new (apiOpts: KubeApiOptions<Object>) => Api): Api; >(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: new (apiOpts: KubeApiOptions<Object>) => Api): Api;
export function forCluster< export function forCluster<
Object extends KubeObject<any, any, KubeObjectScope>, Object extends KubeObject,
Data extends KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object>,
>(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>): KubeApi<Object>; >(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>): KubeApi<Object>;
export function forCluster< export function forCluster<
Object extends KubeObject<any, any, KubeObjectScope>, Object extends KubeObject,
Data extends KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object>,
>(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: (new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>) = KubeApi): KubeApi<Object> { >(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: (new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>) = KubeApi): KubeApi<Object> {
const url = new URL(apiBase.config.serverAddress); const url = new URL(apiBase.config.serverAddress);
@ -210,17 +210,17 @@ export function forCluster<
} }
export function forRemoteCluster< export function forRemoteCluster<
Object extends KubeObject<any, any, KubeObjectScope>, Object extends KubeObject,
Api extends KubeApi<Object>, Api extends KubeApi<Object>,
Data extends KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object>,
>(config: IRemoteKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: new (apiOpts: KubeApiOptions<Object>) => Api): Api; >(config: IRemoteKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: new (apiOpts: KubeApiOptions<Object>) => Api): Api;
export function forRemoteCluster< export function forRemoteCluster<
Object extends KubeObject<any, any, KubeObjectScope>, Object extends KubeObject,
Data extends KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object>,
>(config: IRemoteKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>): KubeApi<Object>; >(config: IRemoteKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>): KubeApi<Object>;
export function forRemoteCluster< export function forRemoteCluster<
Object extends KubeObject<any, any, KubeObjectScope>, Object extends KubeObject,
Api extends KubeApi<Object>, Api extends KubeApi<Object>,
Data extends KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object>,
>(config: IRemoteKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object> = KubeApi): KubeApi<Object> { >(config: IRemoteKubeApiConfig, kubeClass: KubeObjectConstructor<Object, Data>, apiClass: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object> = KubeApi): KubeApi<Object> {
@ -277,7 +277,7 @@ export function forRemoteCluster<
export type KubeApiWatchCallback<T extends KubeJsonApiData = KubeJsonApiData> = (data: IKubeWatchEvent<T>, error: any) => void; export type KubeApiWatchCallback<T extends KubeJsonApiData = KubeJsonApiData> = (data: IKubeWatchEvent<T>, error: any) => void;
export interface KubeApiWatchOptions<Object extends KubeObject<any, any, KubeObjectScope>, Data extends KubeJsonApiDataFor<Object>> { export interface KubeApiWatchOptions<Object extends KubeObject, Data extends KubeJsonApiDataFor<Object>> {
namespace: string; namespace: string;
callback?: KubeApiWatchCallback<Data>; callback?: KubeApiWatchCallback<Data>;
abortController?: AbortController; abortController?: AbortController;

View File

@ -83,6 +83,8 @@ export type KubeApiDataFrom<K extends KubeObject, A> = A extends KubeApi<K, infe
: never : never
: never; : never;
export type JsonPatch = Patch;
export abstract class KubeObjectStore< export abstract class KubeObjectStore<
K extends KubeObject = KubeObject, K extends KubeObject = KubeObject,
A extends KubeApi<K, D> = KubeApi<K, KubeJsonApiDataFor<K>>, A extends KubeApi<K, D> = KubeApi<K, KubeJsonApiDataFor<K>>,
@ -90,7 +92,7 @@ export abstract class KubeObjectStore<
> extends ItemStore<K> { > extends ItemStore<K> {
static readonly defaultContext = observable.box<ClusterContext>(); // TODO: support multiple cluster contexts static readonly defaultContext = observable.box<ClusterContext>(); // TODO: support multiple cluster contexts
public readonly api: A; public readonly api!: A;
public readonly limit: number | undefined; public readonly limit: number | undefined;
public readonly bufferSize: number; public readonly bufferSize: number;
@observable private loadedNamespaces: string[] | undefined = undefined; @observable private loadedNamespaces: string[] | undefined = undefined;
@ -103,9 +105,18 @@ export abstract class KubeObjectStore<
return when(() => Boolean(this.loadedNamespaces)); return when(() => Boolean(this.loadedNamespaces));
} }
constructor(api: A, opts?: KubeObjectStoreOptions) { constructor(api: A, opts?: KubeObjectStoreOptions);
/**
* @deprecated Supply API instance through constructor
*/
constructor();
constructor(api?: A, opts?: KubeObjectStoreOptions) {
super(); super();
if (api) {
this.api = api; this.api = api;
}
this.limit = opts?.limit; this.limit = opts?.limit;
this.bufferSize = opts?.bufferSize ?? 50_000; this.bufferSize = opts?.bufferSize ?? 50_000;
@ -376,7 +387,7 @@ export abstract class KubeObjectStore<
return newItem; return newItem;
} }
async patch(item: K, patch: Patch): Promise<K> { async patch(item: K, patch: JsonPatch): Promise<K> {
const rawItem = await this.api.patch( const rawItem = await this.api.patch(
{ {
name: item.getName(), namespace: item.getNs(), name: item.getName(), namespace: item.getNs(),

View File

@ -15,8 +15,8 @@ import type { Patch } from "rfc6902";
import assert from "assert"; import assert from "assert";
import type { JsonObject } from "type-fest"; import type { JsonObject } from "type-fest";
export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Status, infer Spec, infer Scope> export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Metadata, infer Status, infer Spec>
? KubeJsonApiData<KubeObjectMetadata<Scope>, Status, Spec> ? KubeJsonApiData<Metadata, Status, Spec>
: never; : never;
export interface KubeObjectConstructorData { export interface KubeObjectConstructorData {
@ -25,7 +25,7 @@ export interface KubeObjectConstructorData {
readonly apiBase?: string; readonly apiBase?: string;
} }
export type KubeObjectConstructor<K extends KubeObject<any, any, KubeObjectScope>, Data> = (new (data: Data) => K) & KubeObjectConstructorData; export type KubeObjectConstructor<K extends KubeObject, Data> = (new (data: Data) => K) & KubeObjectConstructorData;
export interface OwnerReference { export interface OwnerReference {
apiVersion: string; apiVersion: string;
@ -199,9 +199,11 @@ export interface BaseKubeJsonApiObjectMetadata<Namespaced extends KubeObjectScop
[key: string]: unknown; [key: string]: unknown;
} }
export type KubeJsonApiObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = Namespaced extends KubeObjectScope.Namespace export type KubeJsonApiObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = BaseKubeJsonApiObjectMetadata<Namespaced> & (
? BaseKubeJsonApiObjectMetadata<KubeObjectScope.Namespace> & { readonly namespace: string } Namespaced extends KubeObjectScope.Namespace
: BaseKubeJsonApiObjectMetadata<Namespaced>; ? { readonly namespace: string }
: {}
);
export type KubeObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = KubeJsonApiObjectMetadata<Namespaced> & { export type KubeObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = KubeJsonApiObjectMetadata<Namespaced> & {
readonly selfLink: string; readonly selfLink: string;
@ -210,6 +212,9 @@ export type KubeObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectSc
readonly resourceVersion: string; readonly resourceVersion: string;
}; };
export type NamespaceScopedMetadata = KubeObjectMetadata<KubeObjectScope.Namespace>;
export type ClusterScopedMetadata = KubeObjectMetadata<KubeObjectScope.Cluster>;
export interface KubeStatusData { export interface KubeStatusData {
kind: string; kind: string;
apiVersion: string; apiVersion: string;
@ -371,9 +376,9 @@ export type ScopedNamespace<Namespaced extends KubeObjectScope> = (
); );
export class KubeObject< export class KubeObject<
Metadata extends KubeObjectMetadata<KubeObjectScope> = KubeObjectMetadata<KubeObjectScope>,
Status = unknown, Status = unknown,
Spec = unknown, Spec = unknown,
Namespaced extends KubeObjectScope = KubeObjectScope,
> implements ItemObject { > implements ItemObject {
static readonly kind?: string; static readonly kind?: string;
static readonly namespaced?: boolean; static readonly namespaced?: boolean;
@ -381,7 +386,7 @@ export class KubeObject<
apiVersion!: string; apiVersion!: string;
kind!: string; kind!: string;
metadata!: KubeObjectMetadata<Namespaced>; metadata!: Metadata;
status?: Status; status?: Status;
spec!: Spec; spec!: Spec;
@ -393,7 +398,7 @@ export class KubeObject<
return new KubeObject(data); return new KubeObject(data);
} }
static isNonSystem(item: KubeJsonApiData | KubeObject<unknown, unknown, KubeObjectScope>) { static isNonSystem(item: KubeJsonApiData | KubeObject<KubeObjectMetadata<KubeObjectScope>, unknown, unknown>) {
return !item.metadata.name?.startsWith("system:"); return !item.metadata.name?.startsWith("system:");
} }
@ -488,7 +493,7 @@ export class KubeObject<
...KubeObject.nonEditablePathPrefixes, ...KubeObject.nonEditablePathPrefixes,
]); ]);
constructor(data: KubeJsonApiData<KubeObjectMetadata<Namespaced>, Status, Spec>) { constructor(data: KubeJsonApiData<Metadata, Status, Spec>) {
if (typeof data !== "object") { if (typeof data !== "object") {
throw new TypeError(`Cannot create a KubeObject from ${typeof data}`); throw new TypeError(`Cannot create a KubeObject from ${typeof data}`);
} }
@ -524,7 +529,7 @@ export class KubeObject<
return this.metadata.name; return this.metadata.name;
} }
getNs(): ScopedNamespace<Namespaced> { getNs(): Metadata["namespace"] {
// avoid "null" serialization via JSON.stringify when post data // avoid "null" serialization via JSON.stringify when post data
return (this.metadata.namespace || undefined) as never; return (this.metadata.namespace || undefined) as never;
} }

View File

@ -25,14 +25,22 @@ export {
export { export {
KubeObject, KubeObject,
KubeStatus, KubeStatus,
type OwnerReference,
type KubeObjectMetadata, type KubeObjectMetadata,
type NamespaceScopedMetadata,
type ClusterScopedMetadata,
type BaseKubeJsonApiObjectMetadata, type BaseKubeJsonApiObjectMetadata,
type KubeJsonApiObjectMetadata, type KubeJsonApiObjectMetadata,
type KubeStatusData, type KubeStatusData,
} from "../../common/k8s-api/kube-object"; } from "../../common/k8s-api/kube-object";
export {
type KubeJsonApiData,
} from "../../common/k8s-api/kube-json-api";
export { export {
KubeObjectStore, KubeObjectStore,
type JsonPatch,
type KubeObjectStoreLoadAllParams, type KubeObjectStoreLoadAllParams,
type KubeObjectStoreLoadingParams, type KubeObjectStoreLoadingParams,
type KubeObjectStoreSubscribeParams, type KubeObjectStoreSubscribeParams,

View File

@ -16,7 +16,7 @@ import { Input } from "../input";
import type { AdditionalPrinterColumnsV1 } from "../../../common/k8s-api/endpoints/custom-resource-definition.api"; import type { AdditionalPrinterColumnsV1 } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/custom-resource-definition.api"; import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
import { convertKubectlJsonPathToNodeJsonPath } from "../../utils/jsonPath"; import { convertKubectlJsonPathToNodeJsonPath } from "../../utils/jsonPath";
import type { KubeObjectStatus } from "../../../common/k8s-api/kube-object"; import type { KubeObjectMetadata, KubeObjectStatus } from "../../../common/k8s-api/kube-object";
import { KubeObject } from "../../../common/k8s-api/kube-object"; import { KubeObject } from "../../../common/k8s-api/kube-object";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import { JSONPath } from "@astronautlabs/jsonpath"; import { JSONPath } from "@astronautlabs/jsonpath";
@ -71,7 +71,8 @@ export class CustomResourceDetails extends React.Component<CustomResourceDetails
)); ));
} }
renderStatus(customResource: KubeObject<KubeObjectStatus, unknown>, columns: AdditionalPrinterColumnsV1[]) { renderStatus(cr: KubeObject, columns: AdditionalPrinterColumnsV1[]) {
const customResource = cr as KubeObject<KubeObjectMetadata, KubeObjectStatus, unknown>;
const showStatus = !columns.find(column => column.name == "Status") && Array.isArray(customResource.status?.conditions); const showStatus = !columns.find(column => column.name == "Status") && Array.isArray(customResource.status?.conditions);
if (!showStatus) { if (!showStatus) {

View File

@ -9,7 +9,7 @@ import type { KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
import { cpuUnitsToNumber, unitsToBytes } from "../../utils"; import { cpuUnitsToNumber, unitsToBytes } from "../../utils";
import type { Pod, PodMetrics, PodApi, PodMetricsApi } from "../../../common/k8s-api/endpoints"; import type { Pod, PodMetrics, PodApi, PodMetricsApi } from "../../../common/k8s-api/endpoints";
import type { KubeObject, KubeObjectScope } from "../../../common/k8s-api/kube-object"; import type { KubeObject, NamespaceScopedMetadata } from "../../../common/k8s-api/kube-object";
export interface PodStoreDependencies { export interface PodStoreDependencies {
readonly podMetricsApi: PodMetricsApi; readonly podMetricsApi: PodMetricsApi;
@ -36,7 +36,7 @@ export class PodStore extends KubeObjectStore<Pod, PodApi> {
} }
} }
getPodsByOwner(workload: KubeObject<unknown, unknown, KubeObjectScope.Namespace>): Pod[] { getPodsByOwner(workload: KubeObject<NamespaceScopedMetadata, unknown, unknown>): Pod[] {
return this.items.filter(pod => ( return this.items.filter(pod => (
pod.getOwnerRefs() pod.getOwnerRefs()
.find(owner => owner.uid === workload.getId()) .find(owner => owner.uid === workload.getId())