Skip to content

Commit

Permalink
Extend playback to watch events
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed May 19, 2021
1 parent e31a61f commit 4d36450
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controllers/events/playback.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ func playback(ctx context.Context, r *EventWatcher, filename string) error {
err = r.handleEvent(ctx, &ev)
mtime.NowReset()
return err
case "watch":
dec := yaml.NewYAMLToJSONDecoder(bytes.NewBuffer(doc))
var u unstructured.Unstructured
err := dec.Decode(&u)
if err != nil {
return fmt.Errorf("error parsing: %v", err)
}
mtime.NowForce(details.Timestamp)
wi, err := r.watcher.getWatch(&u)
if err != nil {
return err
}
err = wi.checkConditionUpdates(&u, r)
mtime.NowReset()
return err
default:
return fmt.Errorf("style not recognized: %q", string(details.Style))
}
Expand Down
12 changes: 12 additions & 0 deletions controllers/events/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ func (m *watchManager) getResourceInterface(gvk schema.GroupVersionKind, ns stri
return m.client.Resource(mapping.Resource).Namespace(ns), nil
}

func (m *watchManager) getWatch(obj runtime.Object) (*watchInfo, error) {
ma, _ := meta.Accessor(obj)
ref := refFromObject(ma)
m.Lock()
wi := m.watches[ref]
m.Unlock()
if wi == nil {
return nil, fmt.Errorf("watcher not found for object %q", ref)
}
return wi, nil
}

func (w *watchInfo) run(ew eventNotifier) {
for e := range w.watch.ResultChan() {
obj, ok := e.Object.(*unstructured.Unstructured)
Expand Down

0 comments on commit 4d36450

Please sign in to comment.