How can I specify an optional field in an external struct using Kubernetes controller-gen?

12/22/2019

I am implementing a Kubernetes controller and am creating an API using a struct that looks like:

import (
    corev1 "k8s.io/api/core/v1"
)

type MySpec struct {
    corev1.PodSpec `json:",inline"`
}

However, since the Containers field in PodSpec is required, when generating a corresponding CRD using controller-gen the containers field is being marked as required - however I want it to be optional in my CRD.

Is there any way to override this without copying out the whole structure or patching the output of controller-gen?

For reference the whole project is here.

-- dippynark
kubebuilder
kubernetes

0 Answers