Skip to content

Commit

Permalink
frontend: Introduce kind, apiVersion, apiName fields for all KubeObjects
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Dubenko <[email protected]>
  • Loading branch information
sniok committed Oct 24, 2024
1 parent 58c51a5 commit c9adbd5
Show file tree
Hide file tree
Showing 37 changed files with 204 additions and 85 deletions.
6 changes: 2 additions & 4 deletions frontend/src/lib/k8s/KubeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,8 @@ export class KubeObject<T extends KubeObjectInterface | KubeEvent = any> {
* @param objectName The name of the object to create a KubeObject implementation for.
*/

export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(objectName: string) {
class KubeObjectInternal extends KubeObject<T> {
static objectName = objectName;
}
export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>() {
class KubeObjectInternal extends KubeObject<T> {}
return KubeObjectInternal;
}
/**
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/lib/k8s/clusterRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { apiFactory } from './apiProxy';
import { makeKubeObject } from './KubeObject';
import { KubeRole } from './role';

class ClusterRole extends makeKubeObject<KubeRole>('role') {
static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterroles');

static get className() {
return 'ClusterRole';
}
class ClusterRole extends makeKubeObject<KubeRole>() {
static kind = 'ClusterRole';
static apiName = 'clusterroles';
static apiVersion = 'rbac.authorization.k8s.io/v1';
static isNamespaced = false;

get detailsRoute() {
return 'clusterRole';
}
static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterroles');

get rules() {
return this.jsonData!.rules;
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/lib/k8s/clusterRoleBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { apiFactory } from './apiProxy';
import { makeKubeObject } from './KubeObject';
import { KubeRoleBinding } from './roleBinding';

class ClusterRoleBinding extends makeKubeObject<KubeRoleBinding>('roleBinding') {
static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterrolebindings');

static get className(): string {
return 'ClusterRoleBinding';
}
class ClusterRoleBinding extends makeKubeObject<KubeRoleBinding>() {
static kind = 'ClusterRoleBinding';
static apiName = 'clusterrolebindings';
static apiVersion = 'rbac.authorization.k8s.io/v1';
static isNamespaced = false;

get detailsRoute() {
return 'clusterRoleBinding';
}
static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterrolebindings');

get roleRef() {
return this.jsonData!.roleRef;
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/configMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export interface KubeConfigMap extends KubeObjectInterface {
}

class ConfigMap extends KubeObject<KubeConfigMap> {
static objectName = 'configMap';
static kind = 'ConfigMap';
static apiName = 'configmaps';
static apiVersion = 'v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'configmaps');

get data() {
Expand Down
16 changes: 12 additions & 4 deletions frontend/src/lib/k8s/crd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ export interface KubeCRD extends KubeObjectInterface {
}

class CustomResourceDefinition extends KubeObject<KubeCRD> {
static objectName = 'crd';
static kind = 'CustomResourceDefinition';
static apiName = 'customresourcedefinitions';
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 className(): string {
return 'CustomResourceDefinition';
static get listRoute(): string {
return 'crds';
}

static get detailsRoute(): string {
Expand Down Expand Up @@ -163,7 +167,11 @@ export function makeCustomResourceClass(

const apiFunc = !!objArgs.isNamespaced ? apiFactoryWithNamespace : apiFactory;
return class CRClass extends KubeObject<any> {
static objectName = objArgs.singleName;
static kind = objArgs.singleName;
static apiName = crClassArgs.pluralName;
static apiVersion = apiInfoArgs.map(([group, version]) =>
group ? `${group}/${version}` : version
);
static apiEndpoint = apiFunc(...apiInfoArgs);
};
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/cronJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export interface KubeCronJob extends KubeObjectInterface {
}

class CronJob extends KubeObject<KubeCronJob> {
static objectName = 'CronJob';
static kind = 'CronJob';
static apiName = 'cronjobs';
static apiVersion = ['batch/v1', 'batch/v1beta1'];
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace(
['batch', 'v1', 'cronjobs'],
['batch', 'v1beta1', 'cronjobs']
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/daemonSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export interface KubeDaemonSet extends KubeObjectInterface {
}

class DaemonSet extends KubeObject<KubeDaemonSet> {
static objectName = 'DaemonSet';
static kind = 'DaemonSet';
static apiName = 'daemonsets';
static apiVersion = 'apps/v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('apps', 'v1', 'daemonsets');

get spec() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export interface KubeDeployment extends KubeObjectInterface {
}

class Deployment extends KubeObject<KubeDeployment> {
static objectName = 'Deployment';
static kind = 'Deployment';
static apiName = 'deployments';
static apiVersion = 'apps/v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('apps', 'v1', 'deployments', true);

get spec() {
Expand Down
16 changes: 15 additions & 1 deletion frontend/src/lib/k8s/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,23 @@ export interface KubeEndpoint extends KubeObjectInterface {
}

class Endpoints extends KubeObject<KubeEndpoint> {
static objectName = 'endpoint';
static kind = 'Endpoints';
static apiName = 'endpoints';
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';
}

// @todo Remove this when we can break backward compatibility.
static get className() {
return 'Endpoint';
}

get spec() {
return this.jsonData.spec;
}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/k8s/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export interface KubeEvent {
}

class Event extends KubeObject<KubeEvent> {
static objectName = 'Event';
static kind = 'Event';
static apiName = 'events';
static apiVersion = 'v1';

static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'events');

// Max number of events to fetch from the API
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/hpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ interface HPAMetrics {
}

class HPA extends KubeObject<KubeHPA> {
static objectName = 'horizontalPodAutoscaler';
static kind = 'HorizontalPodAutoscaler';
static apiName = 'horizontalpodautoscalers';
static apiVersion = 'autoscaling/v2';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('autoscaling', 'v2', 'horizontalpodautoscalers');

get spec(): HpaSpec {
Expand Down
14 changes: 5 additions & 9 deletions frontend/src/lib/k8s/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export interface KubeIngress extends KubeObjectInterface {
}

class Ingress extends KubeObject<KubeIngress> {
static objectName = 'ingress';
static kind = 'Ingress';
static apiName = 'ingresses';
static apiVersion = ['networking.k8s.io/v1', 'extensions/v1beta1'];
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace(
['networking.k8s.io', 'v1', 'ingresses'],
['extensions', 'v1beta1', 'ingresses']
Expand Down Expand Up @@ -130,14 +134,6 @@ class Ingress extends KubeObject<KubeIngress> {
this.cachedRules = rules;
return rules;
}

static get listRoute() {
return 'ingresses';
}

static get pluralName() {
return 'ingresses';
}
}

export default Ingress;
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/ingressClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export interface KubeIngressClass extends KubeObjectInterface {
}

class IngressClass extends KubeObject<KubeIngressClass> {
static objectName = 'ingressClass';
static kind = 'IngressClass';
static apiName = 'ingressclasses';
static apiVersion = 'networking.k8s.io/v1';
static isNamespaced = false;

static apiEndpoint = apiFactory(['networking.k8s.io', 'v1', 'ingressclasses']);

get spec(): KubeIngressClass['spec'] {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export interface KubeJob extends KubeObjectInterface {
}

class Job extends KubeObject<KubeJob> {
static objectName = 'Job';
static kind = 'Job';
static apiName = 'jobs';
static apiVersion = 'batch/v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('batch', 'v1', 'jobs');

get spec() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export interface KubeLease extends KubeObjectInterface {
}

export class Lease extends KubeObject<KubeLease> {
static objectName = 'Lease';
static kind = 'Lease';
static apiName = 'leases';
static apiVersion = 'coordination.k8s.io/v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('coordination.k8s.io', 'v1', 'leases');

get spec() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/limitRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export interface KubeLimitRange extends KubeObjectInterface {
}

export class LimitRange extends KubeObject<KubeLimitRange> {
static objectName = 'LimitRange';
static kind = 'LimitRange';
static apiName = 'limitranges';
static apiVersion = 'v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'limitranges');

get spec() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/mutatingWebhookConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export interface KubeMutatingWebhookConfiguration extends KubeObjectInterface {
}

class MutatingWebhookConfiguration extends KubeObject<KubeMutatingWebhookConfiguration> {
static objectName = 'MutatingWebhookConfiguration';
static kind = 'MutatingWebhookConfiguration';
static apiName = 'mutatingwebhookconfigurations';
static apiVersion = 'admissionregistration.k8s.io/v1';
static isNamespaced = false;

static apiEndpoint = apiFactory(
'admissionregistration.k8s.io',
'v1',
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export interface KubeNamespace extends KubeObjectInterface {
}

class Namespace extends KubeObject<KubeNamespace> {
static objectName = 'namespace';
static kind = 'Namespace';
static apiName = 'namespaces';
static apiVersion = 'v1';
static isNamespaced = false;

static apiEndpoint = apiFactory('', 'v1', 'namespaces');

get status() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/networkpolicy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export interface KubeNetworkPolicy extends KubeObjectInterface {
}

class NetworkPolicy extends KubeObject<KubeNetworkPolicy> {
static objectName = 'NetworkPolicy';
static kind = 'NetworkPolicy';
static apiName = 'networkpolicies';
static apiVersion = 'networking.k8s.io/v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('networking.k8s.io', 'v1', 'networkpolicies');

static get pluralName() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export interface KubeNode extends KubeObjectInterface {
}

class Node extends KubeObject<KubeNode> {
static objectName = 'node';
static kind = 'Node';
static apiName = 'nodes';
static apiVersion = 'v1';
static isNamespaced = false;

static apiEndpoint = apiFactory('', 'v1', 'nodes');

get status(): KubeNode['status'] {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/persistentVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export interface KubePersistentVolume extends KubeObjectInterface {
}

class PersistentVolume extends KubeObject<KubePersistentVolume> {
static objectName = 'persistentVolume';
static kind = 'PersistentVolume';
static apiName = 'persistentvolumes';
static apiVersion = 'v1';
static isNamespaced = false;

static apiEndpoint = apiFactory('', 'v1', 'persistentvolumes');

get spec() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/persistentVolumeClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export interface KubePersistentVolumeClaim extends KubeObjectInterface {
}

class PersistentVolumeClaim extends KubeObject<KubePersistentVolumeClaim> {
static objectName = 'persistentVolumeClaim';
static kind = 'PersistentVolumeClaim';
static apiName = 'persistentvolumeclaims';
static apiVersion = 'v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'persistentvolumeclaims');

get spec() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ type PodDetailedStatus = {
};

class Pod extends KubeObject<KubePod> {
static objectName = 'Pod';
static kind = 'Pod';
static apiName = 'pods';
static apiVersion = 'v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'pods');
protected detailedStatusCache: Partial<{ resourceVersion: string; details: PodDetailedStatus }>;

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/k8s/podDisruptionBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export interface KubePDB extends KubeObjectInterface {
}

class PDB extends KubeObject<KubePDB> {
static objectName = 'podDisruptionBudget';
static kind = 'PodDisruptionBudget';
static apiName = 'poddisruptionbudgets';
static apiVersion = 'policy/v1';
static isNamespaced = true;

static apiEndpoint = apiFactoryWithNamespace(['policy', 'v1', 'poddisruptionbudgets']);

get spec(): KubePDB['spec'] {
Expand Down
Loading

0 comments on commit c9adbd5

Please sign in to comment.