Skip to content

Commit

Permalink
Handle len check for keypair resource transformation value
Browse files Browse the repository at this point in the history
Signed-off-by: Ram <[email protected]>
  • Loading branch information
Ram committed Oct 20, 2022
1 parent 4374fed commit 6336f00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/migration/controllers/resourcetransformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func (r *ResourceTransformationController) validateTransformResource(ctx context
log.TransformLog(transform).Errorf("Unable to apply patch path %s on resource kind: %s/,%s/%s, err: %v", path, kind, resInfo.Namespace, resInfo.Name, err)
resInfo.Status = stork_api.ResourceTransformationStatusFailed
resInfo.Reason = err.Error()
return err
}
unstructured, ok := object.(*unstructured.Unstructured)
if !ok {
Expand Down
9 changes: 6 additions & 3 deletions pkg/resourcecollector/resourcetransformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,22 @@ func TransformResources(
var value interface{}
if path.Type == stork_api.KeyPairResourceType {
currMap, _, err := unstructured.NestedMap(content, strings.Split(path.Path, ".")...)
if err != nil {
return fmt.Errorf("unable to find suspend path, err: %v", err)
if err != nil || len(currMap) == 0 {
return fmt.Errorf("unable to find spec path, err: %v", err)
}
mapList := strings.Split(path.Value, ",")
for _, val := range mapList {
keyPair := strings.Split(val, ":")
if len(keyPair) != 2 {
return fmt.Errorf("invalid keypair value format :%s", keyPair)
}
currMap[keyPair[0]] = keyPair[1]
}
value = currMap
} else if path.Type == stork_api.SliceResourceType {
currList, _, err := unstructured.NestedSlice(content, strings.Split(path.Path, ".")...)
if err != nil {
return fmt.Errorf("unable to find suspend path, err: %v", err)
return fmt.Errorf("unable to find spec path, err: %v", err)
}
arrList := strings.Split(path.Value, ",")
for _, val := range arrList {
Expand Down
3 changes: 3 additions & 0 deletions pkg/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func GetOptions(policyName string, namespace string, policyType stork_api.Schedu
return schedulePolicy.Policy.Interval.Options, nil
case stork_api.SchedulePolicyTypeDaily:
options := schedulePolicy.Policy.Daily.Options
if len(options) == 0 {
options = make(map[string]string)
}
scheduledDay, ok := stork_api.Days[schedulePolicy.Policy.Daily.ForceFullSnapshotDay]
if ok {
currentDay := GetCurrentTime().Weekday()
Expand Down

0 comments on commit 6336f00

Please sign in to comment.