diff --git a/pkg/metrics/generator.go b/pkg/metrics/generator.go index d0f151b68..64a1283fd 100644 --- a/pkg/metrics/generator.go +++ b/pkg/metrics/generator.go @@ -34,6 +34,7 @@ import ( "sigs.k8s.io/controller-tools/pkg/metrics/internal/config" "sigs.k8s.io/controller-tools/pkg/metrics/markers" "sigs.k8s.io/controller-tools/pkg/rbac" + "sigs.k8s.io/controller-tools/pkg/version" ) // Generator generates kube-state-metrics custom resource configuration files. @@ -54,6 +55,10 @@ func (g Generator) RegisterMarkers(into *ctrlmarkers.Registry) error { return nil } +const headerText = `# Generated by controller-gen version %s +# Compatible to kube-state-metrics %s +` + // Generate generates artifacts produced by this marker. // It's called after RegisterMarkers has been called. func (g Generator) Generate(ctx *genall.GenerationContext) error { @@ -129,9 +134,11 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { return a < b }) + header := fmt.Sprintf(headerText, version.Version(), config.KubeStateMetricsVersion) + // Write the rendered yaml to the context which will result in stdout. virtualFilePath := "metrics.yaml" - if err := ctx.WriteYAML(virtualFilePath, "", []interface{}{metrics}, genall.WithTransform(addCustomResourceStateKind)); err != nil { + if err := ctx.WriteYAML(virtualFilePath, header, []interface{}{metrics}, genall.WithTransform(addCustomResourceStateKind)); err != nil { return fmt.Errorf("WriteYAML to %s: %w", virtualFilePath, err) } diff --git a/pkg/metrics/internal/config/doc.go b/pkg/metrics/internal/config/doc.go index 5548521dc..6f315ff2c 100644 --- a/pkg/metrics/internal/config/doc.go +++ b/pkg/metrics/internal/config/doc.go @@ -15,7 +15,6 @@ limitations under the License. */ // config contains a copy of the types from k8s.io/kube-state-metrics/pkg/customresourcestate. -// It is currently based on kube-state-metrics v2.13.0. // The following modifications got applied: // For `config.go`: // * Rename the package to `config`. @@ -38,3 +37,7 @@ limitations under the License. // - `MetricGauge.LabelFromkey` // - `MetricInfo.LabelFromkey` package config + +// KubeStateMetricsVersion defines which version of kube-state-metrics these types +// are based on and the output file should be compatible to. +const KubeStateMetricsVersion = "v2.13.0"