@@ -42,6 +42,9 @@ var CRDMarkers = []*definitionWithHelp{
42
42
43
43
must (markers .MakeDefinition ("kubebuilder:storageversion" , markers .DescribesType , StorageVersion {})).
44
44
WithHelp (StorageVersion {}.Help ()),
45
+
46
+ must (markers .MakeDefinition ("kubebuilder:skipversion" , markers .DescribesType , SkipVersion {})).
47
+ WithHelp (SkipVersion {}.Help ()),
45
48
}
46
49
47
50
// TODO: categories and singular used to be annotations types
@@ -165,6 +168,34 @@ func (s StorageVersion) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, ver
165
168
166
169
// +controllertools:marker:generateHelp:category=CRD
167
170
171
+ // SkipVersion removes the particular version of the CRD from the CRDs spec.
172
+ //
173
+ // This is useful if you need to skip generating and listing version entries
174
+ // for 'internal' resource versions, which typically exist if using the
175
+ // Kubernetes upstream conversion-gen tool.
176
+ type SkipVersion struct {}
177
+
178
+ func (s SkipVersion ) ApplyToCRD (crd * apiext.CustomResourceDefinitionSpec , version string ) error {
179
+ if version == "" {
180
+ // single-version, this is an invalid state
181
+ return fmt .Errorf ("cannot skip a version if there is only a single version" )
182
+ }
183
+ var versions []apiext.CustomResourceDefinitionVersion
184
+ // multi-version
185
+ for i := range crd .Versions {
186
+ ver := crd .Versions [i ]
187
+ if ver .Name == version {
188
+ // skip the skipped version
189
+ continue
190
+ }
191
+ versions = append (versions , ver )
192
+ }
193
+ crd .Versions = versions
194
+ return nil
195
+ }
196
+
197
+ // +controllertools:marker:generateHelp:category=CRD
198
+
168
199
// PrintColumn adds a column to "kubectl get" output for this CRD.
169
200
type PrintColumn struct {
170
201
// Name specifies the name of the column.
0 commit comments