mirror of
https://github.com/vmware-tanzu/velero.git
synced 2025-12-23 06:15:21 +00:00
use old namespace in resource modifier (#6724)
* use old namespace in resource modifier Signed-off-by: lou <alex1988@outlook.com> * add changelog Signed-off-by: lou <alex1988@outlook.com> * update docs Signed-off-by: lou <alex1988@outlook.com> * updated after review Signed-off-by: lou <alex1988@outlook.com> --------- Signed-off-by: lou <alex1988@outlook.com>
This commit is contained in:
1
changelogs/unreleased/6724-27149chen
Normal file
1
changelogs/unreleased/6724-27149chen
Normal file
@@ -0,0 +1 @@
|
||||
Use old(origin) namespace in resource modifier conditions in case namespace may change during restore
|
||||
@@ -96,6 +96,7 @@ resourceModifierRules:
|
||||
path: "/metadata/labels/test"
|
||||
```
|
||||
- The above configmap will apply the JSON Patch to all the PVCs in the namespaces bar and foo with name starting with mysql. The JSON Patch will replace the storageClassName with "premium" and remove the label "test" from the PVCs.
|
||||
- Note that the Namespace here is the original namespace of the backed up resource, not the new namespace where the resource is going to be restored.
|
||||
- The user can specify multiple JSON Patches for a particular resource. The patches will be applied in the order specified in the configmap. A subsequent patch is applied in order and if multiple patches are specified for the same path, the last patch will override the previous patches.
|
||||
- The user can specify multiple resourceModifierRules in the configmap. The rules will be applied in the order specified in the configmap.
|
||||
|
||||
|
||||
@@ -1352,6 +1352,14 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.resourceModifiers != nil {
|
||||
if errList := ctx.resourceModifiers.ApplyResourceModifierRules(obj, groupResource.String(), ctx.log); errList != nil {
|
||||
for _, err := range errList {
|
||||
errs.Add(namespace, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Necessary because we may have remapped the namespace if the namespace is
|
||||
// blank, don't create the key.
|
||||
originalNamespace := obj.GetNamespace()
|
||||
@@ -1364,14 +1372,6 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
||||
// and which backup they came from.
|
||||
addRestoreLabels(obj, ctx.restore.Name, ctx.restore.Spec.BackupName)
|
||||
|
||||
if ctx.resourceModifiers != nil {
|
||||
if errList := ctx.resourceModifiers.ApplyResourceModifierRules(obj, groupResource.String(), ctx.log); errList != nil {
|
||||
for _, err := range errList {
|
||||
errs.Add(namespace, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The object apiVersion might get modified by a RestorePlugin so we need to
|
||||
// get a new client to reflect updated resource path.
|
||||
newGR := schema.GroupResource{Group: obj.GroupVersionKind().Group, Resource: groupResource.Resource}
|
||||
|
||||
@@ -46,6 +46,7 @@ resourceModifierRules:
|
||||
```
|
||||
|
||||
- The above configmap will apply the JSON Patch to all the PVCs in the namespaces bar and foo with name starting with mysql and match label `foo: bar`. The JSON Patch will replace the storageClassName with "premium" and remove the label "test" from the PVCs.
|
||||
- Note that the Namespace here is the original namespace of the backed up resource, not the new namespace where the resource is going to be restored.
|
||||
- You can specify multiple JSON Patches for a particular resource. The patches will be applied in the order specified in the configmap. A subsequent patch is applied in order and if multiple patches are specified for the same path, the last patch will override the previous patches.
|
||||
- You can specify multiple resourceModifierRules in the configmap. The rules will be applied in the order specified in the configmap.
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ resourceModifierRules:
|
||||
```
|
||||
|
||||
- The above configmap will apply the JSON Patch to all the PVCs in the namespaces bar and foo with name starting with mysql and match label `foo: bar`. The JSON Patch will replace the storageClassName with "premium" and remove the label "test" from the PVCs.
|
||||
- Note that the Namespace here is the original namespace of the backed up resource, not the new namespace where the resource is going to be restored.
|
||||
- You can specify multiple JSON Patches for a particular resource. The patches will be applied in the order specified in the configmap. A subsequent patch is applied in order and if multiple patches are specified for the same path, the last patch will override the previous patches.
|
||||
- You can specify multiple resourceModifierRules in the configmap. The rules will be applied in the order specified in the configmap.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user