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

Replace KubeObject scope strings with enum

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-04-07 08:54:17 -04:00
parent 0e3bf40e21
commit d4e2848f90
35 changed files with 86 additions and 79 deletions

View File

@ -6,17 +6,17 @@ import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
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 } from "../kube-object"; import type { 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";
export interface ClusterRoleBindingData extends KubeJsonApiData<KubeObjectMetadata<"cluster-scoped">, void, void> { export interface ClusterRoleBindingData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Cluster>, void, void> {
subjects?: Subject[]; subjects?: Subject[];
roleRef: RoleRef; roleRef: RoleRef;
} }
export class ClusterRoleBinding extends KubeObject<void, void, "cluster-scoped"> { export class ClusterRoleBinding extends KubeObject<void, void, KubeObjectScope.Cluster> {
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

@ -7,17 +7,17 @@ import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
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 } from "../kube-object"; import type { 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";
export interface ClusterRoleData extends KubeJsonApiData<KubeObjectMetadata<"cluster-scoped">, void, void> { export interface ClusterRoleData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Cluster>, void, void> {
rules?: PolicyRule[]; rules?: PolicyRule[];
aggregationRule?: AggregationRule; aggregationRule?: AggregationRule;
} }
export class ClusterRole extends KubeObject<void, void, "cluster-scoped"> { export class ClusterRole extends KubeObject<void, void, KubeObjectScope.Cluster> {
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 } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope } 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";
@ -11,13 +11,13 @@ import { KubeApi } from "../kube-api";
import { autoBind } from "../../utils"; import { autoBind } from "../../utils";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
data?: Partial<Record<string, string>>; data?: Partial<Record<string, string>>;
binaryData?: Partial<Record<string, string>>; binaryData?: Partial<Record<string, string>>;
immutable?: boolean; immutable?: boolean;
} }
export class ConfigMap extends KubeObject<void, void, "namespace-scoped"> { export class ConfigMap extends KubeObject<void, void, KubeObjectScope.Namespace> {
static kind = "ConfigMap"; static kind = "ConfigMap";
static namespaced = true; static namespaced = true;
static apiBase = "/api/v1/configmaps"; static apiBase = "/api/v1/configmaps";

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 } from "../kube-object"; import type { BaseKubeObjectCondition, 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";
@ -102,7 +102,7 @@ export interface CustomResourceDefinitionStatus {
storedVersions: string[]; storedVersions: string[];
} }
export class CustomResourceDefinition extends KubeObject<CustomResourceDefinitionStatus, CustomResourceDefinitionSpec, "cluster-scoped"> { export class CustomResourceDefinition extends KubeObject<CustomResourceDefinitionStatus, CustomResourceDefinitionSpec, KubeObjectScope.Cluster> {
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

@ -4,7 +4,7 @@
*/ */
import moment from "moment"; import moment from "moment";
import type { ObjectReference } from "../kube-object"; import type { KubeObjectScope, 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";
@ -67,7 +67,7 @@ export interface CronJobStatus {
active?: ObjectReference[]; active?: ObjectReference[];
} }
export class CronJob extends KubeObject<CronJobStatus, CronJobSpec, "namespace-scoped"> { export class CronJob extends KubeObject<CronJobStatus, CronJobSpec, KubeObjectScope.Namespace> {
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

@ -8,7 +8,7 @@ import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pods.api"; import type { PodMetricData } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectScope, KubeObjectStatus, LabelSelector } 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";
@ -42,7 +42,7 @@ export interface DaemonSetStatus extends KubeObjectStatus {
updatedNumberScheduled?: number; updatedNumberScheduled?: number;
} }
export class DaemonSet extends KubeObject<DaemonSetStatus, DaemonSetSpec, "namespace-scoped"> { export class DaemonSet extends KubeObject<DaemonSetStatus, DaemonSetSpec, KubeObjectScope.Namespace> {
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

@ -10,7 +10,7 @@ import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData, PodSpec } from "./pods.api"; import type { PodMetricData, PodSpec } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectScope, KubeObjectStatus, LabelSelector } 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";
@ -117,7 +117,7 @@ export interface DeploymentStatus extends KubeObjectStatus {
unavailableReplicas?: number; unavailableReplicas?: number;
} }
export class Deployment extends KubeObject<DeploymentStatus, DeploymentSpec, "namespace-scoped"> { export class Deployment extends KubeObject<DeploymentStatus, DeploymentSpec, KubeObjectScope.Namespace> {
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, ObjectReference } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, 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";
@ -72,11 +72,11 @@ export interface EndpointSubset {
ports?: EndpointPort[]; ports?: EndpointPort[];
} }
export interface EndpointsData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface EndpointsData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
subsets?: EndpointSubset[]; subsets?: EndpointSubset[];
} }
export class Endpoints extends KubeObject<void, void, "namespace-scoped"> { export class Endpoints extends KubeObject<void, void, KubeObjectScope.Namespace> {
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, LabelSelector } from "../kube-object"; import type { BaseKubeObjectCondition, KubeObjectScope, LabelSelector } 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";
@ -98,7 +98,7 @@ interface MetricCurrentTarget {
target?: string | undefined; target?: string | undefined;
} }
export class HorizontalPodAutoscaler extends KubeObject<HorizontalPodAutoscalerStatus, HorizontalPodAutoscalerSpec, "namespace-scoped"> { export class HorizontalPodAutoscaler extends KubeObject<HorizontalPodAutoscalerStatus, HorizontalPodAutoscalerSpec, KubeObjectScope.Namespace> {
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 { TypedLocalObjectReference } from "../kube-object"; import type { KubeObjectScope, 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";
@ -141,7 +141,7 @@ export interface IngressStatus {
}; };
} }
export class Ingress extends KubeObject<IngressStatus, IngressSpec, "namespace-scoped"> { export class Ingress extends KubeObject<IngressStatus, IngressSpec, KubeObjectScope.Namespace> {
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

@ -8,7 +8,7 @@ import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { IPodContainer, PodMetricData, PodSpec } from "./pods.api"; import type { IPodContainer, PodMetricData, PodSpec } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
export interface JobSpec { export interface JobSpec {
@ -39,7 +39,7 @@ export interface JobStatus extends KubeObjectStatus {
succeeded: number; succeeded: number;
} }
export class Job extends KubeObject<JobStatus, JobSpec, "namespace-scoped"> { export class Job extends KubeObject<JobStatus, JobSpec, KubeObjectScope.Namespace> {
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,6 +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 { 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 +40,7 @@ export interface LimitRangeSpec {
limits: LimitRangeItem[]; limits: LimitRangeItem[];
} }
export class LimitRange extends KubeObject<void, LimitRangeSpec, "namespace-scoped"> { export class LimitRange extends KubeObject<void, LimitRangeSpec, KubeObjectScope.Namespace> {
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

@ -4,7 +4,7 @@
*/ */
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { KubeObjectStatus } from "../kube-object"; import type { KubeObjectScope, 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 "./pods.api"; import type { PodMetricData } from "./pods.api";
@ -23,7 +23,7 @@ export interface NamespaceStatus extends KubeObjectStatus {
phase?: string; phase?: string;
} }
export class Namespace extends KubeObject<NamespaceStatus, NamespaceSpec, "cluster-scoped"> { export class Namespace extends KubeObject<NamespaceStatus, NamespaceSpec, KubeObjectScope.Cluster> {
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 { LabelSelector } from "../kube-object"; import type { KubeObjectScope, LabelSelector } 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";
@ -104,7 +104,7 @@ export interface NetworkPolicy {
spec: NetworkPolicySpec; spec: NetworkPolicySpec;
} }
export class NetworkPolicy extends KubeObject<void, NetworkPolicySpec, "namespace-scoped"> { 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 } from "../kube-object"; import type { BaseKubeObjectCondition, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { cpuUnitsToNumber, unitsToBytes } from "../../../renderer/utils"; import { cpuUnitsToNumber, unitsToBytes } from "../../../renderer/utils";
import type { MetricData } from "./metrics.api"; import type { MetricData } from "./metrics.api";
@ -166,7 +166,7 @@ export interface NodeStatus {
volumesAttached?: AttachedVolume[]; volumesAttached?: AttachedVolume[];
} }
export class Node extends KubeObject<NodeStatus, NodeSpec, "cluster-scoped"> { export class Node extends KubeObject<NodeStatus, NodeSpec, KubeObjectScope.Cluster> {
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 { LabelSelector, TypedLocalObjectReference } from "../kube-object"; import type { KubeObjectScope, LabelSelector, 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";
@ -54,7 +54,7 @@ export interface PersistentVolumeClaimStatus {
phase: string; // Pending phase: string; // Pending
} }
export class PersistentVolumeClaim extends KubeObject<PersistentVolumeClaimStatus, PersistentVolumeClaimSpec, "namespace-scoped"> { export class PersistentVolumeClaim extends KubeObject<PersistentVolumeClaimStatus, PersistentVolumeClaimSpec, KubeObjectScope.Namespace> {
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 { LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object"; import type { KubeObjectScope, 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";
@ -65,7 +65,7 @@ export interface PersistentVolumeStatus {
reason?: string; reason?: string;
} }
export class PersistentVolume extends KubeObject<PersistentVolumeStatus, PersistentVolumeSpec, "cluster-scoped"> { export class PersistentVolume extends KubeObject<PersistentVolumeStatus, PersistentVolumeSpec, KubeObjectScope.Cluster> {
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,14 +3,14 @@
* 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 } from "../kube-object"; import type { 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";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
export interface PodMetricsData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface PodMetricsData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
timestamp: string; timestamp: string;
window: string; window: string;
containers: PodMetricsContainer[]; containers: PodMetricsContainer[];
@ -26,7 +26,7 @@ export interface PodMetricsContainer {
usage: PodMetricsContainerUsage; usage: PodMetricsContainerUsage;
} }
export class PodMetrics extends KubeObject<void, void, "namespace-scoped"> { export class PodMetrics extends KubeObject<void, void, KubeObjectScope.Namespace> {
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 { LabelSelector } from "../kube-object"; import type { KubeObjectScope, LabelSelector } 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";
@ -22,7 +22,7 @@ export interface PodDisruptionBudgetStatus {
expectedPods: number; expectedPods: number;
} }
export class PodDisruptionBudget extends KubeObject<PodDisruptionBudgetStatus, PodDisruptionBudgetSpec, "namespace-scoped"> { export class PodDisruptionBudget extends KubeObject<PodDisruptionBudgetStatus, PodDisruptionBudgetSpec, KubeObjectScope.Namespace> {
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

@ -9,7 +9,7 @@ import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { RequireExactlyOne } from "type-fest"; import type { RequireExactlyOne } from "type-fest";
import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, LabelSelector } from "../kube-object"; import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, LabelSelector, KubeObjectScope } from "../kube-object";
import type { SecretReference } from "./secret.api"; import type { SecretReference } from "./secret.api";
import type { PersistentVolumeClaimSpec } from "./persistent-volume-claims.api"; import type { PersistentVolumeClaimSpec } from "./persistent-volume-claims.api";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
@ -759,7 +759,7 @@ export interface PodStatus {
reason?: string; reason?: string;
} }
export class Pod extends KubeObject<PodStatus, PodSpec, "namespace-scoped"> { export class Pod extends KubeObject<PodStatus, PodSpec, KubeObjectScope.Namespace> {
static kind = "Pod"; static kind = "Pod";
static namespaced = true; static namespaced = true;
static apiBase = "/api/v1/pods"; static apiBase = "/api/v1/pods";

View File

@ -3,6 +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 { 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 +81,7 @@ export interface PodSecurityPolicySpec {
volumes?: string[]; volumes?: string[];
} }
export class PodSecurityPolicy extends KubeObject<void, PodSecurityPolicySpec, "cluster-scoped"> { export class PodSecurityPolicy extends KubeObject<void, PodSecurityPolicySpec, KubeObjectScope.Cluster> {
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 { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pods.api"; import type { PodMetricData } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectScope, KubeObjectStatus, LabelSelector } 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";
@ -74,7 +74,7 @@ export interface ReplicaSetStatus extends KubeObjectStatus {
observedGeneration?: number; observedGeneration?: number;
} }
export class ReplicaSet extends KubeObject<ReplicaSetStatus, ReplicaSetSpec, "namespace-scoped"> { export class ReplicaSet extends KubeObject<ReplicaSetStatus, ReplicaSetSpec, KubeObjectScope.Namespace> {
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,6 +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 { 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 +51,7 @@ export interface ResourceQuotaStatus {
used: IResourceQuotaValues; used: IResourceQuotaValues;
} }
export class ResourceQuota extends KubeObject<ResourceQuotaStatus, ResourceQuotaSpec, "namespace-scoped"> { export class ResourceQuota extends KubeObject<ResourceQuotaStatus, ResourceQuotaSpec, KubeObjectScope.Namespace> {
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 } from "../kube-object"; import type { 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";
@ -12,12 +12,12 @@ import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
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";
export interface RoleBindingData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface RoleBindingData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
subjects?: Subject[]; subjects?: Subject[];
roleRef: RoleRef; roleRef: RoleRef;
} }
export class RoleBinding extends KubeObject<void, void, "namespace-scoped"> { export class RoleBinding extends KubeObject<void, void, KubeObjectScope.Namespace> {
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 } from "../kube-object"; import type { 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";
@ -11,11 +11,11 @@ import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import type { PolicyRule } from "./types/policy-rule"; import type { PolicyRule } from "./types/policy-rule";
export interface RoleData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface RoleData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
rules?: PolicyRule[]; rules?: PolicyRule[];
} }
export class Role extends KubeObject<void, void, "namespace-scoped"> { export class Role extends KubeObject<void, void, KubeObjectScope.Namespace> {
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 } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope } 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";
@ -27,12 +27,12 @@ export interface SecretReference {
namespace?: string; namespace?: string;
} }
export interface SecretData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface SecretData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
type: SecretType; type: SecretType;
data?: Partial<Record<string, string>>; data?: Partial<Record<string, string>>;
} }
export class Secret extends KubeObject<void, void, "namespace-scoped"> { export class Secret extends KubeObject<void, void, KubeObjectScope.Namespace> {
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,20 +3,20 @@
* 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, LocalObjectReference, ObjectReference } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, LocalObjectReference, 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";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
export interface ServiceAccountData extends KubeJsonApiData<KubeObjectMetadata<"namespace-scoped">, void, void> { export interface ServiceAccountData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
automountServiceAccountToken?: boolean; automountServiceAccountToken?: boolean;
imagePullSecrets?: LocalObjectReference[]; imagePullSecrets?: LocalObjectReference[];
secrets?: ObjectReference[]; secrets?: ObjectReference[];
} }
export class ServiceAccount extends KubeObject<void, void, "namespace-scoped"> { export class ServiceAccount extends KubeObject<void, void, KubeObjectScope.Namespace> {
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,6 +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 { 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 +61,7 @@ export interface ServiceStatus {
}; };
} }
export class Service extends KubeObject<ServiceStatus, ServiceSpec, "namespace-scoped"> { export class Service extends KubeObject<ServiceStatus, ServiceSpec, KubeObjectScope.Namespace> {
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

@ -8,7 +8,7 @@ import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pods.api"; import type { PodMetricData } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { LabelSelector } from "../kube-object"; import type { KubeObjectScope, LabelSelector } 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";
@ -82,7 +82,7 @@ export interface StatefulSetStatus {
collisionCount: number; collisionCount: number;
} }
export class StatefulSet extends KubeObject<StatefulSetStatus, StatefulSetSpec, "namespace-scoped"> { export class StatefulSet extends KubeObject<StatefulSetStatus, StatefulSetSpec, KubeObjectScope.Namespace> {
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 } from "../kube-object"; import type { 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";
@ -20,7 +20,7 @@ export interface TopologySelectorTerm {
matchLabelExpressions?: TopologySelectorLabelRequirement[]; matchLabelExpressions?: TopologySelectorLabelRequirement[];
} }
export interface StorageClassData extends KubeJsonApiData<KubeObjectMetadata<"cluster-scoped">, void, void> { export interface StorageClassData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Cluster>, void, void> {
allowVolumeExpansion?: boolean; allowVolumeExpansion?: boolean;
allowedTopologies?: TopologySelectorTerm[]; allowedTopologies?: TopologySelectorTerm[];
mountOptions?: string[]; mountOptions?: string[];
@ -30,7 +30,7 @@ export interface StorageClassData extends KubeJsonApiData<KubeObjectMetadata<"cl
volumeBindingMode?: string; volumeBindingMode?: string;
} }
export class StorageClass extends KubeObject<void, void, "cluster-scoped"> { export class StorageClass extends KubeObject<void, void, KubeObjectScope.Cluster> {
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

@ -3,10 +3,10 @@
* 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 { KubeTemplateObjectMetadata } from "../../kube-object"; import type { KubeObjectScope, KubeTemplateObjectMetadata } from "../../kube-object";
import type { JobSpec } from "../job.api"; import type { JobSpec } from "../job.api";
export interface JobTemplateSpec { export interface JobTemplateSpec {
metadata?: KubeTemplateObjectMetadata<"namespace-scoped">; metadata?: KubeTemplateObjectMetadata<KubeObjectScope.Namespace>;
spec?: JobSpec; spec?: JobSpec;
} }

View File

@ -3,10 +3,10 @@
* 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 { KubeTemplateObjectMetadata } from "../../kube-object"; import type { KubeObjectScope, KubeTemplateObjectMetadata } from "../../kube-object";
import type { PersistentVolumeSpec } from "../persistent-volume.api"; import type { PersistentVolumeSpec } from "../persistent-volume.api";
export interface PersistentVolumeClaimTemplateSpec { export interface PersistentVolumeClaimTemplateSpec {
metadata?: KubeTemplateObjectMetadata<"cluster-scoped">; metadata?: KubeTemplateObjectMetadata<KubeObjectScope.Cluster>;
spec?: PersistentVolumeSpec; spec?: PersistentVolumeSpec;
} }

View File

@ -3,10 +3,10 @@
* 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 { KubeTemplateObjectMetadata } from "../../kube-object"; import type { KubeObjectScope, KubeTemplateObjectMetadata } from "../../kube-object";
import type { PodSpec } from "../pods.api"; import type { PodSpec } from "../pods.api";
export interface PodTemplateSpec { export interface PodTemplateSpec {
metadata?: KubeTemplateObjectMetadata<"namespace-scoped">; metadata?: KubeTemplateObjectMetadata<KubeObjectScope.Namespace>;
spec?: PodSpec; spec?: PodSpec;
} }

View File

@ -200,8 +200,8 @@ interface BaseKubeJsonApiObjectMetadata<Namespaced extends KubeObjectScope> {
[key: string]: unknown; [key: string]: unknown;
} }
export type KubeJsonApiObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = Namespaced extends "namespace-scoped" export type KubeJsonApiObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = Namespaced extends KubeObjectScope.Namespace
? BaseKubeJsonApiObjectMetadata<"namespace-scoped"> & { readonly namespace: string } ? BaseKubeJsonApiObjectMetadata<KubeObjectScope.Namespace> & { readonly namespace: string }
: BaseKubeJsonApiObjectMetadata<Namespaced>; : BaseKubeJsonApiObjectMetadata<Namespaced>;
export type KubeObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = KubeJsonApiObjectMetadata<Namespaced> & { export type KubeObjectMetadata<Namespaced extends KubeObjectScope = KubeObjectScope> = KubeJsonApiObjectMetadata<Namespaced> & {
@ -359,11 +359,14 @@ export interface LabelSelector {
matchExpressions?: LabelMatchExpression[]; matchExpressions?: LabelMatchExpression[];
} }
export type KubeObjectScope = "namespace-scoped" | "cluster-scoped"; export enum KubeObjectScope {
Namespace,
Cluster,
}
export type ScopedNamespace<Namespaced extends KubeObjectScope> = ( export type ScopedNamespace<Namespaced extends KubeObjectScope> = (
Namespaced extends "namespace-scoped" Namespaced extends KubeObjectScope.Namespace
? string ? string
: Namespaced extends "cluster-scoped" : Namespaced extends KubeObjectScope.Cluster
? undefined ? undefined
: string | undefined : string | undefined
); );

View File

@ -10,7 +10,7 @@ import { cpuUnitsToNumber, isClusterPageContext, unitsToBytes } from "../../util
import type { Pod, PodMetrics, PodApi } from "../../../common/k8s-api/endpoints"; import type { Pod, PodMetrics, PodApi } from "../../../common/k8s-api/endpoints";
import { podMetricsApi, podApi } from "../../../common/k8s-api/endpoints"; import { podMetricsApi, podApi } from "../../../common/k8s-api/endpoints";
import { apiManager } from "../../../common/k8s-api/api-manager"; import { apiManager } from "../../../common/k8s-api/api-manager";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject, KubeObjectScope } from "../../../common/k8s-api/kube-object";
export class PodsStore extends KubeObjectStore<Pod, PodApi> { export class PodsStore extends KubeObjectStore<Pod, PodApi> {
readonly kubeMetrics = observable.array<PodMetrics>([]); readonly kubeMetrics = observable.array<PodMetrics>([]);
@ -25,7 +25,7 @@ export class PodsStore extends KubeObjectStore<Pod, PodApi> {
} }
} }
getPodsByOwner(workload: KubeObject<any, any, "namespace-scoped">): Pod[] { getPodsByOwner(workload: KubeObject<unknown, unknown, KubeObjectScope.Namespace>): 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())