mirror of https://github.com/grpc/grpc-node.git
Merge pull request #2198 from murgatroid99/grpc-js-xds_ignore_resource_deletion
grpc-js-xds: Implement ignore_resource_deletion option
This commit is contained in:
commit
68aa56fa4a
|
@ -360,6 +360,10 @@ export class XdsClient {
|
||||||
} else {
|
} else {
|
||||||
this.apiVersion = XdsApiVersion.V2;
|
this.apiVersion = XdsApiVersion.V2;
|
||||||
}
|
}
|
||||||
|
if (bootstrapInfo.xdsServers[0].serverFeatures.indexOf('ignore_resource_deletion') >= 0) {
|
||||||
|
this.adsState.lds.enableIgnoreResourceDeletion();
|
||||||
|
this.adsState.cds.enableIgnoreResourceDeletion();
|
||||||
|
}
|
||||||
const nodeV2: NodeV2 = {
|
const nodeV2: NodeV2 = {
|
||||||
...bootstrapInfo.node,
|
...bootstrapInfo.node,
|
||||||
build_version: `gRPC Node Pure JS ${clientVersion}`,
|
build_version: `gRPC Node Pure JS ${clientVersion}`,
|
||||||
|
|
|
@ -75,6 +75,7 @@ interface SubscriptionEntry<ResponseType> {
|
||||||
watchers: Watcher<ResponseType>[];
|
watchers: Watcher<ResponseType>[];
|
||||||
cachedResponse: ResponseType | null;
|
cachedResponse: ResponseType | null;
|
||||||
resourceTimer: NodeJS.Timer;
|
resourceTimer: NodeJS.Timer;
|
||||||
|
deletionIgnored: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RESOURCE_TIMEOUT_MS = 15_000;
|
const RESOURCE_TIMEOUT_MS = 15_000;
|
||||||
|
@ -86,6 +87,7 @@ export abstract class BaseXdsStreamState<ResponseType> implements XdsStreamState
|
||||||
private subscriptions: Map<string, SubscriptionEntry<ResponseType>> = new Map<string, SubscriptionEntry<ResponseType>>();
|
private subscriptions: Map<string, SubscriptionEntry<ResponseType>> = new Map<string, SubscriptionEntry<ResponseType>>();
|
||||||
private latestIsV2 = false;
|
private latestIsV2 = false;
|
||||||
private isAdsStreamRunning = false;
|
private isAdsStreamRunning = false;
|
||||||
|
private ignoreResourceDeletion = false;
|
||||||
|
|
||||||
constructor(private updateResourceNames: () => void) {}
|
constructor(private updateResourceNames: () => void) {}
|
||||||
|
|
||||||
|
@ -111,7 +113,8 @@ export abstract class BaseXdsStreamState<ResponseType> implements XdsStreamState
|
||||||
subscriptionEntry = {
|
subscriptionEntry = {
|
||||||
watchers: [],
|
watchers: [],
|
||||||
cachedResponse: null,
|
cachedResponse: null,
|
||||||
resourceTimer: setTimeout(() => {}, 0)
|
resourceTimer: setTimeout(() => {}, 0),
|
||||||
|
deletionIgnored: false
|
||||||
};
|
};
|
||||||
if (this.isAdsStreamRunning) {
|
if (this.isAdsStreamRunning) {
|
||||||
this.startResourceTimer(subscriptionEntry);
|
this.startResourceTimer(subscriptionEntry);
|
||||||
|
@ -142,6 +145,9 @@ export abstract class BaseXdsStreamState<ResponseType> implements XdsStreamState
|
||||||
}
|
}
|
||||||
if (subscriptionEntry.watchers.length === 0) {
|
if (subscriptionEntry.watchers.length === 0) {
|
||||||
clearTimeout(subscriptionEntry.resourceTimer);
|
clearTimeout(subscriptionEntry.resourceTimer);
|
||||||
|
if (subscriptionEntry.deletionIgnored) {
|
||||||
|
experimental.log(logVerbosity.INFO, 'Unsubscribing from resource with previously ignored deletion: ' + resourceName);
|
||||||
|
}
|
||||||
this.subscriptions.delete(resourceName);
|
this.subscriptions.delete(resourceName);
|
||||||
this.updateResourceNames();
|
this.updateResourceNames();
|
||||||
}
|
}
|
||||||
|
@ -187,6 +193,10 @@ export abstract class BaseXdsStreamState<ResponseType> implements XdsStreamState
|
||||||
}
|
}
|
||||||
clearTimeout(subscriptionEntry.resourceTimer);
|
clearTimeout(subscriptionEntry.resourceTimer);
|
||||||
subscriptionEntry.cachedResponse = resource;
|
subscriptionEntry.cachedResponse = resource;
|
||||||
|
if (subscriptionEntry.deletionIgnored) {
|
||||||
|
experimental.log(logVerbosity.INFO, 'Received resource with previously ignored deletion: ' + resourceName);
|
||||||
|
subscriptionEntry.deletionIgnored = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.missing = this.handleMissingNames(allResourceNames);
|
result.missing = this.handleMissingNames(allResourceNames);
|
||||||
|
@ -218,10 +228,18 @@ export abstract class BaseXdsStreamState<ResponseType> implements XdsStreamState
|
||||||
const missingNames: string[] = [];
|
const missingNames: string[] = [];
|
||||||
for (const [resourceName, subscriptionEntry] of this.subscriptions.entries()) {
|
for (const [resourceName, subscriptionEntry] of this.subscriptions.entries()) {
|
||||||
if (!allResponseNames.has(resourceName) && subscriptionEntry.cachedResponse !== null) {
|
if (!allResponseNames.has(resourceName) && subscriptionEntry.cachedResponse !== null) {
|
||||||
this.trace('Reporting resource does not exist named ' + resourceName);
|
if (this.ignoreResourceDeletion) {
|
||||||
missingNames.push(resourceName);
|
if (!subscriptionEntry.deletionIgnored) {
|
||||||
for (const watcher of subscriptionEntry.watchers) {
|
experimental.log(logVerbosity.ERROR, 'Ignoring nonexistent resource ' + resourceName);
|
||||||
watcher.onResourceDoesNotExist();
|
subscriptionEntry.deletionIgnored = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.trace('Reporting resource does not exist named ' + resourceName);
|
||||||
|
missingNames.push(resourceName);
|
||||||
|
for (const watcher of subscriptionEntry.watchers) {
|
||||||
|
watcher.onResourceDoesNotExist();
|
||||||
|
}
|
||||||
|
subscriptionEntry.cachedResponse = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,6 +249,10 @@ export abstract class BaseXdsStreamState<ResponseType> implements XdsStreamState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableIgnoreResourceDeletion() {
|
||||||
|
this.ignoreResourceDeletion = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the validation rules for this resource type to this resource
|
* Apply the validation rules for this resource type to this resource
|
||||||
* instance.
|
* instance.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export { trace } from './logging';
|
export { trace, log } from './logging';
|
||||||
export {
|
export {
|
||||||
Resolver,
|
Resolver,
|
||||||
ResolverListener,
|
ResolverListener,
|
||||||
|
|
Loading…
Reference in New Issue