Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(schema): Add marker to skip fields #955

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/crd/markers/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ var FieldOnlyMarkers = []*definitionWithHelp{
must(markers.MakeDefinition("optional", markers.DescribesField, struct{}{})).
WithHelp(markers.SimpleHelp("CRD validation", "specifies that this field is optional.")),

must(markers.MakeDefinition("kubebuilder:skip", markers.DescribesField, struct{}{})).
WithHelp(markers.SimpleHelp("CRD generation", "specifies that this field should be skipped for schema generation.")),

must(markers.MakeDefinition("nullable", markers.DescribesField, Nullable{})).
WithHelp(Nullable{}.Help()),

Expand Down
5 changes: 5 additions & 0 deletions pkg/crd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ func structToSchema(ctx *schemaContext, structType *ast.StructType) *apiext.JSON
continue
}

if field.Markers.Get("kubebuilder:skip") != nil {
// Explicitly ignore this field for schema generation
continue
}

jsonTag, hasTag := field.Tag.Lookup("json")
if !hasTag {
// if the field doesn't have a JSON tag, it doesn't belong in output (and shouldn't exist in a serialized type)
Expand Down
4 changes: 4 additions & 0 deletions pkg/crd/testdata/gen/foo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type FooSpec struct {
// +kubebuilder:default=fooDefaultString
// +kubebuilder:example=fooExampleString
DefaultedString string `json:"defaultedString"`

// This field is explicitly ignored for schema generation.
// +kubebuilder:skip
Skipped string `json:"skipped"`
}
type FooStatus struct{}

Expand Down