mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-04-22 00:30:34 +00:00
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user