@citymallservices/k8s-grpc-resolver
Advanced tools
Comparing version 1.1.3 to 1.1.4
import { ChannelOptions } from "@grpc/grpc-js"; | ||
import { Resolver, ResolverListener } from "@grpc/grpc-js/build/src/resolver"; | ||
import { GrpcUri } from "@grpc/grpc-js/build/src/uri-parser"; | ||
import { ExponentialBackoff } from "cockatiel"; | ||
export declare const K8sScheme = "k8s"; | ||
/** | ||
* setup register the k8s:// scheme into grpc resolver | ||
* @param backoff - use cockatiel's backoff handle reconnect when error, | ||
* setup register the k8s:// scheme into grpc resolver and returns new address | ||
* @param address - kube cluster url | ||
* default is ExponentialBackoff(a max 30 second delay on a decorrelated jitter) | ||
*/ | ||
export declare const setup: (backoff?: ExponentialBackoff<unknown>) => void; | ||
export declare const setup: (address: string) => string; | ||
export declare class K8sResolover implements Resolver { | ||
@@ -13,0 +11,0 @@ private target; |
@@ -35,3 +35,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.K8sResolover = exports.setup = exports.K8sScheme = void 0; | ||
exports.K8sResolover = exports.setup = void 0; | ||
const grpc_js_1 = require("@grpc/grpc-js"); | ||
@@ -44,3 +44,3 @@ const constants_1 = require("@grpc/grpc-js/build/src/constants"); | ||
const cockatiel_1 = require("cockatiel"); | ||
exports.K8sScheme = "k8s"; | ||
const K8sScheme = "k8s"; | ||
const TRACER_NAME = "k8s_resolver"; | ||
@@ -53,7 +53,7 @@ const FieldSelectorPrefix = "metadata.name="; | ||
/** | ||
* setup register the k8s:// scheme into grpc resolver | ||
* @param backoff - use cockatiel's backoff handle reconnect when error, | ||
* setup register the k8s:// scheme into grpc resolver and returns new address | ||
* @param address - kube cluster url | ||
* default is ExponentialBackoff(a max 30 second delay on a decorrelated jitter) | ||
*/ | ||
const setup = (backoff = new cockatiel_1.ExponentialBackoff()) => { | ||
const setup = (address) => { | ||
// init k8s client in setup avoid throw error | ||
@@ -63,4 +63,7 @@ // when only import lib in non k8s env | ||
k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
(0, resolver_1.registerResolver)(exports.K8sScheme, K8sResolover); | ||
backoffFactory = backoff; | ||
(0, resolver_1.registerResolver)(K8sScheme, K8sResolover); | ||
const [host, servicePort] = address.split(":"); | ||
const [serviceName, serviceNs] = host.split("."); | ||
address = `${K8sScheme}://${serviceNs}/${serviceName}:${servicePort}`; | ||
return address; | ||
}; | ||
@@ -67,0 +70,0 @@ exports.setup = setup; |
{ | ||
"name": "@citymallservices/k8s-grpc-resolver", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -12,3 +12,3 @@ import { ChannelOptions, Metadata, StatusObject } from "@grpc/grpc-js"; | ||
export const K8sScheme = "k8s"; | ||
const K8sScheme = "k8s"; | ||
const TRACER_NAME = "k8s_resolver"; | ||
@@ -24,7 +24,7 @@ const FieldSelectorPrefix = "metadata.name="; | ||
/** | ||
* setup register the k8s:// scheme into grpc resolver | ||
* @param backoff - use cockatiel's backoff handle reconnect when error, | ||
* setup register the k8s:// scheme into grpc resolver and returns new address | ||
* @param address - kube cluster url | ||
* default is ExponentialBackoff(a max 30 second delay on a decorrelated jitter) | ||
*/ | ||
export const setup = (backoff = new ExponentialBackoff()) => { | ||
export const setup = (address: string) => { | ||
// init k8s client in setup avoid throw error | ||
@@ -35,3 +35,6 @@ // when only import lib in non k8s env | ||
registerResolver(K8sScheme, K8sResolover); | ||
backoffFactory = backoff; | ||
const [host, servicePort] = address.split(":"); | ||
const [serviceName, serviceNs] = host.split("."); | ||
address = `${K8sScheme}://${serviceNs}/${serviceName}:${servicePort}`; | ||
return address; | ||
}; | ||
@@ -38,0 +41,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54487
991