Signed-off-by: Anshul Ahuja <anshulahuja@microsoft.com>
This commit is contained in:
Anshul Ahuja
2023-07-06 11:29:33 +05:30
parent 4b3f6d41cb
commit 4e6d31dc38
5 changed files with 11 additions and 12 deletions

View File

@@ -21,7 +21,7 @@ const (
ResourceModifierSupportedVersionV1 = "v1"
)
type JsonPatch struct {
type JSONPatch struct {
Operation string `yaml:"operation"`
Path string `yaml:"path"`
Value string `yaml:"value,omitempty"`
@@ -35,7 +35,7 @@ type Conditions struct {
type ResourceModifierRule struct {
Conditions Conditions `yaml:"conditions"`
Patches []JsonPatch `yaml:"patches"`
Patches []JSONPatch `yaml:"patches"`
}
type ResourceModifiers struct {
@@ -111,7 +111,7 @@ func (r *ResourceModifierRule) PatchArrayToByteArray() ([]byte, error) {
return []byte(fmt.Sprintf(`[%s]`, patchesStr)), nil
}
func (p *JsonPatch) ToString() string {
func (p *JSONPatch) ToString() string {
return fmt.Sprintf(`{"op": "%s", "path": "%s", "value": "%s"}`, p.Operation, p.Path, p.Value)
}
@@ -122,7 +122,7 @@ func ApplyPatch(patch []byte, obj *unstructured.Unstructured, log logrus.FieldLo
}
objBytes, err := obj.MarshalJSON()
if err != nil {
return fmt.Errorf("error in marshalling object %s", err.Error())
return fmt.Errorf("error in marshaling object %s", err.Error())
}
modifiedObjBytes, err := jsonPatch.Apply(objBytes)
if err != nil {

View File

@@ -40,7 +40,7 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {
ResourceNameRegex: ".*",
Namespaces: []string{"bar", "foo"},
},
Patches: []JsonPatch{
Patches: []JSONPatch{
{
Operation: "replace",
Path: "/spec/storageClassName",
@@ -114,7 +114,7 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
ResourceNameRegex: ".*",
Namespaces: []string{"foo"},
},
Patches: []JsonPatch{
Patches: []JSONPatch{
{
Operation: "test",
Path: "/spec/storageClassName",

View File

@@ -36,7 +36,7 @@ func (p *ResourceModifiers) Validate() error {
return nil
}
func (p *JsonPatch) Validate() error {
func (p *JSONPatch) Validate() error {
// TODO validate allowed operation
if p.Operation == "" {
return fmt.Errorf("operation cannot be empty")

View File

@@ -25,7 +25,7 @@ func TestResourceModifiers_Validate(t *testing.T) {
ResourceNameRegex: ".*",
Namespaces: []string{"bar", "foo"},
},
Patches: []JsonPatch{
Patches: []JSONPatch{
{
Operation: "replace",
Path: "/spec/storageClassName",
@@ -48,7 +48,7 @@ func TestResourceModifiers_Validate(t *testing.T) {
ResourceNameRegex: ".*",
Namespaces: []string{"bar", "foo"},
},
Patches: []JsonPatch{
Patches: []JSONPatch{
{
Operation: "replace",
Path: "/spec/storageClassName",
@@ -124,7 +124,7 @@ func TestJsonPatch_Validate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &JsonPatch{
p := &JSONPatch{
Operation: tt.fields.Operation,
Path: tt.fields.Path,
Value: tt.fields.Value,

View File

@@ -38,7 +38,6 @@ import (
"k8s.io/utils/clock"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/vmware-tanzu/velero/internal/hook"
"github.com/vmware-tanzu/velero/internal/resourcemodifiers"
@@ -338,7 +337,7 @@ func (r *restoreReconciler) validateAndComplete(restore *api.Restore) (backupInf
var resourceModifiers *resourcemodifiers.ResourceModifiers = nil
if restore.Spec.ResourceModifier != nil && restore.Spec.ResourceModifier.Kind == resourcemodifiers.ConfigmapRefType {
ResourceModifierConfigMap := &corev1api.ConfigMap{}
err := r.kbClient.Get(context.Background(), kbclient.ObjectKey{Namespace: restore.Namespace, Name: restore.Spec.ResourceModifier.Name}, ResourceModifierConfigMap)
err := r.kbClient.Get(context.Background(), client.ObjectKey{Namespace: restore.Namespace, Name: restore.Spec.ResourceModifier.Name}, ResourceModifierConfigMap)
if err != nil {
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, fmt.Sprintf("failed to get resource modifiers configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name))
return backupInfo{}, nil