Skip to content

Commit

Permalink
runner: reset RESTMapper after CRD change
Browse files Browse the repository at this point in the history
As otherwise with a persistent discovery client and/or REST mapper
configuration, newly installed CRDs will not be recognized and cause a
`resource mapping not found for name` error.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed Mar 6, 2023
1 parent 34d87cc commit 11aeaf1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,23 @@ func (r *Runner) applyCRDs(policy v2.CRDsPolicy, chart *chart.Chart, visitorFunc
}
r.config.Log("Clearing discovery cache")
discoveryClient.Invalidate()

// Clear the RESTMapper cache, since it will not have the new CRDs.
if m, err := r.config.RESTClientGetter.ToRESTMapper(); err == nil {
if rm, ok := m.(meta.ResettableRESTMapper); ok {
r.config.Log("Clearing RESTMapper cache")
rm.Reset()
}
}

// Give time for the CRD to be recognized.
if err := r.config.KubeClient.Wait(totalItems, 60*time.Second); err != nil {
r.config.Log("Error waiting for items: %s", err)
return err
}

// Make sure to force a rebuild of the cache.
discoveryClient.ServerGroups()
_, _ = discoveryClient.ServerGroups()
}
return nil
}
Expand Down

0 comments on commit 11aeaf1

Please sign in to comment.