Rename func to getClusterNameFromAnnotation to match with updated behavior
Signed-off-by: yizhang-zen <yizhang@zendesk.com>
This commit is contained in:
parent
b0da31afc1
commit
04395e3579
|
@ -152,7 +152,7 @@ func (c *WorkStatusController) RunWorkQueue() {
|
||||||
// generateKey generates a key from obj, the key contains cluster, GVK, namespace and name.
|
// generateKey generates a key from obj, the key contains cluster, GVK, namespace and name.
|
||||||
func generateKey(obj interface{}) (util.QueueKey, error) {
|
func generateKey(obj interface{}) (util.QueueKey, error) {
|
||||||
resource := obj.(*unstructured.Unstructured)
|
resource := obj.(*unstructured.Unstructured)
|
||||||
cluster, err := getClusterNameFromLabel(resource)
|
cluster, err := getClusterNameFromAnnotation(resource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -164,8 +164,8 @@ func generateKey(obj interface{}) (util.QueueKey, error) {
|
||||||
return keys.FederatedKeyFunc(cluster, obj)
|
return keys.FederatedKeyFunc(cluster, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getClusterNameFromLabel gets cluster name from ownerLabel, if label not exist, means resource is not created by karmada.
|
// getClusterNameFromAnnotation gets cluster name from ownerLabel, if label not exist, means resource is not created by karmada.
|
||||||
func getClusterNameFromLabel(resource *unstructured.Unstructured) (string, error) {
|
func getClusterNameFromAnnotation(resource *unstructured.Unstructured) (string, error) {
|
||||||
workNamespace, exist := resource.GetAnnotations()[workv1alpha2.WorkNamespaceAnnotation]
|
workNamespace, exist := resource.GetAnnotations()[workv1alpha2.WorkNamespaceAnnotation]
|
||||||
if !exist {
|
if !exist {
|
||||||
klog.V(4).Infof("Ignore resource(%s/%s/%s) which not managed by karmada", resource.GetKind(), resource.GetNamespace(), resource.GetName())
|
klog.V(4).Infof("Ignore resource(%s/%s/%s) which not managed by karmada", resource.GetKind(), resource.GetNamespace(), resource.GetName())
|
||||||
|
|
|
@ -382,7 +382,7 @@ func TestGenerateKey(t *testing.T) {
|
||||||
existErr: false,
|
existErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "getClusterNameFromLabel failed",
|
name: "getClusterNameFromAnnotation failed",
|
||||||
obj: &unstructured.Unstructured{
|
obj: &unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
|
@ -437,7 +437,7 @@ func TestGenerateKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetClusterNameFromLabel(t *testing.T) {
|
func TestGetClusterNameFromAnnotation(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
resource *unstructured.Unstructured
|
resource *unstructured.Unstructured
|
||||||
|
@ -502,7 +502,7 @@ func TestGetClusterNameFromLabel(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
actual, err := getClusterNameFromLabel(tt.resource)
|
actual, err := getClusterNameFromAnnotation(tt.resource)
|
||||||
assert.Equal(t, tt.expect, actual)
|
assert.Equal(t, tt.expect, actual)
|
||||||
if tt.existErr {
|
if tt.existErr {
|
||||||
assert.NotEmpty(t, err)
|
assert.NotEmpty(t, err)
|
||||||
|
|
Loading…
Reference in New Issue