-
Notifications
You must be signed in to change notification settings - Fork 58
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
fix cluster labels update conflict. #287
base: main
Are you sure you want to change the base?
fix cluster labels update conflict. #287
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: morvencao The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
return nil | ||
} | ||
|
||
// otherwise, update cluster | ||
_, err = c.clusterClient.ClusterV1().ManagedClusters().Update(ctx, cluster, metav1.UpdateOptions{}) | ||
oldData, err := json.Marshal(clusterv1.ManagedCluster{ |
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.
maybe we could only build the patch like
patch := fmt.Sprintf("{\"metadata\": {\"finalizers\": %s}}", string(finalizerBytes)) |
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.
and the unit tests need to be updated too
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.
done.
/hold |
058c319
to
af19cfd
Compare
// no work if the cluster labels have no change | ||
if !modified { | ||
return nil | ||
} |
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.
How about keeping the modified check, after the modified check, we create patchBytes
and apply the patch, thus we can avoid to path the same thing
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.
added label equality check, if they are equal, no need to patch.
return nil | ||
} | ||
// patch the cluster labels | ||
_, err = c.clusterClient.ClusterV1().ManagedClusters().Patch(ctx, cluster.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{}, "") |
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.
nit: we can omit the empty string ""
at the end of Patch function
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.
nice catch! done.
return nil | ||
} | ||
// patch the cluster labels | ||
_, err = c.clusterClient.ClusterV1().ManagedClusters().Patch(ctx, cluster.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{}, "") |
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.
nit: we can omit the empty string ""
at the end of Patch function
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.
done.
resourcemerge.MergeMap(&modified, &cluster.Labels, addOnLabels) | ||
|
||
// no work if the cluster labels have no change | ||
if !modified { |
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.
How about keeping the modified check, after the modified check, we create patchBytes
and apply the patch, thus we can avoid to path the same thing
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.
added label equality check, if they are equal, no need to patch.
1ed4b3c
to
3c8be77
Compare
is the integration test failure relevant? |
/hold cancel |
it seems not, restart the test to have a try |
Signed-off-by: morvencao <[email protected]>
3c8be77
to
004c7cb
Compare
Signed-off-by: morvencao <[email protected]>
9c6ee0c
to
a49c139
Compare
Signed-off-by: morvencao <[email protected]>
a49c139
to
54a22eb
Compare
addOn, err := c.addOnLister.ManagedClusterAddOns(clusterName).Get(addOnName) | ||
switch { | ||
case errors.IsNotFound(err): | ||
// addon is deleted | ||
key := fmt.Sprintf("%s%s-", addOnFeaturePrefix, addOnName) | ||
labels[key] = "" | ||
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName) |
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.
nit I think you can build key apriori instead of in each case
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.
done
key := fmt.Sprintf("%s%s-", addOnFeaturePrefix, addOnName) | ||
labels[key] = "" | ||
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName) | ||
delete(labels, key) |
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.
should this be labels[key] = nil?
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.
it will not work since labels are known type(map[string]string
), set value to nil
, it will complain;
pkg/hub/addon/discovery_controller.go:144:17: cannot use nil as string value in assignment
pkg/hub/addon/discovery_controller.go:148:17: cannot use nil as string value in assignment
pkg/hub/addon/discovery_controller.go:219:23: cannot use nil as string value in assignment
pkg/hub/addon/discovery_controller.go:234:23: cannot use nil as string value in assignment
key := fmt.Sprintf("%s%s-", addOnFeaturePrefix, addOnName) | ||
labels[key] = "" | ||
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName) | ||
delete(labels, key) |
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.
should this be labels[key] = nil?
newTaints = nil | ||
} | ||
// build cluster taints patch | ||
patchBytes, err := json.Marshal(map[string]interface{}{ |
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.
it is better to add uid/resourceversion is precond.
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.
added uid/resourceversion as precond
@@ -110,48 +112,68 @@ func (c *addOnFeatureDiscoveryController) sync(ctx context.Context, syncCtx fact | |||
func (c *addOnFeatureDiscoveryController) syncAddOn(ctx context.Context, clusterName, addOnName string) error { | |||
klog.V(4).Infof("Reconciling addOn %q", addOnName) | |||
|
|||
labels := map[string]string{} |
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 do not remember why we need syncAddOn, seems to me syncCluster is sufficient...
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.
From integration testing, the syncAddOn
is covered, so it is still being used?
// addon is deleting | ||
if !addOn.DeletionTimestamp.IsZero() { | ||
delete(addOnLabels, key) |
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.
set to nil if the key exists
if _, ok := addOnLabels[key]; !ok { | ||
addOnLabels[fmt.Sprintf("%s-", key)] = "" | ||
if _, ok := newAddonLabels[key]; !ok { | ||
delete(addOnLabels, key) |
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.
set to nil if the key exists
Signed-off-by: morvencao <[email protected]>
d42d27e
to
5dbc6af
Compare
@qiujian16 Another look? all comments addressed except the one
|
you cannot set nil in map[string]string, but you can do it in map[string]interface{}. The patch you generate should be based on a map[string]interface{}. |
Any benefit to use |
you can delete a key with map[string]interface{} |
fix cluster labels update conflict:
Signed-off-by: morvencao [email protected]