Skip to content

Commit

Permalink
bugfix: ignore non-support watch resources
Browse files Browse the repository at this point in the history
  • Loading branch information
howieyuen committed Mar 2, 2023
1 parent 3cfa054 commit cfc7898
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pkg/engine/operation/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (wo *WatchOperation) Watch(req *WatchRequest) error {
res := &resources[i]
t := res.Type

// Save id first, might have TF resources
ids[i] = res.ResourceKey()

// Get watchers, only support k8s resources
resp := runtimes[t].Watch(ctx, &runtime.WatchRequest{Resource: res})
if resp == nil {
Expand All @@ -61,9 +64,7 @@ func (wo *WatchOperation) Watch(req *WatchRequest) error {
return fmt.Errorf(resp.Status.String())
}

// Save id
ids[i] = res.ResourceKey()
// Save channels
// Save watchers
msgChs[res.ResourceKey()] = resp.Watchers
}

Expand All @@ -84,14 +85,14 @@ func (wo *WatchOperation) Watch(req *WatchRequest) error {
// Start go routine for each table
for _, id := range ids {
sw, ok := msgChs[id]
if !ok {
if !ok { // Terraform resource, skip
continue
}
// Get or new the target table
table, exist := tables[id]
if !exist {
table = printers.NewTable(sw.IDs)
}
// New target table
table := printers.NewTable(sw.IDs)
// Save tables first
tables[id] = table
// Start watching resource
go func(id string, chs []<-chan k8swatch.Event, table *printers.Table) {
// Resources selects
cases := createSelectCases(chs)
Expand Down Expand Up @@ -145,7 +146,7 @@ func (wo *WatchOperation) Watch(req *WatchRequest) error {
// Waiting for all tables completed
for {
// Finish watch
if len(finished) == len(ids) {
if len(finished) == len(tables) {
break
}

Expand All @@ -170,7 +171,8 @@ func (wo *WatchOperation) printTables(w *uilive.Writer, ids []string, tables map
_, _ = fmt.Fprintln(w, pretty.LightCyanBold("[%s]", id))

table, ok := tables[id]
if !ok {
if !ok { // Terraform resource, leave a hint
_, _ = fmt.Fprintln(w, pretty.LightYellow("Terraform resources no need to watch, skip it"))
continue
}
// Print table
Expand Down

0 comments on commit cfc7898

Please sign in to comment.