Skip to content

Commit

Permalink
Merge pull request #4800 from yizhang-zen/yizhang/rename
Browse files Browse the repository at this point in the history
Rename a function to match with updated behavior
  • Loading branch information
karmada-bot committed Apr 10, 2024
2 parents 02a6e5e + 04395e3 commit bc60437
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/controllers/status/work_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *WorkStatusController) RunWorkQueue() {
// generateKey generates a key from obj, the key contains cluster, GVK, namespace and name.
func generateKey(obj interface{}) (util.QueueKey, error) {
resource := obj.(*unstructured.Unstructured)
cluster, err := getClusterNameFromLabel(resource)
cluster, err := getClusterNameFromAnnotation(resource)
if err != nil {
return nil, err
}
Expand All @@ -164,8 +164,8 @@ func generateKey(obj interface{}) (util.QueueKey, error) {
return keys.FederatedKeyFunc(cluster, obj)
}

// getClusterNameFromLabel gets cluster name from ownerLabel, if label not exist, means resource is not created by karmada.
func getClusterNameFromLabel(resource *unstructured.Unstructured) (string, error) {
// getClusterNameFromAnnotation gets cluster name from ownerLabel, if label not exist, means resource is not created by karmada.
func getClusterNameFromAnnotation(resource *unstructured.Unstructured) (string, error) {
workNamespace, exist := resource.GetAnnotations()[workv1alpha2.WorkNamespaceAnnotation]
if !exist {
klog.V(4).Infof("Ignore resource(%s/%s/%s) which not managed by karmada", resource.GetKind(), resource.GetNamespace(), resource.GetName())
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/status/work_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestGenerateKey(t *testing.T) {
existErr: false,
},
{
name: "getClusterNameFromLabel failed",
name: "getClusterNameFromAnnotation failed",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestGenerateKey(t *testing.T) {
}
}

func TestGetClusterNameFromLabel(t *testing.T) {
func TestGetClusterNameFromAnnotation(t *testing.T) {
tests := []struct {
name string
resource *unstructured.Unstructured
Expand Down Expand Up @@ -502,7 +502,7 @@ func TestGetClusterNameFromLabel(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual, err := getClusterNameFromLabel(tt.resource)
actual, err := getClusterNameFromAnnotation(tt.resource)
assert.Equal(t, tt.expect, actual)
if tt.existErr {
assert.NotEmpty(t, err)
Expand Down

0 comments on commit bc60437

Please sign in to comment.