diff --git a/pkg/yurthub/storage/disk/storage.go b/pkg/yurthub/storage/disk/storage.go index 69e55f6801d..4128938c25d 100644 --- a/pkg/yurthub/storage/disk/storage.go +++ b/pkg/yurthub/storage/disk/storage.go @@ -460,16 +460,19 @@ func (ds *diskStorage) lockKey(key string) bool { ds.Lock() defer ds.Unlock() if _, ok := ds.keyPendingStatus[key]; ok { + klog.Infof("key(%s) storage is pending, just skip it", key) return false } for pendingKey := range ds.keyPendingStatus { if len(key) > len(pendingKey) { - if strings.Contains(key, pendingKey) { + if strings.Contains(key, fmt.Sprintf("%s/", pendingKey)) { + klog.Infof("key(%s) storage is pending, skip to store key(%s)", pendingKey, key) return false } } else { - if strings.Contains(pendingKey, key) { + if strings.Contains(pendingKey, fmt.Sprintf("%s/", key)) { + klog.Infof("key(%s) storage is pending, skip to store key(%s)", pendingKey, key) return false } } diff --git a/pkg/yurthub/storage/disk/storage_test.go b/pkg/yurthub/storage/disk/storage_test.go index 78dad3495a4..fe0ab229f2d 100644 --- a/pkg/yurthub/storage/disk/storage_test.go +++ b/pkg/yurthub/storage/disk/storage_test.go @@ -685,6 +685,12 @@ func TestLockKey(t *testing.T) { lockResult: true, lockVerifyResult: false, }, + "lock same prefix key with pre-locked key ": { + preLockedKeys: []string{"kubelet/pods/kube-system/foo"}, + lockKey: "kubelet/pods/kube-system/foo2", + lockResult: true, + lockVerifyResult: false, + }, } s := &diskStorage{