Skip to content

Commit

Permalink
Improved error messages for enforced backup/restore spec
Browse files Browse the repository at this point in the history
Enforced backup/restore spec validation errors now include the
enforced value in addition to the field name.
  • Loading branch information
sseago committed Feb 6, 2025
1 parent 720430d commit a1ea7c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/common/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func ValidateBackupSpec(nonAdminBackup *nacv1alpha1.NonAdminBackup, enforcedBack
field, _ := reflect.TypeOf(nonAdminBackup.Spec.BackupSpec).Elem().FieldByName(enforcedFieldName)
tagName, _, _ := strings.Cut(field.Tag.Get(constant.JSONTagString), constant.CommaString)
return fmt.Errorf(
"NonAdminBackup spec.backupSpec.%v field value is enforced by admin user, can not override it",
"the administrator has restricted spec.backupSpec.%v field value to %v",
tagName,
reflect.Indirect(enforcedField),
)
}
}
Expand Down Expand Up @@ -158,8 +159,9 @@ func ValidateRestoreSpec(ctx context.Context, clientInstance client.Client, nonA
field, _ := reflect.TypeOf(nonAdminRestore.Spec.RestoreSpec).Elem().FieldByName(enforcedFieldName)
tagName, _, _ := strings.Cut(field.Tag.Get(constant.JSONTagString), constant.CommaString)
return fmt.Errorf(
"NonAdminRestore spec.restoreSpec.%v field value is enforced by admin user, can not override it",
"the administrator has restricted spec.restoreSpec.%v field value to %v",
tagName,
reflect.Indirect(enforcedField),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nonadminbackup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ var _ = ginkgo.Describe("Test full reconcile loop of NonAdminBackup Controller",
Type: "Accepted",
Status: metav1.ConditionFalse,
Reason: "InvalidBackupSpec",
Message: "spec.backupSpec.snapshotVolumes field value is enforced by admin user",
Message: "the administrator has restricted spec.backupSpec.snapshotVolumes field value to false",
},
},
},
Expand Down

0 comments on commit a1ea7c8

Please sign in to comment.