Skip to content

Commit

Permalink
Merge pull request #308 from munnerz/skipversion-marker
Browse files Browse the repository at this point in the history
✨ Add skipversion marker to selectively exclude CRD versions
  • Loading branch information
k8s-ci-robot authored Aug 19, 2019
2 parents ba0eb80 + 5fc42b1 commit a653df4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/crd/markers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ var CRDMarkers = []*definitionWithHelp{

must(markers.MakeDefinition("kubebuilder:storageversion", markers.DescribesType, StorageVersion{})).
WithHelp(StorageVersion{}.Help()),

must(markers.MakeDefinition("kubebuilder:skipversion", markers.DescribesType, SkipVersion{})).
WithHelp(SkipVersion{}.Help()),
}

// TODO: categories and singular used to be annotations types
Expand Down Expand Up @@ -165,6 +168,34 @@ func (s StorageVersion) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, ver

// +controllertools:marker:generateHelp:category=CRD

// SkipVersion removes the particular version of the CRD from the CRDs spec.
//
// This is useful if you need to skip generating and listing version entries
// for 'internal' resource versions, which typically exist if using the
// Kubernetes upstream conversion-gen tool.
type SkipVersion struct{}

func (s SkipVersion) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, version string) error {
if version == "" {
// single-version, this is an invalid state
return fmt.Errorf("cannot skip a version if there is only a single version")
}
var versions []apiext.CustomResourceDefinitionVersion
// multi-version
for i := range crd.Versions {
ver := crd.Versions[i]
if ver.Name == version {
// skip the skipped version
continue
}
versions = append(versions, ver)
}
crd.Versions = versions
return nil
}

// +controllertools:marker:generateHelp:category=CRD

// PrintColumn adds a column to "kubectl get" output for this CRD.
type PrintColumn struct {
// Name specifies the name of the column.
Expand Down
11 changes: 11 additions & 0 deletions pkg/crd/markers/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a653df4

Please sign in to comment.