@@ -210,14 +210,16 @@ func (o *ResourceOptions) Complete(f kcmdutil.Factory, c *cobra.Command) error {
210
210
}
211
211
}
212
212
213
- clientConfig , err := f .ToRESTConfig ()
214
- if err != nil {
215
- return err
216
- }
217
- discoveryClient , err := discovery .NewDiscoveryClientForConfig (clientConfig )
213
+ // use the factory's caching discovery client
214
+ discoveryClient , err := f .ToDiscoveryClient ()
218
215
if err != nil {
219
216
return err
220
217
}
218
+ // but invalidate its cache to force it to fetch the latest data
219
+ discoveryClient .Invalidate ()
220
+ // and do a no-op call to cause the latest data to be written to disk
221
+ _ , _ = discoveryClient .ServerResources ()
222
+ // so that the REST mapper will never use stale discovery data
221
223
mapper , err := f .ToRESTMapper ()
222
224
if err != nil {
223
225
return err
@@ -725,7 +727,7 @@ func DefaultRetriable(info *resource.Info, err error) error {
725
727
// represented.
726
728
// TODO: add a field to APIResources for "virtual" (or that points to the canonical resource).
727
729
// TODO: fallback to the scheme when discovery is not possible.
728
- func FindAllCanonicalResources (d discovery.DiscoveryInterface , m meta.RESTMapper ) ([]schema.GroupResource , error ) {
730
+ func FindAllCanonicalResources (d discovery.ServerResourcesInterface , m meta.RESTMapper ) ([]schema.GroupResource , error ) {
729
731
set := make (map [schema.GroupResource ]struct {})
730
732
all , err := d .ServerResources ()
731
733
if err != nil {
0 commit comments