-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tracking for deleted namespace status check in restore flow
Signed-off-by: sangitaray2021 <[email protected]> fixed unittest Signed-off-by: sangitaray2021 <[email protected]> refactored tracker execution and caller Signed-off-by: sangitaray2021 <[email protected]> added change log Signed-off-by: sangitaray2021 <[email protected]> Author: sangitaray2021 <[email protected]> Author: sangitaray2021 <[email protected]> Date: Thu Sep 19 02:26:14 2024 +0530
- Loading branch information
1 parent
3f9c2dc
commit 72d3b56
Showing
8 changed files
with
178 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added tracking for deleted namespace status check in restore flow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2018 the Velero contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package kube | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
) | ||
|
||
// NamespaceDeletionStatusTracker keeps track of in-progress backups. | ||
type NamespaceDeletionStatusTracker interface { | ||
// Add informs the tracker that a polling is in progress to check namespace deletion status. | ||
Add(ns, name string) | ||
// Delete informs the tracker that a namespace deletion is completed. | ||
Delete(ns, name string) | ||
// Contains returns true if the tracker is tracking the namespace deletion progress. | ||
Contains(ns, name string) bool | ||
} | ||
|
||
type namespaceDeletionStatusTracker struct { | ||
lock sync.RWMutex | ||
isNameSpacePresentInPollingSet sets.Set[string] | ||
} | ||
|
||
// NewNamespaceDeletionStatusTracker returns a new NamespaceDeletionStatusTracker. | ||
func NewNamespaceDeletionStatusTracker() NamespaceDeletionStatusTracker { | ||
return &namespaceDeletionStatusTracker{ | ||
isNameSpacePresentInPollingSet: sets.New[string](), | ||
} | ||
} | ||
|
||
func (bt *namespaceDeletionStatusTracker) Add(ns, name string) { | ||
bt.lock.Lock() | ||
defer bt.lock.Unlock() | ||
|
||
bt.isNameSpacePresentInPollingSet.Insert(namespaceDeletionStatusTrackerKey(ns, name)) | ||
} | ||
|
||
func (bt *namespaceDeletionStatusTracker) Delete(ns, name string) { | ||
bt.lock.Lock() | ||
defer bt.lock.Unlock() | ||
|
||
bt.isNameSpacePresentInPollingSet.Delete(namespaceDeletionStatusTrackerKey(ns, name)) | ||
} | ||
|
||
func (bt *namespaceDeletionStatusTracker) Contains(ns, name string) bool { | ||
bt.lock.RLock() | ||
defer bt.lock.RUnlock() | ||
|
||
return bt.isNameSpacePresentInPollingSet.Has(namespaceDeletionStatusTrackerKey(ns, name)) | ||
} | ||
|
||
func namespaceDeletionStatusTrackerKey(ns, name string) string { | ||
return fmt.Sprintf("%s/%s", ns, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters