-
Notifications
You must be signed in to change notification settings - Fork 64
fix(rbg): use SSA Apply with distinct field managers on RBG writes #309
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,15 +24,13 @@ import ( | |
|
|
||
| "github.com/pkg/errors" | ||
| corev1 "k8s.io/api/core/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| metaapplyv1 "k8s.io/client-go/applyconfigurations/meta/v1" | ||
| "k8s.io/client-go/tools/record" | ||
| "k8s.io/client-go/util/retry" | ||
| "k8s.io/klog/v2" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/builder" | ||
|
|
@@ -498,28 +496,25 @@ func (r *RoleBasedGroupScalingAdapterReconciler) GetTargetRbgFromAdapter( | |
| func (r *RoleBasedGroupScalingAdapterReconciler) updateRoleReplicas( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All calls to Is there a guarantee that only one RBGSA at a time updates replicas for a given RBG? If multiple RBGSAs can exist per RBG, a per-role field manager like |
||
| ctx context.Context, rbg *workloadsv1alpha2.RoleBasedGroup, targetRoleName string, newReplicas *int32, | ||
| ) error { | ||
| return retry.RetryOnConflict( | ||
| retry.DefaultBackoff, func() error { | ||
| for index, role := range rbg.Spec.Roles { | ||
| if role.Name == targetRoleName { | ||
| role.Replicas = newReplicas | ||
| rbg.Spec.Roles[index] = role | ||
| break | ||
| } | ||
| } | ||
| if err := r.client.Update(ctx, rbg); err != nil { | ||
| if apierrors.IsConflict(err) { | ||
| if err := r.client.Get( | ||
| ctx, types.NamespacedName{Name: rbg.Name, Namespace: rbg.Namespace}, rbg, | ||
| ); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return err | ||
| } | ||
| return nil | ||
| }, | ||
| ) | ||
| gvk := utils.GetRbgGVK() | ||
| applyCfg := applyconfiguration.RoleBasedGroup(rbg.Name, rbg.Namespace). | ||
| WithKind(gvk.Kind). | ||
| WithAPIVersion(gvk.GroupVersion().String()). | ||
| WithSpec( | ||
| applyconfiguration.RoleBasedGroupSpec(). | ||
| WithRoles( | ||
| applyconfiguration.RoleSpec(). | ||
| WithName(targetRoleName). | ||
| WithReplicas(*newReplicas), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old code assigned Non-blocking -- just something to keep in mind. |
||
| ), | ||
| ) | ||
|
|
||
| if err := utils.PatchObjectApplyConfigurationWithFieldManager( | ||
| ctx, r.client, applyCfg, utils.PatchSpec, utils.RBGReplicaFieldManager, | ||
| ); err != nil { | ||
| return fmt.Errorf("apply replica update for role %q: %w", targetRoleName, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // extractLabelSelectorDefault extracts a LabelSelector string from the given role's scale subresource. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.