-
Notifications
You must be signed in to change notification settings - Fork 230
USHIFT-6401: Patch unbounded KAS context to break pre-hook deadlock #6635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
copejon
wants to merge
1
commit into
openshift:main
Choose a base branch
from
copejon:fix-USHIFT-6401-alt-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+134
−28
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
scripts/auto-rebase/rebase_patches/0040-rbac-bootstrap-hook-context-threading.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| 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 | ||
| index 16502c476..299034360 100644 | ||
| --- 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 | ||
| @@ -169,7 +169,7 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc { | ||
| utilruntime.HandleError(fmt.Errorf("unable to initialize client set: %v", err)) | ||
| return false, nil | ||
| } | ||
| - return ensureRBACPolicy(p, client) | ||
| + return ensureRBACPolicy(hookContext, p, client) | ||
| }) | ||
| // if we're never able to make it through initialization, kill the API server | ||
| if err != nil { | ||
| @@ -180,26 +180,26 @@ func (p *PolicyData) EnsureRBACPolicy() genericapiserver.PostStartHookFunc { | ||
| } | ||
| } | ||
|
|
||
| -func ensureRBACPolicy(p *PolicyData, client clientset.Interface) (done bool, err error) { | ||
| +func ensureRBACPolicy(ctx context.Context, p *PolicyData, client clientset.Interface) (done bool, err error) { | ||
| failedReconciliation := false | ||
| // Make sure etcd is responding before we start reconciling | ||
| - if _, err := client.RbacV1().ClusterRoles().List(context.TODO(), metav1.ListOptions{}); err != nil { | ||
| + if _, err := client.RbacV1().ClusterRoles().List(ctx, metav1.ListOptions{}); err != nil { | ||
| utilruntime.HandleError(fmt.Errorf("unable to initialize clusterroles: %v", err)) | ||
| return false, nil | ||
| } | ||
| - if _, err := client.RbacV1().ClusterRoleBindings().List(context.TODO(), metav1.ListOptions{}); err != nil { | ||
| + if _, err := client.RbacV1().ClusterRoleBindings().List(ctx, metav1.ListOptions{}); err != nil { | ||
| utilruntime.HandleError(fmt.Errorf("unable to initialize clusterrolebindings: %v", err)) | ||
| return false, nil | ||
| } | ||
|
|
||
| // if the new cluster roles to aggregate do not yet exist, then we need to copy the old roles if they don't exist | ||
| // in new locations | ||
| - if err := primeAggregatedClusterRoles(p.ClusterRolesToAggregate, client.RbacV1()); err != nil { | ||
| + if err := primeAggregatedClusterRoles(ctx, p.ClusterRolesToAggregate, client.RbacV1()); err != nil { | ||
| utilruntime.HandleError(fmt.Errorf("unable to prime aggregated clusterroles: %v", err)) | ||
| return false, nil | ||
| } | ||
|
|
||
| - if err := primeSplitClusterRoleBindings(p.ClusterRoleBindingsToSplit, client.RbacV1()); err != nil { | ||
| + if err := primeSplitClusterRoleBindings(ctx, p.ClusterRoleBindingsToSplit, client.RbacV1()); err != nil { | ||
| utilruntime.HandleError(fmt.Errorf("unable to prime split ClusterRoleBindings: %v", err)) | ||
| return false, nil | ||
| } | ||
| @@ -345,9 +345,9 @@ func (p RESTStorageProvider) GroupName() string { | ||
|
|
||
| // primeAggregatedClusterRoles copies roles that have transitioned to aggregated roles and may need to pick up changes | ||
| // that were done to the legacy roles. | ||
| -func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clusterRoleClient rbacv1client.ClusterRolesGetter) error { | ||
| +func primeAggregatedClusterRoles(ctx context.Context, clusterRolesToAggregate map[string]string, clusterRoleClient rbacv1client.ClusterRolesGetter) error { | ||
| for oldName, newName := range clusterRolesToAggregate { | ||
| - _, err := clusterRoleClient.ClusterRoles().Get(context.TODO(), newName, metav1.GetOptions{}) | ||
| + _, err := clusterRoleClient.ClusterRoles().Get(ctx, newName, metav1.GetOptions{}) | ||
| if err == nil { | ||
| continue | ||
| } | ||
| @@ -355,7 +355,7 @@ func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clus | ||
| return err | ||
| } | ||
|
|
||
| - existingRole, err := clusterRoleClient.ClusterRoles().Get(context.TODO(), oldName, metav1.GetOptions{}) | ||
| + existingRole, err := clusterRoleClient.ClusterRoles().Get(ctx, oldName, metav1.GetOptions{}) | ||
| if apierrors.IsNotFound(err) { | ||
| continue | ||
| } | ||
| @@ -369,7 +369,7 @@ func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clus | ||
| klog.V(1).Infof("migrating %v to %v", existingRole.Name, newName) | ||
| existingRole.Name = newName | ||
| existingRole.ResourceVersion = "" // clear this so the object can be created. | ||
| - if _, err := clusterRoleClient.ClusterRoles().Create(context.TODO(), existingRole, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { | ||
| + if _, err := clusterRoleClient.ClusterRoles().Create(ctx, existingRole, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { | ||
| return err | ||
| } | ||
| } | ||
| @@ -380,10 +380,10 @@ func primeAggregatedClusterRoles(clusterRolesToAggregate map[string]string, clus | ||
| // primeSplitClusterRoleBindings ensures the existence of target ClusterRoleBindings | ||
| // by copying Subjects, Annotations, and Labels from the specified source | ||
| // ClusterRoleBinding, if present. | ||
| -func primeSplitClusterRoleBindings(clusterRoleBindingToSplit map[string]rbacapiv1.ClusterRoleBinding, clusterRoleBindingClient rbacv1client.ClusterRoleBindingsGetter) error { | ||
| +func primeSplitClusterRoleBindings(ctx context.Context, clusterRoleBindingToSplit map[string]rbacapiv1.ClusterRoleBinding, clusterRoleBindingClient rbacv1client.ClusterRoleBindingsGetter) error { | ||
| for existingBindingName, clusterRoleBindingToCreate := range clusterRoleBindingToSplit { | ||
| // If source ClusterRoleBinding does not exist, do nothing. | ||
| - existingRoleBinding, err := clusterRoleBindingClient.ClusterRoleBindings().Get(context.TODO(), existingBindingName, metav1.GetOptions{}) | ||
| + existingRoleBinding, err := clusterRoleBindingClient.ClusterRoleBindings().Get(ctx, existingBindingName, metav1.GetOptions{}) | ||
| if apierrors.IsNotFound(err) { | ||
| continue | ||
| } | ||
| @@ -392,7 +392,7 @@ func primeSplitClusterRoleBindings(clusterRoleBindingToSplit map[string]rbacapiv | ||
| } | ||
|
|
||
| // If the target ClusterRoleBinding already exists, do nothing. | ||
| - _, err = clusterRoleBindingClient.ClusterRoleBindings().Get(context.TODO(), clusterRoleBindingToCreate.Name, metav1.GetOptions{}) | ||
| + _, err = clusterRoleBindingClient.ClusterRoleBindings().Get(ctx, clusterRoleBindingToCreate.Name, metav1.GetOptions{}) | ||
| if err == nil { | ||
| continue | ||
| } | ||
| @@ -407,7 +407,7 @@ func primeSplitClusterRoleBindings(clusterRoleBindingToSplit map[string]rbacapiv | ||
| newCRB.Subjects = existingRoleBinding.Subjects | ||
| newCRB.Labels = existingRoleBinding.Labels | ||
| newCRB.Annotations = existingRoleBinding.Annotations | ||
| - if _, err := clusterRoleBindingClient.ClusterRoleBindings().Create(context.TODO(), newCRB, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { | ||
| + if _, err := clusterRoleBindingClient.ClusterRoleBindings().Create(ctx, newCRB, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { | ||
| return err | ||
| } | ||
| } |
28 changes: 14 additions & 14 deletions
28
vendor/k8s.io/kubernetes/pkg/registry/rbac/rest/storage_rbac.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if that context has a deadline? Or is it just a context for signaling shutdown?
Because if it's the latter, it improves nothing - it won't expire on its own to break the deadlock.
Maybe we need to wrap the context with .WithTimeout() based on wait.Poll() params as well? Or just use the 15 seconds from previous PR.
Because if I'm correct and hookContext does not time out, then we gained nothing.