1 // Copyright 2022 The Kubernetes Authors. 2 // SPDX-License-Identifier: Apache-2.0 3 4 // Package watcher is a library for computing the status of kubernetes resource 5 // objects based on watching object state from a cluster. It keeps watching 6 // until it is cancelled through the provided context. Updates on the status of 7 // objects are streamed back to the caller through a channel. 8 // 9 // # Watching Resources 10 // 11 // In order to watch a set of resources objects, create a StatusWatcher 12 // and pass in the list of object identifiers to the Watch function. 13 // 14 // import ( 15 // "sigs.k8s.io/cli-utils/pkg/kstatus/watcher" 16 // ) 17 // 18 // ids := []prune.ObjMetadata{ 19 // { 20 // GroupKind: schema.GroupKind{ 21 // Group: "apps", 22 // Kind: "Deployment", 23 // }, 24 // Name: "dep", 25 // Namespace: "default", 26 // } 27 // } 28 // 29 // statusWatcher := watcher.NewDefaultStatusWatcher(dynamicClient, mapper) 30 // ctx, cancelFunc := context.WithCancel(context.Background()) 31 // eventCh := statusWatcher.Watch(ctx, ids, watcher.Options{}) 32 // for e := range eventCh { 33 // // Handle event 34 // if e.Type == event.ErrorEvent { 35 // cancelFunc() 36 // return e.Err 37 // } 38 // } 39 package watcher 40