Skip to content

Commit

Permalink
fix cluster labels patch format.
Browse files Browse the repository at this point in the history
Signed-off-by: morvencao <[email protected]>
  • Loading branch information
morvencao committed Nov 23, 2022
1 parent 3028100 commit 54a22eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pkg/hub/addon/discovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,12 @@ func (c *addOnFeatureDiscoveryController) syncAddOn(ctx context.Context, cluster
case errors.IsNotFound(err):
// addon is deleted
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName)
if _, exist := labels[key]; exist {
delete(labels, key)
labels[fmt.Sprintf("%s-", key)] = ""
}
delete(labels, key)
case err != nil:
return err
case !addOn.DeletionTimestamp.IsZero():
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName)
if _, exist := labels[key]; exist {
delete(labels, key)
labels[fmt.Sprintf("%s-", key)] = ""
}
delete(labels, key)
default:
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOn.Name)
labels[key] = getAddOnLabelValue(addOn)
Expand All @@ -163,6 +157,11 @@ func (c *addOnFeatureDiscoveryController) syncAddOn(ctx context.Context, cluster
return nil
}

// if labels is empty, put it to nil, otherwise patch operation will not take effect
if len(labels) == 0 {
labels = nil
}
// build cluster labels patch
patchBytes, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"labels": labels,
Expand Down Expand Up @@ -217,10 +216,7 @@ func (c *addOnFeatureDiscoveryController) syncCluster(ctx context.Context, clust

// addon is deleting
if !addOn.DeletionTimestamp.IsZero() {
if _, exist := addOnLabels[key]; exist {
delete(addOnLabels, key)
addOnLabels[fmt.Sprintf("%s-", key)] = ""
}
delete(addOnLabels, key)
continue
}

Expand All @@ -236,7 +232,6 @@ func (c *addOnFeatureDiscoveryController) syncCluster(ctx context.Context, clust

if _, ok := newAddonLabels[key]; !ok {
delete(addOnLabels, key)
addOnLabels[fmt.Sprintf("%s-", key)] = ""
}
}

Expand All @@ -245,6 +240,10 @@ func (c *addOnFeatureDiscoveryController) syncCluster(ctx context.Context, clust
return nil
}

// for empty addOnLabels, assign it to nil, otherwise patch operation will take no effect
if len(addOnLabels) == 0 {
addOnLabels = nil
}
// build cluster labels patch
patchBytes, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
Expand Down
4 changes: 4 additions & 0 deletions pkg/hub/taint/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (c *taintController) sync(ctx context.Context, syncCtx factory.SyncContext)
}

if updated {
// for empty newTaints, assign it to nil, otherwise patch operation will take no effect
if len(newTaints) == 0 {
newTaints = nil
}
// build cluster taints patch
patchBytes, err := json.Marshal(map[string]interface{}{
"spec": map[string]interface{}{
Expand Down

0 comments on commit 54a22eb

Please sign in to comment.