godaddy / kubernetes-client

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

Regarding watch event failures and retries #682

Open tankunsheng opened 3 years ago

tankunsheng commented 3 years ago

Looking at the examples of the implementation of watches for resources. How would the reconciliation work in the event that a creation/update/deletion event fails and needs to be retried again?

It does not seem right to handle the retry from within the code. Is there someway to reschedule a retry?

From the example of the watchDeploymentNotifiers below:

function watchDeploymentNotifiers (client) {
  const stream = client.apis['kubernetes-client.io'].v1.watch.deploymentnotifiers.getStream()
  const jsonStream = new JSONStream()
  stream.pipe(jsonStream)

  const watchers = {}
  jsonStream.on('data', async event => {
    const id = `${event.object.metadata.namespace}/${event.object.metadata.name}`
    if (event.type === 'ADDED') {

      // What happens if the logic fails here and errors out
      // How do I ensure that the watch for this particular resource version is triggered again?

    } else if (event.type === 'DELETED') {

    }
  })
}