File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
"sigs.k8s.io/controller-tools/pkg/genall"
28
28
"sigs.k8s.io/controller-tools/pkg/loader"
29
29
"sigs.k8s.io/controller-tools/pkg/markers"
30
+ "sigs.k8s.io/controller-tools/pkg/version"
30
31
)
31
32
32
33
// +controllertools:marker:generateHelp
@@ -81,6 +82,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
81
82
if g .TrivialVersions {
82
83
toTrivialVersions (& crd )
83
84
}
85
+ addAttribution (& crd )
84
86
fileName := fmt .Sprintf ("%s_%s.yaml" , crd .Spec .Group , crd .Spec .Names .Plural )
85
87
if err := ctx .WriteYAML (fileName , crd ); err != nil {
86
88
return err
@@ -116,6 +118,15 @@ func toTrivialVersions(crd *apiext.CustomResourceDefinition) {
116
118
crd .Spec .AdditionalPrinterColumns = canonicalColumns
117
119
}
118
120
121
+ // addAttribution adds attribution info to indicate controller-gen tool was used
122
+ // to generate this CRD definition along with the version info.
123
+ func addAttribution (crd * apiext.CustomResourceDefinition ) {
124
+ if crd .ObjectMeta .Annotations == nil {
125
+ crd .ObjectMeta .Annotations = map [string ]string {}
126
+ }
127
+ crd .ObjectMeta .Annotations ["controller-gen.kubebuilder.io/version" ] = version .Version ()
128
+ }
129
+
119
130
// FindMetav1 locates the actual package representing metav1 amongst
120
131
// the imports of the roots.
121
132
func FindMetav1 (roots []* loader.Package ) * loader.Package {
Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2019 The Kubernetes Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
1
16
package version
2
17
3
18
import (
4
19
"fmt"
5
20
"runtime/debug"
6
21
)
7
22
8
- // version returns the version of the main module
9
- func version () string {
23
+ // Version returns the version of the main module
24
+ func Version () string {
10
25
info , ok := debug .ReadBuildInfo ()
11
26
if ! ok {
12
27
// binary has not been built with module support
@@ -30,5 +45,5 @@ func version() string {
30
45
//
31
46
// - "Version: (unknown)" when not using go modules.
32
47
func Print () {
33
- fmt .Printf ("Version: %s\n " , version ())
48
+ fmt .Printf ("Version: %s\n " , Version ())
34
49
}
You can’t perform that action at this time.
0 commit comments