-
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.
Track the skipped PVC and print the summary in backup log
Signed-off-by: Daniel Jiang <[email protected]>
- Loading branch information
1 parent
e54a8af
commit 6c49c5e
Showing
13 changed files
with
500 additions
and
77 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
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,85 @@ | ||
package backup | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sort" | ||
"sync" | ||
) | ||
|
||
// skipPVTracker keeps track of persistent volumes that have been skipped and the reason why they are skipped. | ||
type skipPVTracker struct { | ||
*sync.RWMutex | ||
// pvs is a map of name of the pv to the list of reasons why it is skipped. | ||
// The reasons are stored in a map each key of the map is the backup approach, each approach can have one reason | ||
pvs map[string]map[string]string | ||
} | ||
|
||
const ( | ||
podVolumeApproach = "podvolume" | ||
csiSnapshotApproach = "csiSnapshot" | ||
volumeSnapshotApproach = "volumeSnapshot" | ||
anyApproach = "any" | ||
) | ||
|
||
// NotCSIError is the error for CSI plugin to communicate to velero that the volume is not CSI and is skipped | ||
var NotCSIError = errors.New("not a CSI volume") | ||
|
||
func NewSkipPVTracker() *skipPVTracker { | ||
return &skipPVTracker{ | ||
RWMutex: &sync.RWMutex{}, | ||
pvs: make(map[string]map[string]string), | ||
} | ||
} | ||
|
||
// Track tracks the pv with the specified name and the reason why it is skipped. | ||
func (pt *skipPVTracker) Track(name, approach, reason string) { | ||
|
||
pt.Lock() | ||
defer pt.Unlock() | ||
if name == "" || reason == "" { | ||
return | ||
} | ||
skipReasons := pt.pvs[name] | ||
if skipReasons == nil { | ||
skipReasons = make(map[string]string, 0) | ||
pt.pvs[name] = skipReasons | ||
} | ||
if approach == "" { | ||
approach = anyApproach | ||
} | ||
skipReasons[approach] = reason | ||
} | ||
|
||
// Untrack removes the pvc with the specified namespace and name. | ||
func (pt *skipPVTracker) Untrack(name string) { | ||
pt.Lock() | ||
defer pt.Unlock() | ||
delete(pt.pvs, name) | ||
} | ||
|
||
// Summary returns the summary of the tracked pvcs. | ||
func (pt *skipPVTracker) Summary() string { | ||
pt.RLock() | ||
defer pt.RUnlock() | ||
keys := make([]string, 0, len(pt.pvs)) | ||
for key := range pt.pvs { | ||
keys = append(keys, key) | ||
} | ||
sort.Strings(keys) | ||
res := "" | ||
for _, key := range keys { | ||
if skipReasons := pt.pvs[key]; skipReasons != nil && len(skipReasons) > 0 { | ||
res += fmt.Sprintf("PV: %s, skipped reasons: \n", key) | ||
approaches := make([]string, 0, len(skipReasons)) | ||
for a := range skipReasons { | ||
approaches = append(approaches, a) | ||
} | ||
sort.Strings(approaches) | ||
for _, a := range approaches { | ||
res += fmt.Sprintf("\tapproach: %s, reason: %s\n", a, skipReasons[a]) | ||
} | ||
} | ||
} | ||
return res | ||
} |
Oops, something went wrong.