mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Prefer usage of preference over autoselection (#4436)
This commit is contained in:
parent
31946daea3
commit
120134a084
@ -34,12 +34,19 @@ export interface PrometheusDetails {
|
|||||||
provider: PrometheusProvider;
|
provider: PrometheusProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PrometheusServicePreferences {
|
||||||
|
namespace: string;
|
||||||
|
service: string;
|
||||||
|
port: number;
|
||||||
|
prefix: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class ContextHandler {
|
export class ContextHandler {
|
||||||
public clusterUrl: UrlWithStringQuery;
|
public clusterUrl: UrlWithStringQuery;
|
||||||
protected kubeAuthProxy?: KubeAuthProxy;
|
protected kubeAuthProxy?: KubeAuthProxy;
|
||||||
protected apiTarget?: httpProxy.ServerOptions;
|
protected apiTarget?: httpProxy.ServerOptions;
|
||||||
protected prometheusProvider?: string;
|
protected prometheusProvider?: string;
|
||||||
protected prometheusPath: string | null;
|
protected prometheus?: PrometheusServicePreferences;
|
||||||
|
|
||||||
constructor(protected cluster: Cluster) {
|
constructor(protected cluster: Cluster) {
|
||||||
this.clusterUrl = url.parse(cluster.apiUrl);
|
this.clusterUrl = url.parse(cluster.apiUrl);
|
||||||
@ -48,13 +55,7 @@ export class ContextHandler {
|
|||||||
|
|
||||||
public setupPrometheus(preferences: ClusterPrometheusPreferences = {}) {
|
public setupPrometheus(preferences: ClusterPrometheusPreferences = {}) {
|
||||||
this.prometheusProvider = preferences.prometheusProvider?.type;
|
this.prometheusProvider = preferences.prometheusProvider?.type;
|
||||||
this.prometheusPath = null;
|
this.prometheus = preferences.prometheus || null;
|
||||||
|
|
||||||
if (preferences.prometheus) {
|
|
||||||
const { namespace, service, port } = preferences.prometheus;
|
|
||||||
|
|
||||||
this.prometheusPath = `${namespace}/services/${service}:${port}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getPrometheusDetails(): Promise<PrometheusDetails> {
|
public async getPrometheusDetails(): Promise<PrometheusDetails> {
|
||||||
@ -66,7 +67,7 @@ export class ContextHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ensurePrometheusPath({ service, namespace, port }: PrometheusService): string {
|
protected ensurePrometheusPath({ service, namespace, port }: PrometheusService): string {
|
||||||
return this.prometheusPath ||= `${namespace}/services/${service}:${port}`;
|
return `${namespace}/services/${service}:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ensurePrometheusProvider(service: PrometheusService): PrometheusProvider {
|
protected ensurePrometheusProvider(service: PrometheusService): PrometheusProvider {
|
||||||
@ -90,6 +91,15 @@ export class ContextHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async getPrometheusService(): Promise<PrometheusService> {
|
protected async getPrometheusService(): Promise<PrometheusService> {
|
||||||
|
if (this.prometheus !== null && this.prometheusProvider !== null) {
|
||||||
|
return {
|
||||||
|
id: this.prometheusProvider,
|
||||||
|
namespace: this.prometheus.namespace,
|
||||||
|
service: this.prometheus.service,
|
||||||
|
port: this.prometheus.port,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const providers = this.listPotentialProviders();
|
const providers = this.listPotentialProviders();
|
||||||
const proxyConfig = await this.cluster.getProxyKubeconfig();
|
const proxyConfig = await this.cluster.getProxyKubeconfig();
|
||||||
const apiClient = proxyConfig.makeApiClient(CoreV1Api);
|
const apiClient = proxyConfig.makeApiClient(CoreV1Api);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user