File tree Expand file tree Collapse file tree 5 files changed +18
-5
lines changed
pkg/customresourcestate/generate Expand file tree Collapse file tree 5 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 34
34
35
35
Available Commands :
36
36
completion Generate completion script for kube-state-metrics.
37
- generate Generate custom resource metrics configuration from go-code markers.
37
+ generate Generate custom resource metrics configuration from go-code markers (experimental) .
38
38
help Help about any command
39
39
version Print version information.
40
40
Original file line number Diff line number Diff line change 44
44
// GenerateCommand runs the kube-state-metrics custom resource config generator.
45
45
var GenerateCommand = & cobra.Command {
46
46
Use : "generate [flags] /path/to/package [/path/to/package]" ,
47
- Short : "Generate custom resource metrics configuration from go-code markers." ,
47
+ Short : "Generate custom resource metrics configuration from go-code markers (experimental) ." ,
48
48
DisableFlagsInUseLine : true ,
49
49
Args : cobra .MinimumNArgs (1 ),
50
50
RunE : func (cmd * cobra.Command , args []string ) error {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import (
22
22
"path"
23
23
"testing"
24
24
25
+ "github.com/google/go-cmp/cmp"
25
26
"sigs.k8s.io/controller-tools/pkg/genall"
26
27
"sigs.k8s.io/controller-tools/pkg/loader"
27
28
"sigs.k8s.io/controller-tools/pkg/markers"
@@ -73,10 +74,15 @@ func Test_Generate(t *testing.T) {
73
74
t .Error (err )
74
75
}
75
76
76
- if string (expectedFile ) != output {
77
+ diff := cmp .Diff (string (expectedFile ), output )
78
+ if diff != "" {
77
79
t .Log ("output:" )
78
80
t .Log (output )
79
- t .Error ("Expected output to match file testdata/foo-config.yaml" )
81
+ t .Log ("diff:" )
82
+ t .Log (diff )
83
+ t .Log ("Expected output to match file `testdata/foo-config.yaml` but it does not." )
84
+ t .Log ("If the change is intended, use `go generate ./pkg/customresourcestate/generate/generator/testdata` to regenerate the `testdata/foo-config.yaml` file." )
85
+ t .Error ("Detected a diff between the output of the integration test and the file `testdata/foo-config.yaml`." )
80
86
}
81
87
}
82
88
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ // Changes to this file may require to regenerate the `foo-config.yaml`. Otherwise the
18
+ // tests in ../generate_integration_test.go may fail.
19
+ // The below marker can be used to regenerate the `foo-config.yaml` file by running
20
+ // the following command:
21
+ // $ go generate ./pkg/customresourcestate/generate/generator/testdata
17
22
//go:generate sh -c "go run ../../../../../ generate ./... > foo-config.yaml"
18
23
19
24
// +groupName=bar.example.com
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ func (gvkMarker) Help() *markers.DefinitionHelp {
55
55
}
56
56
57
57
func (n gvkMarker ) ApplyToResource (resource * customresourcestate.Resource ) error {
58
- resource .MetricNamePrefix = & n .NamePrefix
58
+ if n .NamePrefix != "" {
59
+ resource .MetricNamePrefix = & n .NamePrefix
60
+ }
59
61
return nil
60
62
}
You can’t perform that action at this time.
0 commit comments