From 0b1f1fc10d89872efd6cf05f6387497092437a09 Mon Sep 17 00:00:00 2001 From: Oleksandr Dubenko Date: Fri, 11 Oct 2024 16:34:45 +0200 Subject: [PATCH] frontend: Create apiEndpoint using existing apiName and apiVersion information Signed-off-by: Oleksandr Dubenko --- frontend/src/lib/k8s/KubeObject.ts | 62 ++++++++++++++----- frontend/src/lib/k8s/clusterRole.ts | 3 - frontend/src/lib/k8s/clusterRoleBinding.ts | 3 - frontend/src/lib/k8s/configMap.ts | 3 - frontend/src/lib/k8s/crd.ts | 4 -- frontend/src/lib/k8s/cronJob.ts | 6 -- frontend/src/lib/k8s/daemonSet.ts | 3 - frontend/src/lib/k8s/deployment.ts | 3 - frontend/src/lib/k8s/endpoints.ts | 3 - frontend/src/lib/k8s/event.ts | 4 +- frontend/src/lib/k8s/hpa.ts | 3 - frontend/src/lib/k8s/ingress.ts | 5 -- frontend/src/lib/k8s/ingressClass.ts | 3 - frontend/src/lib/k8s/job.ts | 3 - frontend/src/lib/k8s/lease.ts | 3 - frontend/src/lib/k8s/limitRange.tsx | 3 - .../lib/k8s/mutatingWebhookConfiguration.ts | 7 --- frontend/src/lib/k8s/namespace.ts | 3 - frontend/src/lib/k8s/networkpolicy.tsx | 3 - frontend/src/lib/k8s/node.ts | 4 +- frontend/src/lib/k8s/persistentVolume.ts | 3 - frontend/src/lib/k8s/persistentVolumeClaim.ts | 3 - frontend/src/lib/k8s/pod.ts | 3 +- frontend/src/lib/k8s/podDisruptionBudget.ts | 3 - frontend/src/lib/k8s/priorityClass.ts | 7 +-- frontend/src/lib/k8s/replicaSet.ts | 3 - frontend/src/lib/k8s/resourceQuota.ts | 3 - frontend/src/lib/k8s/role.ts | 3 - frontend/src/lib/k8s/roleBinding.ts | 3 - frontend/src/lib/k8s/runtime.ts | 3 - frontend/src/lib/k8s/secret.ts | 3 - frontend/src/lib/k8s/service.ts | 3 - frontend/src/lib/k8s/serviceAccount.ts | 3 - frontend/src/lib/k8s/statefulSet.ts | 3 - frontend/src/lib/k8s/storageClass.ts | 3 - .../lib/k8s/validatingWebhookConfiguration.ts | 7 --- frontend/src/lib/k8s/vpa.ts | 7 --- 37 files changed, 51 insertions(+), 143 deletions(-) diff --git a/frontend/src/lib/k8s/KubeObject.ts b/frontend/src/lib/k8s/KubeObject.ts index 3bb93c4f4f8..d43cb8c6523 100644 --- a/frontend/src/lib/k8s/KubeObject.ts +++ b/frontend/src/lib/k8s/KubeObject.ts @@ -23,13 +23,47 @@ function getAllowedNamespaces() { } export class KubeObject { - static apiEndpoint: ReturnType; - static readOnlyFields: string[] = []; - static objectName: string; - jsonData: T; + /** Readonly field defined as JSONPath paths */ + static readOnlyFields: string[] = []; _clusterName: string; + /** The kind of the object. Corresponding to the resource kind in Kubernetes. */ + static readonly kind: string; + + /** Name of the resource, plural, used in API */ + static readonly apiName: string; + + /** Group and version of the resource formatted as "GROUP/VERSION", e.g. "policy.k8s.io/v1". */ + static readonly apiVersion: string | string[]; + + /** Whether the object is namespaced. */ + static readonly isNamespaced: boolean; + + static _internalApiEndpoint?: ReturnType; + + static get apiEndpoint() { + if (this._internalApiEndpoint) return this._internalApiEndpoint; + + const factory = this.isNamespaced ? apiFactoryWithNamespace : apiFactory; + const versions = Array.isArray(this.apiVersion) ? this.apiVersion : [this.apiVersion]; + + const factoryArguments = versions.map(apiVersion => { + const [group, version] = apiVersion.includes('/') ? apiVersion.split('/') : ['', apiVersion]; + const includeScaleApi = ['Deployment', 'ReplicaSet', 'StatefulSet'].includes(this.kind); + + return [group, version, this.apiName, includeScaleApi]; + }); + + const endpoint = factory(...(factoryArguments as any)); + this._internalApiEndpoint = endpoint; + + return endpoint; + } + static set apiEndpoint(endpoint: ReturnType) { + this._internalApiEndpoint = endpoint; + } + constructor(json: T, cluster?: string) { this.jsonData = json; this._clusterName = cluster || getCluster() || ''; @@ -44,7 +78,7 @@ export class KubeObject { } static get className(): string { - return this.objectName; + return this.kind; } get detailsRoute(): string { @@ -52,13 +86,13 @@ export class KubeObject { } static get detailsRoute(): string { - return this.className; + return this.kind; } static get pluralName(): string { // This is a naive way to get the plural name of the object by default. It will // work in most cases, but for exceptions (like Ingress), we must override this. - return this.className.toLowerCase() + 's'; + return this.apiName; } get pluralName(): string { @@ -71,7 +105,11 @@ export class KubeObject { } static get listRoute(): string { - return this.detailsRoute + 's'; + return this.apiName; + } + + get kind() { + return this.jsonData.kind; } getDetailsLink() { @@ -111,18 +149,10 @@ export class KubeObject { return this.jsonData.metadata; } - get kind() { - return this.jsonData.kind; - } - get isNamespaced() { return this._class().isNamespaced; } - static get isNamespaced() { - return this.apiEndpoint.isNamespaced; - } - getEditableObject() { const fieldsToRemove = this._class().readOnlyFields; const code = this.jsonData ? cloneDeep(this.jsonData) : {}; diff --git a/frontend/src/lib/k8s/clusterRole.ts b/frontend/src/lib/k8s/clusterRole.ts index 09a400c4386..f9f4e040faa 100644 --- a/frontend/src/lib/k8s/clusterRole.ts +++ b/frontend/src/lib/k8s/clusterRole.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { makeKubeObject } from './KubeObject'; import { KubeRole } from './role'; @@ -8,8 +7,6 @@ class ClusterRole extends makeKubeObject() { static apiVersion = 'rbac.authorization.k8s.io/v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterroles'); - get rules() { return this.jsonData!.rules; } diff --git a/frontend/src/lib/k8s/clusterRoleBinding.ts b/frontend/src/lib/k8s/clusterRoleBinding.ts index 085d4a907b1..a1411cd52a4 100644 --- a/frontend/src/lib/k8s/clusterRoleBinding.ts +++ b/frontend/src/lib/k8s/clusterRoleBinding.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { makeKubeObject } from './KubeObject'; import { KubeRoleBinding } from './roleBinding'; @@ -8,8 +7,6 @@ class ClusterRoleBinding extends makeKubeObject() { static apiVersion = 'rbac.authorization.k8s.io/v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterrolebindings'); - get roleRef() { return this.jsonData!.roleRef; } diff --git a/frontend/src/lib/k8s/configMap.ts b/frontend/src/lib/k8s/configMap.ts index b5be7230fd6..5609fd98cf5 100644 --- a/frontend/src/lib/k8s/configMap.ts +++ b/frontend/src/lib/k8s/configMap.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { StringDict } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -12,8 +11,6 @@ class ConfigMap extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'configmaps'); - get data() { return this.jsonData.data; } diff --git a/frontend/src/lib/k8s/crd.ts b/frontend/src/lib/k8s/crd.ts index 456c46a1ab4..1df833b5712 100644 --- a/frontend/src/lib/k8s/crd.ts +++ b/frontend/src/lib/k8s/crd.ts @@ -55,10 +55,6 @@ class CustomResourceDefinition extends KubeObject { static apiVersion = ['apiextensions.k8s.io/v1', 'apiextensions.k8s.io/v1beta1']; static isNamespaced = false; - static apiEndpoint = apiFactory( - ['apiextensions.k8s.io', 'v1', 'customresourcedefinitions'], - ['apiextensions.k8s.io', 'v1beta1', 'customresourcedefinitions'] - ); static readOnlyFields = ['metadata.managedFields']; static get listRoute(): string { diff --git a/frontend/src/lib/k8s/cronJob.ts b/frontend/src/lib/k8s/cronJob.ts index d22f036755e..36a108cd220 100644 --- a/frontend/src/lib/k8s/cronJob.ts +++ b/frontend/src/lib/k8s/cronJob.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeContainer } from './cluster'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -42,11 +41,6 @@ class CronJob extends KubeObject { static apiVersion = ['batch/v1', 'batch/v1beta1']; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace( - ['batch', 'v1', 'cronjobs'], - ['batch', 'v1beta1', 'cronjobs'] - ); - get spec() { return this.getValue('spec'); } diff --git a/frontend/src/lib/k8s/daemonSet.ts b/frontend/src/lib/k8s/daemonSet.ts index 41be0145f26..da4088da3c7 100644 --- a/frontend/src/lib/k8s/daemonSet.ts +++ b/frontend/src/lib/k8s/daemonSet.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeContainer, LabelSelector } from './cluster'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -30,8 +29,6 @@ class DaemonSet extends KubeObject { static apiVersion = 'apps/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('apps', 'v1', 'daemonsets'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/deployment.ts b/frontend/src/lib/k8s/deployment.ts index d2574391df0..4632392f159 100644 --- a/frontend/src/lib/k8s/deployment.ts +++ b/frontend/src/lib/k8s/deployment.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeContainer, LabelSelector } from './cluster'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -28,8 +27,6 @@ class Deployment extends KubeObject { static apiVersion = 'apps/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('apps', 'v1', 'deployments', true); - get spec() { return this.getValue('spec'); } diff --git a/frontend/src/lib/k8s/endpoints.ts b/frontend/src/lib/k8s/endpoints.ts index 1c9730187cc..90237b605df 100644 --- a/frontend/src/lib/k8s/endpoints.ts +++ b/frontend/src/lib/k8s/endpoints.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -35,8 +34,6 @@ class Endpoints extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'endpoints'); - // @todo Remove this when we can break backward compatibility. static get detailsRoute() { return 'Endpoint'; diff --git a/frontend/src/lib/k8s/event.ts b/frontend/src/lib/k8s/event.ts index d520c6f06cc..28670357604 100644 --- a/frontend/src/lib/k8s/event.ts +++ b/frontend/src/lib/k8s/event.ts @@ -1,6 +1,6 @@ import { useMemo } from 'react'; import { ResourceClasses } from '.'; -import { ApiError, apiFactoryWithNamespace, QueryParameters } from './apiProxy'; +import { ApiError, QueryParameters } from './apiProxy'; import { request } from './apiProxy'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject } from './KubeObject'; @@ -30,8 +30,6 @@ class Event extends KubeObject { static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'events'); - // Max number of events to fetch from the API private static maxEventsLimit = 2000; diff --git a/frontend/src/lib/k8s/hpa.ts b/frontend/src/lib/k8s/hpa.ts index d640f39423d..95cc5518b72 100644 --- a/frontend/src/lib/k8s/hpa.ts +++ b/frontend/src/lib/k8s/hpa.ts @@ -1,5 +1,4 @@ import { ResourceClasses } from '.'; -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectClass, KubeObjectInterface } from './KubeObject'; export interface CrossVersionObjectReference { @@ -173,8 +172,6 @@ class HPA extends KubeObject { static apiVersion = 'autoscaling/v2'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('autoscaling', 'v2', 'horizontalpodautoscalers'); - get spec(): HpaSpec { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/ingress.ts b/frontend/src/lib/k8s/ingress.ts index e3564fe85d4..ca4c9139827 100644 --- a/frontend/src/lib/k8s/ingress.ts +++ b/frontend/src/lib/k8s/ingress.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; interface LegacyIngressRule { @@ -74,10 +73,6 @@ class Ingress extends KubeObject { static apiVersion = ['networking.k8s.io/v1', 'extensions/v1beta1']; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace( - ['networking.k8s.io', 'v1', 'ingresses'], - ['extensions', 'v1beta1', 'ingresses'] - ); // Normalized, cached rules. private cachedRules: IngressRule[] = []; diff --git a/frontend/src/lib/k8s/ingressClass.ts b/frontend/src/lib/k8s/ingressClass.ts index 13ebcf62bc1..bb16021d2af 100644 --- a/frontend/src/lib/k8s/ingressClass.ts +++ b/frontend/src/lib/k8s/ingressClass.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeIngressClass extends KubeObjectInterface { @@ -14,8 +13,6 @@ class IngressClass extends KubeObject { static apiVersion = 'networking.k8s.io/v1'; static isNamespaced = false; - static apiEndpoint = apiFactory(['networking.k8s.io', 'v1', 'ingressclasses']); - get spec(): KubeIngressClass['spec'] { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/job.ts b/frontend/src/lib/k8s/job.ts index 7d722e1d23a..1d71a2226cc 100644 --- a/frontend/src/lib/k8s/job.ts +++ b/frontend/src/lib/k8s/job.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeContainer, LabelSelector } from './cluster'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -24,8 +23,6 @@ class Job extends KubeObject { static apiVersion = 'batch/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('batch', 'v1', 'jobs'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/lease.ts b/frontend/src/lib/k8s/lease.ts index f66f3e63dac..954f290f6f4 100644 --- a/frontend/src/lib/k8s/lease.ts +++ b/frontend/src/lib/k8s/lease.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface LeaseSpec { @@ -18,8 +17,6 @@ export class Lease extends KubeObject { static apiVersion = 'coordination.k8s.io/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('coordination.k8s.io', 'v1', 'leases'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/limitRange.tsx b/frontend/src/lib/k8s/limitRange.tsx index 87c9039fcf8..1380374c19e 100644 --- a/frontend/src/lib/k8s/limitRange.tsx +++ b/frontend/src/lib/k8s/limitRange.tsx @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface LimitRangeSpec { @@ -33,8 +32,6 @@ export class LimitRange extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'limitranges'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/mutatingWebhookConfiguration.ts b/frontend/src/lib/k8s/mutatingWebhookConfiguration.ts index dfd6ce065ba..d939d7782b0 100644 --- a/frontend/src/lib/k8s/mutatingWebhookConfiguration.ts +++ b/frontend/src/lib/k8s/mutatingWebhookConfiguration.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { LabelSelector } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -49,12 +48,6 @@ class MutatingWebhookConfiguration extends KubeObject { static apiVersion = 'v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('', 'v1', 'namespaces'); - get status() { return this.jsonData.status; } diff --git a/frontend/src/lib/k8s/networkpolicy.tsx b/frontend/src/lib/k8s/networkpolicy.tsx index a2313efa57b..b061a8fc943 100644 --- a/frontend/src/lib/k8s/networkpolicy.tsx +++ b/frontend/src/lib/k8s/networkpolicy.tsx @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { LabelSelector } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -42,8 +41,6 @@ class NetworkPolicy extends KubeObject { static apiVersion = 'networking.k8s.io/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('networking.k8s.io', 'v1', 'networkpolicies'); - static get pluralName() { return 'networkpolicies'; } diff --git a/frontend/src/lib/k8s/node.ts b/frontend/src/lib/k8s/node.ts index 2fbac10f9ce..e993390f9f8 100644 --- a/frontend/src/lib/k8s/node.ts +++ b/frontend/src/lib/k8s/node.ts @@ -1,7 +1,7 @@ import React from 'react'; import { useErrorState } from '../util'; import { useConnectApi } from '.'; -import { ApiError, apiFactory, metrics } from './apiProxy'; +import { ApiError, metrics } from './apiProxy'; import { KubeCondition, KubeMetrics } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -59,8 +59,6 @@ class Node extends KubeObject { static apiVersion = 'v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('', 'v1', 'nodes'); - get status(): KubeNode['status'] { return this.jsonData.status; } diff --git a/frontend/src/lib/k8s/persistentVolume.ts b/frontend/src/lib/k8s/persistentVolume.ts index 32b4704b367..e442bde0f95 100644 --- a/frontend/src/lib/k8s/persistentVolume.ts +++ b/frontend/src/lib/k8s/persistentVolume.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubePersistentVolume extends KubeObjectInterface { @@ -21,8 +20,6 @@ class PersistentVolume extends KubeObject { static apiVersion = 'v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('', 'v1', 'persistentvolumes'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/persistentVolumeClaim.ts b/frontend/src/lib/k8s/persistentVolumeClaim.ts index cfc9bd3e968..9a366729dbc 100644 --- a/frontend/src/lib/k8s/persistentVolumeClaim.ts +++ b/frontend/src/lib/k8s/persistentVolumeClaim.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubePersistentVolumeClaim extends KubeObjectInterface { @@ -32,8 +31,6 @@ class PersistentVolumeClaim extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'persistentvolumeclaims'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/pod.ts b/frontend/src/lib/k8s/pod.ts index 2f985ed874d..84f1c7fc98b 100644 --- a/frontend/src/lib/k8s/pod.ts +++ b/frontend/src/lib/k8s/pod.ts @@ -1,5 +1,5 @@ import { Base64 } from 'js-base64'; -import { apiFactoryWithNamespace, stream, StreamArgs, StreamResultsCb } from './apiProxy'; +import { stream, StreamArgs, StreamResultsCb } from './apiProxy'; import { KubeCondition, KubeContainer, KubeContainerStatus, Time } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -90,7 +90,6 @@ class Pod extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'pods'); protected detailedStatusCache: Partial<{ resourceVersion: string; details: PodDetailedStatus }>; constructor(jsonData: KubePod) { diff --git a/frontend/src/lib/k8s/podDisruptionBudget.ts b/frontend/src/lib/k8s/podDisruptionBudget.ts index 25b8d862209..e88b2228993 100644 --- a/frontend/src/lib/k8s/podDisruptionBudget.ts +++ b/frontend/src/lib/k8s/podDisruptionBudget.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubePDB extends KubeObjectInterface { @@ -42,8 +41,6 @@ class PDB extends KubeObject { static apiVersion = 'policy/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace(['policy', 'v1', 'poddisruptionbudgets']); - get spec(): KubePDB['spec'] { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/priorityClass.ts b/frontend/src/lib/k8s/priorityClass.ts index db2edce8562..03a417f775d 100644 --- a/frontend/src/lib/k8s/priorityClass.ts +++ b/frontend/src/lib/k8s/priorityClass.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubePriorityClass extends KubeObjectInterface { @@ -14,10 +13,8 @@ class PriorityClass extends KubeObject { static apiVersion = 'scheduling.k8s.io/v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('scheduling.k8s.io', 'v1', 'priorityclasses'); - - get value(): string { - return String(this.jsonData!.value); + get value(): number { + return this.jsonData!.value; } get globalDefault(): boolean | null { diff --git a/frontend/src/lib/k8s/replicaSet.ts b/frontend/src/lib/k8s/replicaSet.ts index a999a562dd9..a20fc2b5246 100644 --- a/frontend/src/lib/k8s/replicaSet.ts +++ b/frontend/src/lib/k8s/replicaSet.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeCondition, KubeContainer, LabelSelector } from './cluster'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -31,8 +30,6 @@ class ReplicaSet extends KubeObject { static apiVersion = 'apps/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('apps', 'v1', 'replicasets', true); - get spec(): KubeReplicaSet['spec'] { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/resourceQuota.ts b/frontend/src/lib/k8s/resourceQuota.ts index ec3dbe764c9..553f88fe889 100644 --- a/frontend/src/lib/k8s/resourceQuota.ts +++ b/frontend/src/lib/k8s/resourceQuota.ts @@ -1,5 +1,4 @@ import { normalizeUnit } from '../util'; -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; interface spec { @@ -36,8 +35,6 @@ class ResourceQuota extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'resourcequotas'); - get spec(): spec { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/role.ts b/frontend/src/lib/k8s/role.ts index d4d3671eaba..1b187068cbb 100644 --- a/frontend/src/lib/k8s/role.ts +++ b/frontend/src/lib/k8s/role.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeRole extends KubeObjectInterface { @@ -17,8 +16,6 @@ class Role extends KubeObject { static apiVersion = 'rbac.authorization.k8s.io/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('rbac.authorization.k8s.io', 'v1', 'roles'); - get rules() { return this.jsonData.rules; } diff --git a/frontend/src/lib/k8s/roleBinding.ts b/frontend/src/lib/k8s/roleBinding.ts index 03a7f62eef4..87feef388ff 100644 --- a/frontend/src/lib/k8s/roleBinding.ts +++ b/frontend/src/lib/k8s/roleBinding.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeRoleBinding extends KubeObjectInterface { @@ -21,8 +20,6 @@ class RoleBinding extends KubeObject { static apiVersion = 'rbac.authorization.k8s.io/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('rbac.authorization.k8s.io', 'v1', 'rolebindings'); - get roleRef() { return this.jsonData.roleRef; } diff --git a/frontend/src/lib/k8s/runtime.ts b/frontend/src/lib/k8s/runtime.ts index d966437b99c..9d97aeec257 100644 --- a/frontend/src/lib/k8s/runtime.ts +++ b/frontend/src/lib/k8s/runtime.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeRuntimeClass extends KubeObjectInterface { @@ -13,8 +12,6 @@ export class RuntimeClass extends KubeObject { static apiVersion = 'node.k8s.io/v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('node.k8s.io', 'v1', 'runtimeclasses'); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/secret.ts b/frontend/src/lib/k8s/secret.ts index 2c9864fb0bd..628b2255994 100644 --- a/frontend/src/lib/k8s/secret.ts +++ b/frontend/src/lib/k8s/secret.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeSecret extends KubeObjectInterface { @@ -12,8 +11,6 @@ class Secret extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'secrets'); - get data() { return this.jsonData.data; } diff --git a/frontend/src/lib/k8s/service.ts b/frontend/src/lib/k8s/service.ts index 66cc42e65fd..ac46d152db0 100644 --- a/frontend/src/lib/k8s/service.ts +++ b/frontend/src/lib/k8s/service.ts @@ -1,5 +1,4 @@ import _ from 'lodash'; -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeCondition } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -46,8 +45,6 @@ class Service extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'services'); - get spec(): KubeService['spec'] { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/serviceAccount.ts b/frontend/src/lib/k8s/serviceAccount.ts index 6b56698c602..f0623fd6b7e 100644 --- a/frontend/src/lib/k8s/serviceAccount.ts +++ b/frontend/src/lib/k8s/serviceAccount.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeServiceAccount extends KubeObjectInterface { @@ -18,8 +17,6 @@ class ServiceAccount extends KubeObject { static apiVersion = 'v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'serviceaccounts'); - get secrets(): KubeServiceAccount['secrets'] { return this.jsonData.secrets; } diff --git a/frontend/src/lib/k8s/statefulSet.ts b/frontend/src/lib/k8s/statefulSet.ts index 447cfc20bfd..5859c7215bb 100644 --- a/frontend/src/lib/k8s/statefulSet.ts +++ b/frontend/src/lib/k8s/statefulSet.ts @@ -1,4 +1,3 @@ -import { apiFactoryWithNamespace } from './apiProxy'; import { KubeContainer, LabelSelector } from './cluster'; import { KubeMetadata } from './KubeMetadata'; import { KubeObject, KubeObjectInterface } from './KubeObject'; @@ -30,8 +29,6 @@ class StatefulSet extends KubeObject { static apiVersion = 'apps/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace('apps', 'v1', 'statefulsets', true); - get spec() { return this.jsonData.spec; } diff --git a/frontend/src/lib/k8s/storageClass.ts b/frontend/src/lib/k8s/storageClass.ts index e765337e94d..a13cb6c7ba8 100644 --- a/frontend/src/lib/k8s/storageClass.ts +++ b/frontend/src/lib/k8s/storageClass.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { KubeObject, KubeObjectInterface } from './KubeObject'; export interface KubeStorageClass extends KubeObjectInterface { @@ -14,8 +13,6 @@ class StorageClass extends KubeObject { static apiVersion = 'storage.k8s.io/v1'; static isNamespaced = false; - static apiEndpoint = apiFactory('storage.k8s.io', 'v1', 'storageclasses'); - get provisioner() { return this.jsonData.provisioner; } diff --git a/frontend/src/lib/k8s/validatingWebhookConfiguration.ts b/frontend/src/lib/k8s/validatingWebhookConfiguration.ts index a2c244ed002..fc97a1dbd3b 100644 --- a/frontend/src/lib/k8s/validatingWebhookConfiguration.ts +++ b/frontend/src/lib/k8s/validatingWebhookConfiguration.ts @@ -1,4 +1,3 @@ -import { apiFactory } from './apiProxy'; import { LabelSelector } from './cluster'; import { KubeObject, KubeObjectInterface } from './KubeObject'; import { KubeRuleWithOperations, KubeWebhookClientConfig } from './mutatingWebhookConfiguration'; @@ -30,12 +29,6 @@ class ValidatingWebhookConfiguration extends KubeObject { static apiVersion = 'autoscaling.k8s.io/v1'; static isNamespaced = true; - static apiEndpoint = apiFactoryWithNamespace( - 'autoscaling.k8s.io', - 'v1', - 'verticalpodautoscalers' - ); - static async isEnabled(): Promise { let res; try {