Skip to content

Commit

Permalink
fix: Cluster API does not support updating labels and annotations (#7901
Browse files Browse the repository at this point in the history
)

Signed-off-by: May Zhang <may_zhang@intuit.com>
  • Loading branch information
mayzhang2000 authored Dec 10, 2021
1 parent bea379b commit a51169e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ var clusterFieldsByPath = map[string]func(updated *appv1.Cluster, existing *appv
"clusterResources": func(updated *appv1.Cluster, existing *appv1.Cluster) {
updated.ClusterResources = existing.ClusterResources
},
"labels": func(updated *appv1.Cluster, existing *appv1.Cluster) {
updated.Labels = existing.Labels
},
"annotations": func(updated *appv1.Cluster, existing *appv1.Cluster) {
updated.Annotations = existing.Annotations
},
}

// Update updates a cluster
Expand Down
34 changes: 34 additions & 0 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,38 @@ func TestUpdateCluster_FieldsPathSet(t *testing.T) {
assert.Equal(t, updated.Name, "minikube")
assert.Equal(t, updated.Namespaces, []string{"default", "kube-system"})
assert.Equal(t, *updated.Shard, int64(1))

labelEnv := map[string]string{
"env": "qa",
}
_, err = server.Update(context.Background(), &clusterapi.ClusterUpdateRequest{
Cluster: &v1alpha1.Cluster{
Server: "https://127.0.0.1",
Labels: labelEnv,
},
UpdatedFields: []string{"labels"},
})

require.NoError(t, err)

assert.Equal(t, updated.Name, "minikube")
assert.Equal(t, updated.Namespaces, []string{"default", "kube-system"})
assert.Equal(t, updated.Labels, labelEnv)

annotationEnv := map[string]string{
"env": "qa",
}
_, err = server.Update(context.Background(), &clusterapi.ClusterUpdateRequest{
Cluster: &v1alpha1.Cluster{
Server: "https://127.0.0.1",
Annotations: annotationEnv,
},
UpdatedFields: []string{"annotations"},
})

require.NoError(t, err)

assert.Equal(t, updated.Name, "minikube")
assert.Equal(t, updated.Namespaces, []string{"default", "kube-system"})
assert.Equal(t, updated.Annotations, annotationEnv)
}

0 comments on commit a51169e

Please sign in to comment.