Transform Sets
A TransformSet custom resource (CR) is used to save and reuse the set of Transforms to be used in Restore Actions, Restore Cluster Actions and Policies.
Example TransformSet Operations
Create a TransformSet
The following example illustrates how to create a transform set that contains two transforms, one of which changes the deadline parameter value to 300 seconds and another one scales deployments to 3 replicas.
$ cat > sample-transform-set.yaml <<EOF
apiVersion: config.kio.kasten.io/v1alpha1
kind: TransformSet
metadata:
name: sample-transformset
namespace: kasten-io
spec:
comment: "Transform Set Example"
transforms:
- subject:
resource: deployments
name: progressDeadlineSeconds5m
json:
- op: replace
path: /spec/progressDeadlineSeconds
value: 300
- subject:
resource: deployments
name: scaleDeployment3
json:
- op: replace
path: /spec/replicas
value: 3
EOF
$ kubectl apply -f sample-transform-set.yaml
transformset.config.kio.kasten.io/sample-transformset created
# make sure it initializes and validates properly
$ kubectl get transformsets.config.kio.kasten.io --namespace kasten-io -w
NAME STATUS AGE
sample-transformset Success 30s
Update a TransformSet
To update a TransformSet, edit the spec portion of a TransformSet CR using your preferred method of submitting resource changes with kubectl.
$ kubectl apply -f sample-transform-set-updated.yaml
transformset.config.kio.kasten.io/sample-transformset configured
Once the change is submitted, K10 will re-validate the TransformSet and update .status.validation accordingly.
$ kubectl get transformsets.config.kio.kasten.io --namespace kasten-io -w
NAME STATUS AGE
sample-transformset Failed 25m
sample-transformset Success 30m
Since K10 processes API object changes asynchronously, to avoid confusion with a previous TransformSet status, it is recommended as convention that the status portion of the TransformSet is omitted when submitting changes.
Warning
Using a TransformSet
The following example illustrates how to use a TransformSet in a RestoreAction.
$ cat > restore-action-with-transform-set.yaml <<EOF
apiVersion: actions.kio.kasten.io/v1alpha1
kind: RestoreAction
metadata:
generateName: restore-nginx-
namespace: nginx
spec:
subject:
kind: RestorePoint
name: backup-nginx-sdxg2
namespace: nginx
targetNamespace: nginx
transforms:
- transformSetRef:
name: sample-transformset
namespace: kasten-io
EOF
$ kubectl create -f restore-action-with-transform-set.yaml
restoreaction.actions.kio.kasten.io/restore-nginx-l69nd created
The TransformSet will be applied to the restored application.
Delete a TransformSet
A TransformSet can be deleted using the following command.
# delete transformset "sample-transformset" for K10 installed in "kasten-io"
$ kubectl delete transformsets.config.kio.kasten.io sample-transformset --namespace kasten-io
transformset.config.kio.kasten.io "sample-transformset" deleted
TransformSet API Type
The following is a complete specification of a TransformSet CR.
# Standard Kubernetes API Version declaration. Required.
apiVersion: config.kio.kasten.io/v1alpha1
# Standard Kubernetes Kind declaration. Required.
kind: TransformSet
# Standard Kubernetes metadata. Required.
metadata:
# TransformSet name. May be any valid Kubernetes object name. Required.
# TransformSet name is not mutable once created.
name: sample-transformset
# TransformSet namespace. Required.
namespace: kasten-io
# TransformSet parameters. Required.
spec:
# User friendly comment describing the transform set. Optional.
comment:
# The list of transforms. Required.
transforms:
- subject:
# Group, version, resource and/or name of the resource for transformation
resource: deployments
# ``json`` key below indicates JSON patch document object used to perform
# a JSON patch-like transform
json:
- op: test
# reference for operation. mandatory.
path: '/metadata/labels/release'
- op: copy
# source reference for operation. only valid for the 'move' and 'copy' operations
from: '/metadata/labels/release'
# target reference for operation. mandatory.
path: '/spec/template/metadata/labels/release'
# apply regex to match expression. Valid for 'remove', 'replace', 'move',
# 'copy' and 'test'.
regex: 'prod-v.*'
# value is any json structure. only valid for 'add', 'replace'
# and 'test' operation
value: 'prod'
# Second transform document also applies transform to deployments.
# Transforms on a resource are guaranteed to be applied in the order
# specified in the restore action.
- subject:
# Group, version, resource and/or name of the resource for transformation
resource: deployments
# ``json`` key below indicates JSON patch document object used to perform
# a JSON patch-like transform
json:
- op: test
# reference for operation. mandatory.
path: '/metadata/labels/component'
- op: replace
# reference for operation. mandatory.
path: '/metadata/labels/component'
# use regex to test for presence of element value for replacement
regex: 'nginx'
# value is any json structure. only valid for 'add', 'replace'
# and 'test' operation
value: 'webserver'
# Status of the TransformSet. Users should not set any data here.
status:
# Object generation last observed by the controller
observedGeneration: 2
# Validation status of the TransformSet
# Valid values are:
# # Success – successfully initialized and validated
# # Failed - not properly initialized or validated
# # Indeterminate – indicate an indeterminate validation status for multi-cluster TransformSets.
validation: Success
# An array of any validation or initialization errors encountered.
error: null