Skip to content

Commit

Permalink
Re-initialize dynamic client to drop CRD cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kron4eg committed Mar 18, 2019
1 parent 8c59f67 commit 35b8d46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/templates/canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func Deploy(ctx *util.Context) error {
}
}

// HACK: re-init dynamic client in order to re-init RestMapper, to drop caches
err = util.HackIssue321InitDynamicClient(ctx)
if err != nil {
return errors.Wrap(err, "failed to re-init dynamic client")
}

// ClusterRoles
crGenerators := []func() *rbacv1.ClusterRole{
calicoClusterRole,
Expand Down
4 changes: 3 additions & 1 deletion pkg/templates/machinecontroller/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func Deploy(ctx *util.Context) error {
}
}

return nil
// HACK: re-init dynamic client in order to re-init RestMapper, to drop caches
err = util.HackIssue321InitDynamicClient(ctx)
return errors.Wrap(err, "failed to re-init dynamic client")
}

// WaitForMachineController waits for machine-controller-webhook to become running
Expand Down
16 changes: 12 additions & 4 deletions pkg/util/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,18 @@ func BuildKubernetesClientset(ctx *Context) error {
return errors.Wrap(err, "unable to build apiextension-apiserver clientset")
}

ctx.DynamicClient, err = client.New(ctx.RESTConfig, client.Options{})
if err != nil {
return errors.Wrap(err, "unable to build dynamic client")
err = HackIssue321InitDynamicClient(ctx)
return errors.Wrap(err, "unable to build dynamic client")
}

// HackIssue321InitDynamicClient initialize controller-runtime/client
// name comes from: https://github.com/kubernetes-sigs/controller-runtime/issues/321
func HackIssue321InitDynamicClient(ctx *Context) error {
if ctx.RESTConfig == nil {
return errors.New("rest config is not initialized")
}

return nil
var err error
ctx.DynamicClient, err = client.New(ctx.RESTConfig, client.Options{})
return errors.Wrap(err, "unable to build dynamic client")
}

0 comments on commit 35b8d46

Please sign in to comment.