Ensure we send an error when the resource version is too old.

This commit is contained in:
Darren Shepherd 2020-09-27 17:51:52 -07:00
parent 4e31a4b24b
commit a8ce2f5ec8

View File

@ -275,17 +275,21 @@ func returnErr(err error, c chan types.APIEvent) {
func (s *Store) listAndWatch(apiOp *types.APIRequest, k8sClient dynamic.ResourceInterface, schema *types.APISchema, w types.WatchRequest, result chan types.APIEvent) { func (s *Store) listAndWatch(apiOp *types.APIRequest, k8sClient dynamic.ResourceInterface, schema *types.APISchema, w types.WatchRequest, result chan types.APIEvent) {
rev := w.Revision rev := w.Revision
if rev == "" { if rev == "-1" {
rev = ""
} else {
// ensure the revision is valid or get the latest one
list, err := k8sClient.List(apiOp.Context(), metav1.ListOptions{ list, err := k8sClient.List(apiOp.Context(), metav1.ListOptions{
Limit: 1, Limit: 1,
ResourceVersion: rev,
}) })
if err != nil { if err != nil {
returnErr(errors.Wrapf(err, "failed to list %s", schema.ID), result) returnErr(errors.Wrapf(err, "failed to list %s", schema.ID), result)
return return
} }
if rev == "" {
rev = list.GetResourceVersion() rev = list.GetResourceVersion()
} else if rev == "-1" { }
rev = ""
} }
timeout := int64(60 * 30) timeout := int64(60 * 30)