controller-tools: markers to skip fields that does not have json tags for crd generation

controller-tools version: 0.2.2

Currently I am getting this error after upgrading controller-tools from 0.2.2 from 0.1.9 because in our CRD status we included a go struct URL (https://github.com/knative/pkg/blob/43ca049cdbdad4892b0c926e7c6536d064efde72/apis/duck/v1beta1/addressable_types.go#L40) which does not have json tags and this blocks generating the crd manifests.

/usr/local/go/src/net/url/url.go:357:2: encountered struct field "Scheme" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:358:2: encountered struct field "Opaque" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:359:2: encountered struct field "User" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:360:2: encountered struct field "Host" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:361:2: encountered struct field "Path" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:362:2: encountered struct field "RawPath" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:363:2: encountered struct field "ForceQuery" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:364:2: encountered struct field "RawQuery" without JSON tag in type "URL"
/usr/local/go/src/net/url/url.go:365:2: encountered struct field "Fragment" without JSON tag in type "URL"

We want a way to skip fields when generating crd manifests.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 28 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Like yuzisun, I’m trying to add a field of type net.URL to my CRD. In other projects, I’ve wanted to use fields of type time.Time and time.Duration. After doing a bit of digging, I stumbled across metav1.Time and metav1.Duration. These types seem to do exactly what’s wanted here. Does anyone know how? I’ve tried wrapping a type around net.URL with custom serialization, but haven’t had much success

Before the revert, you could do something like

// +kubebuilder:validation:Type=object
type Weird map[string]interface{} // map[string]interface{} is normally invalid, but...

// ... custom marshalling means we *just* use the markers
func (w *Weird) UnmarshalJSON(data []byte) error { ... }
func (w *Weird) MarshalJSON() ([]byte, error) { ... }

Which would get interpreted as:

{type: "Any"} --> apply marker "kubebulider:validation:Type" --> {type: "object"}

So it supported cases where you don’t want an object or you just want a catch-all object, but didn’t support cases where you want a partially-specified object, or a fully specified object, which was an oversight.

For whatever we merge, we should attempt to support both usecases.