@@ -34,6 +34,7 @@ import (
34
34
"sigs.k8s.io/controller-tools/pkg/metrics/internal/config"
35
35
"sigs.k8s.io/controller-tools/pkg/metrics/markers"
36
36
"sigs.k8s.io/controller-tools/pkg/rbac"
37
+ "sigs.k8s.io/controller-tools/pkg/version"
37
38
)
38
39
39
40
// Generator generates kube-state-metrics custom resource configuration files.
@@ -54,6 +55,10 @@ func (g Generator) RegisterMarkers(into *ctrlmarkers.Registry) error {
54
55
return nil
55
56
}
56
57
58
+ const headerText = `# Generated by controller-gen version %s
59
+ # Compatible to kube-state-metrics %s
60
+ `
61
+
57
62
// Generate generates artifacts produced by this marker.
58
63
// It's called after RegisterMarkers has been called.
59
64
func (g Generator ) Generate (ctx * genall.GenerationContext ) error {
@@ -129,9 +134,11 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
129
134
return a < b
130
135
})
131
136
137
+ header := fmt .Sprintf (headerText , version .Version (), config .KubeStateMetricsVersion )
138
+
132
139
// Write the rendered yaml to the context which will result in stdout.
133
140
virtualFilePath := "metrics.yaml"
134
- if err := ctx .WriteYAML (virtualFilePath , "" , []interface {}{metrics }, genall .WithTransform (addCustomResourceStateKind )); err != nil {
141
+ if err := ctx .WriteYAML (virtualFilePath , header , []interface {}{metrics }, genall .WithTransform (addCustomResourceStateKind )); err != nil {
135
142
return fmt .Errorf ("WriteYAML to %s: %w" , virtualFilePath , err )
136
143
}
137
144
0 commit comments