diff --git a/internal/resourcemodifiers/resource_modifiers.go b/internal/resourcemodifiers/resource_modifiers.go index 24bb72eb8..3cab809be 100644 --- a/internal/resourcemodifiers/resource_modifiers.go +++ b/internal/resourcemodifiers/resource_modifiers.go @@ -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 { diff --git a/internal/resourcemodifiers/resource_modifiers_test.go b/internal/resourcemodifiers/resource_modifiers_test.go index 95211131e..f857f5e58 100644 --- a/internal/resourcemodifiers/resource_modifiers_test.go +++ b/internal/resourcemodifiers/resource_modifiers_test.go @@ -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", diff --git a/internal/resourcemodifiers/resource_modifiers_validator.go b/internal/resourcemodifiers/resource_modifiers_validator.go index 705c0c37a..d7f0dd6f0 100644 --- a/internal/resourcemodifiers/resource_modifiers_validator.go +++ b/internal/resourcemodifiers/resource_modifiers_validator.go @@ -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") diff --git a/internal/resourcemodifiers/resource_modifiers_validator_test.go b/internal/resourcemodifiers/resource_modifiers_validator_test.go index 95cb6db60..75dfaa6dd 100644 --- a/internal/resourcemodifiers/resource_modifiers_validator_test.go +++ b/internal/resourcemodifiers/resource_modifiers_validator_test.go @@ -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, diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 7e9ccfd78..54d9c0d46 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -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