Skip to content

Commit 0e8bd15

Browse files
committed
Invalidate discovery cache before migration commands
This change updates the migration commands to invalidate and refetch the cached discovery information on disk. This makes it so that the REST mapper will never use stale discovery data. Signed-off-by: Monis Khan <[email protected]>
1 parent 095b814 commit 0e8bd15

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: pkg/oc/cli/admin/migrate/migrator.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,16 @@ func (o *ResourceOptions) Complete(f kcmdutil.Factory, c *cobra.Command) error {
210210
}
211211
}
212212

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()
218215
if err != nil {
219216
return err
220217
}
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
221223
mapper, err := f.ToRESTMapper()
222224
if err != nil {
223225
return err
@@ -725,7 +727,7 @@ func DefaultRetriable(info *resource.Info, err error) error {
725727
// represented.
726728
// TODO: add a field to APIResources for "virtual" (or that points to the canonical resource).
727729
// 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) {
729731
set := make(map[schema.GroupResource]struct{})
730732
all, err := d.ServerResources()
731733
if err != nil {

0 commit comments

Comments
 (0)