import ( "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/conversion" ) func clonePod(pod *v1.Pod) (*v1.Pod, error) { cloner := conversion.NewCloner(nil) return cloner.DeepCopy(pod) }
import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/kubernetes/pkg/conversion" ) func cloneUnstructured(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { cloner := conversion.NewCloner(nil) return cloner.DeepCopy(obj) }In this example, we use the Cloner to create a deep copy of an unstructured object. Unstructured objects are a variation of Kubernetes objects that can hold arbitrary data. The Cloner's DeepCopy method works for unstructured objects as well as for typed Kubernetes objects like Pods, Deployments, and Services.