@@ -31,6 +31,9 @@ type getFlagpole struct {
3131 Output string
3232 ChunkSize int64
3333 Prefix string
34+
35+ Watch bool
36+ WatchOnly bool
3437}
3538
3639var (
5053 # Nearly equivalent
5154 kubectl get leases -n kube-system -o yaml
5255
56+ # Watch all leases with namespace "kube-system"
57+ augerctl get leases -n kube-system -w
58+ # Nearly equivalent
59+ kubectl get leases -n kube-system -w -o yaml
60+
5361 # List a single resource of type "apiservices.apiregistration.k8s.io" and name "v1.apps"
5462 augerctl get apiservices.apiregistration.k8s.io v1.apps
5563 # Nearly equivalent
@@ -89,6 +97,8 @@ func newCtlGetCommand(f *flagpole) *cobra.Command {
8997 cmd .Flags ().Int64Var (& flags .ChunkSize , "chunk-size" , 500 , "chunk size of the list pager" )
9098 cmd .Flags ().StringVar (& flags .Prefix , "prefix" , "/registry" , "prefix to prepend to the resource" )
9199
100+ cmd .Flags ().BoolVarP (& flags .Watch , "watch" , "w" , false , "after listing/getting the requested object, watch for changes" )
101+ cmd .Flags ().BoolVar (& flags .WatchOnly , "watch-only" , false , "watch for changes to the requested object(s), without listing/getting first" )
92102 return cmd
93103}
94104
@@ -124,13 +134,30 @@ func getCommand(ctx context.Context, etcdclient client.Client, flags *getFlagpol
124134 client .WithResponse (printer .Print ),
125135 }
126136
127- // TODO: Support watch
137+ if flags .Watch {
138+ if ! flags .WatchOnly {
139+ rev , err := etcdclient .Get (ctx , flags .Prefix ,
140+ opOpts ... ,
141+ )
142+ if err != nil {
143+ return err
144+ }
145+ opOpts = append (opOpts , client .WithRevision (rev ))
146+ }
128147
129- _ , err := etcdclient .Get (ctx , flags .Prefix ,
130- opOpts ... ,
131- )
132- if err != nil {
133- return err
148+ err := etcdclient .Watch (ctx , flags .Prefix ,
149+ opOpts ... ,
150+ )
151+ if err != nil {
152+ return err
153+ }
154+ } else {
155+ _ , err := etcdclient .Get (ctx , flags .Prefix ,
156+ opOpts ... ,
157+ )
158+ if err != nil {
159+ return err
160+ }
134161 }
135162
136163 return nil
0 commit comments