import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/kubernetes/pkg/conversion" ) type MyResource struct { runtime.TypeMeta `json:",inline"` metadata metav1.ObjectMeta `json:"metadata,omitempty"` spec MyResourceSpec `json:"spec,omitempty"` } type MyResourceSpec struct { Foo string `json:"foo"` Bar string `json:"bar"` Baz string `json:"baz"` Quux string `json:"quux,omitempty"` StartDelay int32 `json:"startDelay,omitempty"` } func (spec *MyResourceSpec) Default() { if spec.Foo == "" { spec.Foo = "default-foo" } if spec.Bar == "" { spec.Bar = "default-bar" } if spec.Baz == "" { spec.Baz = "default-baz" } } var _ conversion.Defaulting = &MyResourceSpec{}In this example, we define a custom Kubernetes API object called MyResource, which has a spec field of type MyResourceSpec. We then define a defaulting function on MyResourceSpec using the DefaultingInterface. The default function sets default values for the Foo, Bar, and Baz fields if they are empty. This example uses the k8s.io/kubernetes package library.