@@ -34,6 +34,7 @@ import (
3434 "sigs.k8s.io/controller-tools/pkg/metrics/internal/config"
3535 "sigs.k8s.io/controller-tools/pkg/metrics/markers"
3636 "sigs.k8s.io/controller-tools/pkg/rbac"
37+ "sigs.k8s.io/controller-tools/pkg/version"
3738)
3839
3940// Generator generates kube-state-metrics custom resource configuration files.
@@ -54,6 +55,10 @@ func (g Generator) RegisterMarkers(into *ctrlmarkers.Registry) error {
5455 return nil
5556}
5657
58+ const headerText = `# Generated by controller-gen version %s
59+ # Compatible to kube-state-metrics %s
60+ `
61+
5762// Generate generates artifacts produced by this marker.
5863// It's called after RegisterMarkers has been called.
5964func (g Generator ) Generate (ctx * genall.GenerationContext ) error {
@@ -129,9 +134,11 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
129134 return a < b
130135 })
131136
137+ header := fmt .Sprintf (headerText , version .Version (), config .KubeStateMetricsVersion )
138+
132139 // Write the rendered yaml to the context which will result in stdout.
133140 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 {
135142 return fmt .Errorf ("WriteYAML to %s: %w" , virtualFilePath , err )
136143 }
137144
0 commit comments