Skip to content

Commit 6336f00

Browse files
author
Ram
committed
Handle len check for keypair resource transformation value
Signed-off-by: Ram <rsuradkar@purestorage.com>
1 parent 4374fed commit 6336f00

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

pkg/migration/controllers/resourcetransformation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ func (r *ResourceTransformationController) validateTransformResource(ctx context
270270
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)
271271
resInfo.Status = stork_api.ResourceTransformationStatusFailed
272272
resInfo.Reason = err.Error()
273+
return err
273274
}
274275
unstructured, ok := object.(*unstructured.Unstructured)
275276
if !ok {

pkg/resourcecollector/resourcetransformation.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,22 @@ func TransformResources(
8484
var value interface{}
8585
if path.Type == stork_api.KeyPairResourceType {
8686
currMap, _, err := unstructured.NestedMap(content, strings.Split(path.Path, ".")...)
87-
if err != nil {
88-
return fmt.Errorf("unable to find suspend path, err: %v", err)
87+
if err != nil || len(currMap) == 0 {
88+
return fmt.Errorf("unable to find spec path, err: %v", err)
8989
}
9090
mapList := strings.Split(path.Value, ",")
9191
for _, val := range mapList {
9292
keyPair := strings.Split(val, ":")
93+
if len(keyPair) != 2 {
94+
return fmt.Errorf("invalid keypair value format :%s", keyPair)
95+
}
9396
currMap[keyPair[0]] = keyPair[1]
9497
}
9598
value = currMap
9699
} else if path.Type == stork_api.SliceResourceType {
97100
currList, _, err := unstructured.NestedSlice(content, strings.Split(path.Path, ".")...)
98101
if err != nil {
99-
return fmt.Errorf("unable to find suspend path, err: %v", err)
102+
return fmt.Errorf("unable to find spec path, err: %v", err)
100103
}
101104
arrList := strings.Split(path.Value, ",")
102105
for _, val := range arrList {

pkg/schedule/schedule.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ func GetOptions(policyName string, namespace string, policyType stork_api.Schedu
231231
return schedulePolicy.Policy.Interval.Options, nil
232232
case stork_api.SchedulePolicyTypeDaily:
233233
options := schedulePolicy.Policy.Daily.Options
234+
if len(options) == 0 {
235+
options = make(map[string]string)
236+
}
234237
scheduledDay, ok := stork_api.Days[schedulePolicy.Policy.Daily.ForceFullSnapshotDay]
235238
if ok {
236239
currentDay := GetCurrentTime().Weekday()

0 commit comments

Comments
 (0)