Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
address comments.
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 54a22eb commit d42d27e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/hub/addon/discovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,16 @@ func (c *addOnFeatureDiscoveryController) syncAddOn(ctx context.Context, cluster
}

addOn, err := c.addOnLister.ManagedClusterAddOns(clusterName).Get(addOnName)
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName)
switch {
case errors.IsNotFound(err):
// addon is deleted
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName)
delete(labels, key)
labels[key] = nil
case err != nil:
return err
case !addOn.DeletionTimestamp.IsZero():
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOnName)
delete(labels, key)
labels[key] = nil
default:
key := fmt.Sprintf("%s%s", addOnFeaturePrefix, addOn.Name)
labels[key] = getAddOnLabelValue(addOn)
}

Expand All @@ -165,7 +163,9 @@ func (c *addOnFeatureDiscoveryController) syncAddOn(ctx context.Context, cluster
patchBytes, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"labels": labels,
},
"uid": cluster.UID,
"resourceVersion": cluster.ResourceVersion,
}, // to ensure they appear in the patch as preconditions
})
if err != nil {
return fmt.Errorf("failed to create patch for cluster %s: %w", cluster.Name, err)
Expand Down Expand Up @@ -216,7 +216,7 @@ func (c *addOnFeatureDiscoveryController) syncCluster(ctx context.Context, clust

// addon is deleting
if !addOn.DeletionTimestamp.IsZero() {
delete(addOnLabels, key)
addOnLabels[key] = nil
continue
}

Expand All @@ -231,7 +231,7 @@ func (c *addOnFeatureDiscoveryController) syncCluster(ctx context.Context, clust
}

if _, ok := newAddonLabels[key]; !ok {
delete(addOnLabels, key)
addOnLabels[key] = nil
}
}

Expand All @@ -248,7 +248,9 @@ func (c *addOnFeatureDiscoveryController) syncCluster(ctx context.Context, clust
patchBytes, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"labels": addOnLabels,
},
"uid": cluster.UID,
"resourceVersion": cluster.ResourceVersion,
}, // to ensure they appear in the patch as preconditions
})
if err != nil {
return fmt.Errorf("failed to create patch for cluster %s: %w", cluster.Name, err)
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 @@ -96,6 +96,10 @@ func (c *taintController) sync(ctx context.Context, syncCtx factory.SyncContext)
}
// build cluster taints patch
patchBytes, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"uid": managedCluster.UID,
"resourceVersion": managedCluster.ResourceVersion,
}, // to ensure they appear in the patch as preconditions
"spec": map[string]interface{}{
"taints": newTaints,
},
Expand Down

0 comments on commit d42d27e

Please sign in to comment.