Resource Modifiers
Introduction
Resource modifiers allow you to specify if and how specific Kubernetes resources should be automatically modified by restore, migration, and replication jobs. This advanced feature can be used to provide fine-grained control over the resulting configuration.
Note
Resource modifiers are available only with CloudCasa premium (paid) service plans.
Overview
Resource modifiers enable you to:
Modify resource specifications during restore (e.g. change image tags, resource limits, labels)
Transform resources to match different environments (e.g. development to production)
Apply security policies or compliance requirements during restore
Customize networking configurations for different target clusters
The feature uses YAML configuration files that define the modifications to be applied to specific resource types during the restore process.
Using Resource Modifiers
To use resource modifiers during a cluster restore, migration, or replication job:
Enable the Feature: In the cluster restore, migration, or replication wizard, navigate to the Restore transforms step.
Toggle the Option On by enabling the Enable Resource Modifiers switch.
Upload the Configuration: Upload a YAML file containing your restore modifier configuration.
The YAML file format is compatible with the Velero Resource Modifier configuration as defined in the Velero documentation.
Configuration Format
Here is the basic structure:
version: v1
resourceModifierRules:
- conditions:
groupResource: deployments.apps
resourceNameRegex: "^test-.*$"
namespaces:
- bar
- foo
patches:
- operation: replace
path: "/spec/replicas"
value: "1"
- operation: add
path: "/metadata/labels/environment"
value: "development"
Key Configuration Elements
Conditions: Define which resources the modifier applies to:
groupResource: The API group and resource type (e.g.,deployments.apps,services). Note: Ensure that you always use the full group resource name and not just the abbreviated name. For example, you need to usevirtualmachines.kubevirt.iorather thanvirtualmachines. Abbreviated names only work for core resources such as pods and services.resourceNameRegex: Regular expression to match resource namesnamespaces: List of namespaces where the modifier applies. In the case where resources are being restored to an alternate namespace, you need to use the backup-time namespace in this field.labelSelector: Label selector to match specific resources
Patches: Define the modifications to apply:
operation: The type of operation (add,remove,replace,copy,move,test)path: JSON path to the field to modifyvalue: The new value to apply (foraddandreplaceoperations)
Limitations
Resource modifiers are only available with paid CloudCasa service plans.
The YAML file format must be compatible with the Velero resource modifier specifications.
Some complex transformations may require multiple patches.
Modifications are applied during restore and cannot be automatically undone.
Samples
This section shows some examples of resource modifiers.
Changing machine type of a VM that is being restored
To change the machine type of a VM that is being restored, use the following resource modifier YAML. Here, “test-vm” is the name of the VM that is being restored and “app-ns” is the namespace of the VM (at the time of the backup):
version: v1
resourceModifierRules:
- conditions:
groupResource: virtualmachines.kubevirt.io
resourceNameRegex: "^test-vm$"
namespaces:
- app-ns
patches:
- operation: replace
path: "/spec/template/spec/domain/machine/type"
value: "q35"
Resizing a PVC
The following resource modifier changes the size of the PVC “test-pvc” in the namespace “test-ns” to “125Gi” on restore:
version: v1
resourceModifierRules:
- conditions:
groupResource: persistentvolumeclaims
resourceNameRegex: "^test-pvc$"
namespaces:
- test-ns
patches:
- operation: replace
path: "/spec/resources/requests/storage"
value: "125Gi"
Removing an init container
This resource modifier shows how to remove “restore-wait” init container from the pod “test-pod” in the namespace “test-ns” (it is assumed to be the first init container for this example):
version: v1
resourceModifierRules:
- conditions:
groupResource: pods
resourceNameRegex: "^test-pod*"
namespaces:
- test-ns
patches:
- operation: test
path: "/spec/initContainers/0/name"
value: "restore-wait"
- operation: remove
path: "/spec/initContainers/0"
Changing access mode of a PVC
This resource modifier changes access mode of the pvc “test-pvc” in the namespace “test-ns” to “ReadWriteOnce”:
version: v1
resourceModifierRules:
- conditions:
groupResource: persistentvolumeclaims
resourceNameRegex: "^test-pvc$"
namespaces:
- test-ns
patches:
- operation: replace
path: "/spec/accessModes/0"
value: "ReadWriteOnce"