2022-05-18 07:26:57 +00:00
|
|
|
import * as k8s from '@pulumi/kubernetes';
|
|
|
|
|
import * as pulumi from '@pulumi/pulumi';
|
|
|
|
|
|
|
|
|
|
export function serviceLocalEndpoint(service: k8s.types.input.core.v1.Service) {
|
2022-05-24 13:31:53 +00:00
|
|
|
return pulumi.all([service.metadata, service.spec]).apply(([metadata, spec]) => {
|
2022-10-26 07:27:35 +00:00
|
|
|
const defaultPort = (spec?.ports || [])[0];
|
2022-05-24 13:31:53 +00:00
|
|
|
const portText = defaultPort ? `:${defaultPort.port}` : '';
|
2022-05-18 07:26:57 +00:00
|
|
|
|
2022-11-24 10:00:41 +00:00
|
|
|
return `http://${metadata?.name}.${
|
|
|
|
|
metadata?.namespace || 'default'
|
|
|
|
|
}.svc.cluster.local${portText}`;
|
2022-05-24 13:31:53 +00:00
|
|
|
});
|
2022-05-18 07:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function serviceLocalHost(service: k8s.types.input.core.v1.Service) {
|
|
|
|
|
return pulumi.all([service.metadata]).apply(([metadata]) => {
|
2022-10-26 07:27:35 +00:00
|
|
|
return `${metadata?.name}.${metadata?.namespace || 'default'}.svc.cluster.local`;
|
2022-05-18 07:26:57 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 13:31:53 +00:00
|
|
|
export function serviceLocalMetricsEndpoint(service: k8s.types.input.core.v1.Service) {
|
2022-05-18 07:26:57 +00:00
|
|
|
return pulumi.all([service.metadata]).apply(([metadata]) => {
|
2022-10-26 07:27:35 +00:00
|
|
|
return `${metadata?.name}.${metadata?.namespace || 'default'}.svc.cluster.local:10254/metrics`;
|
2022-05-18 07:26:57 +00:00
|
|
|
});
|
|
|
|
|
}
|