Skip to content

Commit

Permalink
actually retry if we failed to reconcile some objects
Browse files Browse the repository at this point in the history
retry RBAC initialization for up to 30 seconds, kill server on failure
  • Loading branch information
roycaihw authored and voutcn committed May 12, 2021
1 parent 0657e7d commit b27bb50
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/registry/rbac/rest/storage_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc {
// initializing roles is really important. On some e2e runs, we've seen cases where etcd is down when the server
// starts, the roles don't initialize, and nothing works.
err := wait.Poll(1*time.Second, 30*time.Second, func() (done bool, err error) {
failedReconciliation := false

coreclientset, err := corev1client.NewForConfig(hookContext.LoopbackClientConfig)
if err != nil {
Expand Down Expand Up @@ -224,6 +225,7 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc {
if err != nil {
// don't fail on failures, try to create as many as you can
utilruntime.HandleError(fmt.Errorf("unable to reconcile clusterrole.%s/%s: %v", rbac.GroupName, clusterRole.Name, err))
failedReconciliation = true
}
}

Expand Down Expand Up @@ -254,6 +256,7 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc {
if err != nil {
// don't fail on failures, try to create as many as you can
utilruntime.HandleError(fmt.Errorf("unable to reconcile clusterrolebinding.%s/%s: %v", rbac.GroupName, clusterRoleBinding.Name, err))
failedReconciliation = true
}
}

Expand Down Expand Up @@ -283,6 +286,7 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc {
if err != nil {
// don't fail on failures, try to create as many as you can
utilruntime.HandleError(fmt.Errorf("unable to reconcile role.%s/%s in %v: %v", rbac.GroupName, role.Name, namespace, err))
failedReconciliation = true
}
}
}
Expand Down Expand Up @@ -315,9 +319,14 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc {
if err != nil {
// don't fail on failures, try to create as many as you can
utilruntime.HandleError(fmt.Errorf("unable to reconcile rolebinding.%s/%s in %v: %v", rbac.GroupName, roleBinding.Name, namespace, err))
failedReconciliation = true
}
}
}
// failed to reconcile some objects, retry
if failedReconciliation {
return false, nil
}

return true, nil
})
Expand Down

0 comments on commit b27bb50

Please sign in to comment.