package main import ( "fmt" "github.com/openshift/origin/pkg/cmd/util/clientcmd" "k8s.io/apimachinery/pkg/apis/meta/v1" ) func main() { // Create a new object. obj := &v1.Pod{ ObjectMeta: v1.ObjectMeta{ Name: "my-pod", }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name: "my-container", Image: "my-image", }, }, }, } // Print the object. fmt.Println(clientcmd.Factory.PrintObject(obj)) }
apiVersion: v1 kind: Pod metadata: creationTimestamp: null name: my-pod spec: containers: - image: my-image name: my-container restartPolicy: Always status: {}
package main import ( "fmt" "github.com/openshift/origin/pkg/cmd/util/clientcmd" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "time" ) func main() { // Create a new unstructured object. obj := &unstructured.Unstructured{} obj.SetName("my-object") obj.SetCreationTimestamp(v1.Time{Time: time.Now()}) obj.SetAnnotations(map[string]string{ "my-annotation": "true", }) // Print the object. fmt.Println(clientcmd.Factory.PrintObject(obj)) }
apiVersion:kind: metadata: annotations: my-annotation: "true" creationTimestamp: "2021-08-09T16:25:51Z" name: my-object