godaddy / kubernetes-client

Simplified Kubernetes API client for Node.js.
MIT License
962 stars 192 forks source link

Ability to catch 410GONE #635

Closed Stono closed 4 years ago

Stono commented 4 years ago

Following on from https://github.com/godaddy/kubernetes-client/issues/633, when we are reconnecting the kubernetes client we need to pass the resourceVersion of the last item we saw (https://kubernetes.io/docs/reference/using-api/api-concepts/)

However, when you do that with this client, eg:

watch.getObjectStream({
  qs: {
    resourceVersion: 1
  }
})

The stream just immediately emits close event, with no context, so its impossible to see why it closed.

It's important we can see the close reason because if the code is 410, we need to restart with a different resourceVersion.

If you add a callback to: https://github.com/godaddy/kubernetes-client/blob/master/backends/request/client.js#L225 - you can see the 410 in the response body:

  body: {
    type: 'ERROR',
    object: {
      kind: 'Status',
      apiVersion: 'v1',
      metadata: {},
      status: 'Failure',
      message: 'too old resource version: 1 (226181910)',
      reason: 'Gone',
      code: 410
    }
Stono commented 4 years ago

Closing as i realised this is being emitted through the on('data') event.