|
| 1 | +diff --git a/deps/github.com/openshift/kubernetes/pkg/registry/rbac/rest/storage_rbac.go b/deps/github.com/openshift/kubernetes/pkg/registry/rbac/rest/storage_rbac.go |
| 2 | +index 16502c476..e0cb709fc 100644 |
| 3 | +--- a/deps/github.com/openshift/kubernetes/pkg/registry/rbac/rest/storage_rbac.go |
| 4 | ++++ b/deps/github.com/openshift/kubernetes/pkg/registry/rbac/rest/storage_rbac.go |
| 5 | +@@ -169,7 +169,11 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc { |
| 6 | + utilruntime.HandleError(fmt.Errorf("unable to initialize client set: %v", err)) |
| 7 | + return false, nil |
| 8 | + } |
| 9 | +- return ensureRBACPolicy(p, client) |
| 10 | ++ // hookContext only cancels on server shutdown — add a per-attempt |
| 11 | ++ // deadline so individual API calls cannot block indefinitely. |
| 12 | ++ ctx, cancel := context.WithTimeout(hookContext, 5*time.Second) |
| 13 | ++ defer cancel() |
| 14 | ++ return ensureRBACPolicy(ctx, p, client) |
| 15 | + }) |
| 16 | + // if we're never able to make it through initialization, kill the API server |
| 17 | + if err != nil { |
| 18 | +@@ -180,26 +184,34 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc { |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | +-func ensureRBACPolicy(p *PolicyData, client clientset.Interface) (done bool, err error) { |
| 23 | ++func ensureRBACPolicy(ctx context.Context, p *PolicyData, client clientset.Interface) (done bool, err error) { |
| 24 | + failedReconciliation := false |
| 25 | + // Make sure etcd is responding before we start reconciling |
| 26 | +- if _, err := client.RbacV1().ClusterRoles().List(context.TODO(), metav1.ListOptions{}); err != nil { |
| 27 | ++ if _, err := client.RbacV1().ClusterRoles().List(ctx, metav1.ListOptions{}); err != nil { |
| 28 | ++ if ctx.Err() != nil { |
| 29 | ++ klog.Warningf("RBAC bootstrap attempt timed out waiting for etcd readiness, retrying") |
| 30 | ++ return false, nil |
| 31 | ++ } |
| 32 | + utilruntime.HandleError(fmt.Errorf("unable to initialize clusterroles: %v", err)) |
| 33 | + return false, nil |
| 34 | + } |
| 35 | +- if _, err := client.RbacV1().ClusterRoleBindings().List(context.TODO(), metav1.ListOptions{}); err != nil { |
| 36 | ++ if _, err := client.RbacV1().ClusterRoleBindings().List(ctx, metav1.ListOptions{}); err != nil { |
| 37 | ++ if ctx.Err() != nil { |
| 38 | ++ klog.Warningf("RBAC bootstrap attempt timed out waiting for etcd readiness, retrying") |
| 39 | ++ return false, nil |
| 40 | ++ } |
| 41 | + utilruntime.HandleError(fmt.Errorf("unable to initialize clusterrolebindings: %v", err)) |
| 42 | + return false, nil |
| 43 | + } |
| 44 | + |
| 45 | + // if the new cluster roles to aggregate do not yet exist, then we need to copy the old roles if they don't exist |
| 46 | + // in new locations |
| 47 | +- if err := primeAggregatedClusterRoles(p.ClusterRolesToAggregate, client.RbacV1()); err != nil { |
| 48 | ++ if err := primeAggregatedClusterRoles(ctx, p.ClusterRolesToAggregate, client.RbacV1()); err != nil { |
| 49 | + utilruntime.HandleError(fmt.Errorf("unable to prime aggregated clusterroles: %v", err)) |
| 50 | + return false, nil |
| 51 | + } |
| 52 | + |
| 53 | +- if err := primeSplitClusterRoleBindings(p.ClusterRoleBindingsToSplit, client.RbacV1()); err != nil { |
| 54 | ++ if err := primeSplitClusterRoleBindings(ctx, p.ClusterRoleBindingsToSplit, client.RbacV1()); err != nil { |
| 55 | + utilruntime.HandleError(fmt.Errorf("unable to prime split ClusterRoleBindings: %v", err)) |
| 56 | + return false, nil |
| 57 | + } |
| 58 | +@@ -345,9 +357,9 @@ func (p RESTStorageProvider) GroupName() string { |
| 59 | + |
| 60 | + // primeAggregatedClusterRoles copies roles that have transitioned to aggregated roles and may need to pick up changes |
| 61 | + // that were done to the legacy roles. |
| 62 | +-func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clusterRoleClient rbacv1client.ClusterRolesGetter) error { |
| 63 | ++func primeAggregatedClusterRoles(ctx context.Context, clusterRolesToAggregate map[string]string, clusterRoleClient rbacv1client.ClusterRolesGetter) error { |
| 64 | + for oldName, newName := range clusterRolesToAggregate { |
| 65 | +- _, err := clusterRoleClient.ClusterRoles().Get(context.TODO(), newName, metav1.GetOptions{}) |
| 66 | ++ _, err := clusterRoleClient.ClusterRoles().Get(ctx, newName, metav1.GetOptions{}) |
| 67 | + if err == nil { |
| 68 | + continue |
| 69 | + } |
| 70 | +@@ -355,7 +367,7 @@ func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clus |
| 71 | + return err |
| 72 | + } |
| 73 | + |
| 74 | +- existingRole, err := clusterRoleClient.ClusterRoles().Get(context.TODO(), oldName, metav1.GetOptions{}) |
| 75 | ++ existingRole, err := clusterRoleClient.ClusterRoles().Get(ctx, oldName, metav1.GetOptions{}) |
| 76 | + if apierrors.IsNotFound(err) { |
| 77 | + continue |
| 78 | + } |
| 79 | +@@ -369,7 +381,7 @@ func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clus |
| 80 | + klog.V(1).Infof("migrating %v to %v", existingRole.Name, newName) |
| 81 | + existingRole.Name = newName |
| 82 | + existingRole.ResourceVersion = "" // clear this so the object can be created. |
| 83 | +- if _, err := clusterRoleClient.ClusterRoles().Create(context.TODO(), existingRole, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { |
| 84 | ++ if _, err := clusterRoleClient.ClusterRoles().Create(ctx, existingRole, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { |
| 85 | + return err |
| 86 | + } |
| 87 | + } |
| 88 | +@@ -380,10 +392,10 @@ func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clus |
| 89 | + // primeSplitClusterRoleBindings ensures the existence of target ClusterRoleBindings |
| 90 | + // by copying Subjects, Annotations, and Labels from the specified source |
| 91 | + // ClusterRoleBinding, if present. |
| 92 | +-func primeSplitClusterRoleBindings(clusterRoleBindingToSplit map[string]rbacapiv1.ClusterRoleBinding, clusterRoleBindingClient rbacv1client.ClusterRoleBindingsGetter) error { |
| 93 | ++func primeSplitClusterRoleBindings(ctx context.Context, clusterRoleBindingToSplit map[string]rbacapiv1.ClusterRoleBinding, clusterRoleBindingClient rbacv1client.ClusterRoleBindingsGetter) error { |
| 94 | + for existingBindingName, clusterRoleBindingToCreate := range clusterRoleBindingToSplit { |
| 95 | + // If source ClusterRoleBinding does not exist, do nothing. |
| 96 | +- existingRoleBinding, err := clusterRoleBindingClient.ClusterRoleBindings().Get(context.TODO(), existingBindingName, metav1.GetOptions{}) |
| 97 | ++ existingRoleBinding, err := clusterRoleBindingClient.ClusterRoleBindings().Get(ctx, existingBindingName, metav1.GetOptions{}) |
| 98 | + if apierrors.IsNotFound(err) { |
| 99 | + continue |
| 100 | + } |
| 101 | +@@ -392,7 +404,7 @@ func primeSplitClusterRoleBindings(clusterRoleBindingToSplit map[string]rbacapiv |
| 102 | + } |
| 103 | + |
| 104 | + // If the target ClusterRoleBinding already exists, do nothing. |
| 105 | +- _, err = clusterRoleBindingClient.ClusterRoleBindings().Get(context.TODO(), clusterRoleBindingToCreate.Name, metav1.GetOptions{}) |
| 106 | ++ _, err = clusterRoleBindingClient.ClusterRoleBindings().Get(ctx, clusterRoleBindingToCreate.Name, metav1.GetOptions{}) |
| 107 | + if err == nil { |
| 108 | + continue |
| 109 | + } |
| 110 | +@@ -407,7 +419,7 @@ func primeSplitClusterRoleBindings(clusterRoleBindingToSplit map[string]rbacapiv |
| 111 | + newCRB.Subjects = existingRoleBinding.Subjects |
| 112 | + newCRB.Labels = existingRoleBinding.Labels |
| 113 | + newCRB.Annotations = existingRoleBinding.Annotations |
| 114 | +- if _, err := clusterRoleBindingClient.ClusterRoleBindings().Create(context.TODO(), newCRB, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { |
| 115 | ++ if _, err := clusterRoleBindingClient.ClusterRoleBindings().Create(ctx, newCRB, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { |
| 116 | + return err |
| 117 | + } |
| 118 | + } |
0 commit comments