parent
6307a43004
commit
a00cf9ad2c
|
@ -23,7 +23,7 @@ const (
|
|||
type JsonPatch struct {
|
||||
Operation string `yaml:"operation"`
|
||||
Path string `yaml:"path"`
|
||||
NewValue string `yaml:"newValue,omitempty"`
|
||||
Value string `yaml:"value,omitempty"`
|
||||
}
|
||||
|
||||
type Conditions struct {
|
||||
|
@ -111,7 +111,7 @@ func (r *ResourceModifierRule) PatchArrayToByteArray() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (p *JsonPatch) ToString() string {
|
||||
return fmt.Sprintf(`{"op": "%s", "path": "%s", "value": "%s"}`, p.Operation, p.Path, p.NewValue)
|
||||
return fmt.Sprintf(`{"op": "%s", "path": "%s", "value": "%s"}`, p.Operation, p.Path, p.Value)
|
||||
}
|
||||
|
||||
func ApplyPatch(patch []byte, obj *unstructured.Unstructured, log logrus.FieldLogger) error {
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {
|
|||
Namespace: "test-namespace",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"sub.yml": "# kubectl delete cm jsonsub-configmap -n velero\n# kubectl create cm jsonsub-configmap --from-file /home/anshulahuja/workspace/fork-velero/tilt-resources/examples/sub.yml -nvelero\nversion: v1\nresourceModifierRules:\n- conditions:\n groupKind: persistentvolumeclaims.storage.k8s.io\n resourceNameRegex: \".*\"\n namespaces:\n - bar\n - foo\n patches:\n - operation: replace\n path: \"/spec/storageClassName\"\n newValue: \"premium\"\n - operation: remove\n path: \"/metadata/labels/test\"\n\n\n",
|
||||
"sub.yml": "# kubectl delete cm jsonsub-configmap -n velero\n# kubectl create cm jsonsub-configmap --from-file /home/anshulahuja/workspace/fork-velero/tilt-resources/examples/sub.yml -nvelero\nversion: v1\nresourceModifierRules:\n- conditions:\n groupKind: persistentvolumeclaims.storage.k8s.io\n resourceNameRegex: \".*\"\n namespaces:\n - bar\n - foo\n patches:\n - operation: replace\n path: \"/spec/storageClassName\"\n Value: \"premium\"\n - operation: remove\n path: \"/metadata/labels/test\"\n\n\n",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {
|
|||
{
|
||||
Operation: "replace",
|
||||
Path: "/spec/storageClassName",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
{
|
||||
Operation: "remove",
|
||||
|
@ -115,10 +115,15 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
|
|||
Namespaces: []string{"foo"},
|
||||
},
|
||||
Patches: []JsonPatch{
|
||||
{
|
||||
Operation: "test",
|
||||
Path: "/spec/storageClassName",
|
||||
Value: "standard",
|
||||
},
|
||||
{
|
||||
Operation: "replace",
|
||||
Path: "/spec/storageClassName",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestResourceModifiers_Validate(t *testing.T) {
|
|||
{
|
||||
Operation: "replace",
|
||||
Path: "/spec/storageClassName",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -52,7 +52,7 @@ func TestResourceModifiers_Validate(t *testing.T) {
|
|||
{
|
||||
Operation: "replace",
|
||||
Path: "/spec/storageClassName",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -87,7 +87,7 @@ func TestJsonPatch_Validate(t *testing.T) {
|
|||
type fields struct {
|
||||
Operation string
|
||||
Path string
|
||||
NewValue string
|
||||
Value string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -99,7 +99,7 @@ func TestJsonPatch_Validate(t *testing.T) {
|
|||
fields: fields{
|
||||
Operation: "replace",
|
||||
Path: "/spec/storageClassName",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
|
@ -108,7 +108,7 @@ func TestJsonPatch_Validate(t *testing.T) {
|
|||
fields: fields{
|
||||
Operation: "",
|
||||
Path: "/spec/storageClassName",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ func TestJsonPatch_Validate(t *testing.T) {
|
|||
fields: fields{
|
||||
Operation: "replace",
|
||||
Path: "",
|
||||
NewValue: "premium",
|
||||
Value: "premium",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
|
@ -127,7 +127,7 @@ func TestJsonPatch_Validate(t *testing.T) {
|
|||
p := &JsonPatch{
|
||||
Operation: tt.fields.Operation,
|
||||
Path: tt.fields.Path,
|
||||
NewValue: tt.fields.NewValue,
|
||||
Value: tt.fields.Value,
|
||||
}
|
||||
if err := p.Validate(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("JsonPatch.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
Loading…
Reference in New Issue