Skip to content

Commit 550fa2f

Browse files
committed
metrics: add version compatibility header
1 parent 1389ce3 commit 550fa2f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/metrics/generator.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
5964
func (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

pkg/metrics/internal/config/doc.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
*/
1616

1717
// config contains a copy of the types from k8s.io/kube-state-metrics/pkg/customresourcestate.
18-
// It is currently based on kube-state-metrics v2.13.0.
1918
// The following modifications got applied:
2019
// For `config.go`:
2120
// * Rename the package to `config`.
@@ -38,3 +37,7 @@ limitations under the License.
3837
// - `MetricGauge.LabelFromkey`
3938
// - `MetricInfo.LabelFromkey`
4039
package config
40+
41+
// KubeStateMetricsVersion defines which version of kube-state-metrics these types
42+
// are based on and the output file should be compatible to.
43+
const KubeStateMetricsVersion = "v2.13.0"

0 commit comments

Comments
 (0)