mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-14 03:09:50 +00:00
♻️ refactor: remove unused code
This commit is contained in:
@@ -3,20 +3,12 @@ import { BaseK8sOperations } from "./base.operations";
|
||||
|
||||
export class ClusterOperations extends BaseK8sOperations {
|
||||
constructor(
|
||||
private coreApi: k8s.CoreV1Api,
|
||||
private customObjectsApi: k8s.CustomObjectsApi,
|
||||
namespace: string
|
||||
) {
|
||||
super(namespace);
|
||||
}
|
||||
|
||||
async listNodes() {
|
||||
return this.executeOperation(
|
||||
() => this.coreApi.listNode().then((r) => r.items),
|
||||
"Failed to fetch nodes"
|
||||
);
|
||||
}
|
||||
|
||||
async getNodeMetrics() {
|
||||
return this.executeOperation(
|
||||
() =>
|
||||
@@ -28,12 +20,4 @@ export class ClusterOperations extends BaseK8sOperations {
|
||||
"Failed to fetch node metrics"
|
||||
);
|
||||
}
|
||||
|
||||
async listConfigMaps(namespace?: string) {
|
||||
const ns = namespace || this.namespace;
|
||||
return this.executeOperation(
|
||||
() => this.coreApi.listNamespacedConfigMap({ namespace: ns }).then((r) => r.items),
|
||||
"Failed to fetch configmaps"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
export { BaseK8sOperations } from "./base.operations";
|
||||
export { ClusterOperations } from "./cluster.operations";
|
||||
export { CustomResourceOperations } from "./custom-resource.operations";
|
||||
export { NetworkOperations } from "./network.operations";
|
||||
export { PodOperations } from "./pod.operations";
|
||||
export { WorkloadOperations } from "./workload.operations";
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import type * as k8s from "@kubernetes/client-node";
|
||||
import { BaseK8sOperations } from "./base.operations";
|
||||
|
||||
export class NetworkOperations extends BaseK8sOperations {
|
||||
constructor(
|
||||
private coreApi: k8s.CoreV1Api,
|
||||
private networkingApi: k8s.NetworkingV1Api,
|
||||
namespace: string
|
||||
) {
|
||||
super(namespace);
|
||||
}
|
||||
|
||||
async listServices() {
|
||||
return this.executeOperation(
|
||||
() => this.coreApi.listNamespacedService({ namespace: this.namespace }).then((r) => r.items),
|
||||
"Failed to fetch services"
|
||||
);
|
||||
}
|
||||
|
||||
async listIngresses() {
|
||||
return this.executeOperation(
|
||||
() =>
|
||||
this.networkingApi
|
||||
.listNamespacedIngress({ namespace: this.namespace })
|
||||
.then((r) => r.items),
|
||||
"Failed to fetch ingresses"
|
||||
);
|
||||
}
|
||||
|
||||
async getServiceInfo(serviceName: string) {
|
||||
return this.executeOperation(
|
||||
() => this.coreApi.readNamespacedService({ name: serviceName, namespace: this.namespace }),
|
||||
`Failed to fetch service info for ${serviceName}`
|
||||
);
|
||||
}
|
||||
|
||||
async getServerConnectionInfo(serviceName: string) {
|
||||
return this.executeOperation(async () => {
|
||||
const service = await this.coreApi.readNamespacedService({
|
||||
name: serviceName,
|
||||
namespace: this.namespace,
|
||||
});
|
||||
|
||||
const serviceType = service.spec?.type || "ClusterIP";
|
||||
const ports = service.spec?.ports || [];
|
||||
|
||||
let host: string;
|
||||
let externalHost: string | undefined;
|
||||
|
||||
switch (serviceType) {
|
||||
case "LoadBalancer": {
|
||||
const ingress = service.status?.loadBalancer?.ingress?.[0];
|
||||
host =
|
||||
ingress?.hostname ||
|
||||
ingress?.ip ||
|
||||
`${serviceName}.${this.namespace}.svc.cluster.local`;
|
||||
externalHost = ingress?.hostname || ingress?.ip;
|
||||
break;
|
||||
}
|
||||
|
||||
case "NodePort":
|
||||
host = `${serviceName}.${this.namespace}.svc.cluster.local`;
|
||||
externalHost = "<node-ip>";
|
||||
break;
|
||||
|
||||
default:
|
||||
host = `${serviceName}.${this.namespace}.svc.cluster.local`;
|
||||
externalHost = undefined;
|
||||
}
|
||||
|
||||
const portMappings = ports.map((port) => ({
|
||||
name: port.name,
|
||||
port: port.port,
|
||||
targetPort: port.targetPort,
|
||||
nodePort: port.nodePort,
|
||||
protocol: port.protocol || "TCP",
|
||||
}));
|
||||
|
||||
return {
|
||||
serviceName,
|
||||
namespace: this.namespace,
|
||||
serviceType,
|
||||
internalHost: host,
|
||||
externalHost,
|
||||
ports: portMappings,
|
||||
};
|
||||
}, `Failed to fetch connection info for service ${serviceName}`);
|
||||
}
|
||||
}
|
||||
@@ -9,30 +9,6 @@ export class PodOperations extends BaseK8sOperations {
|
||||
super(namespace);
|
||||
}
|
||||
|
||||
async listPods() {
|
||||
return this.executeOperation(
|
||||
() => this.coreApi.listNamespacedPod({ namespace: this.namespace }).then((r) => r.items),
|
||||
"Failed to fetch pods"
|
||||
);
|
||||
}
|
||||
|
||||
async listPodsByLabel(labelSelector: string) {
|
||||
return this.executeOperation(
|
||||
() =>
|
||||
this.coreApi
|
||||
.listNamespacedPod({ namespace: this.namespace, labelSelector })
|
||||
.then((r) => r.items),
|
||||
"Failed to fetch pods by label"
|
||||
);
|
||||
}
|
||||
|
||||
async getPodInfo(podName: string) {
|
||||
return this.executeOperation(
|
||||
() => this.coreApi.readNamespacedPod({ name: podName, namespace: this.namespace }),
|
||||
`Failed to fetch pod info for ${podName}`
|
||||
);
|
||||
}
|
||||
|
||||
async getPodLogs(
|
||||
podName: string,
|
||||
options?: {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import type * as k8s from "@kubernetes/client-node";
|
||||
import { BaseK8sOperations } from "./base.operations";
|
||||
|
||||
export class WorkloadOperations extends BaseK8sOperations {
|
||||
constructor(
|
||||
private appsApi: k8s.AppsV1Api,
|
||||
namespace: string
|
||||
) {
|
||||
super(namespace);
|
||||
}
|
||||
|
||||
async listDeployments() {
|
||||
return this.executeOperation(
|
||||
() =>
|
||||
this.appsApi.listNamespacedDeployment({ namespace: this.namespace }).then((r) => r.items),
|
||||
"Failed to fetch deployments"
|
||||
);
|
||||
}
|
||||
|
||||
async listStatefulSets() {
|
||||
return this.executeOperation(
|
||||
() =>
|
||||
this.appsApi.listNamespacedStatefulSet({ namespace: this.namespace }).then((r) => r.items),
|
||||
"Failed to fetch statefulsets"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user