Skip to content

Commit 436f87f

Browse files
committed
review fixes
1 parent f0c5ca9 commit 436f87f

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

docs/cli-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Usage:
3434

3535
Available Commands:
3636
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).
3838
help Help about any command
3939
version Print version information.
4040

pkg/customresourcestate/generate/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var (
4444
// GenerateCommand runs the kube-state-metrics custom resource config generator.
4545
var GenerateCommand = &cobra.Command{
4646
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).",
4848
DisableFlagsInUseLine: true,
4949
Args: cobra.MinimumNArgs(1),
5050
RunE: func(cmd *cobra.Command, args []string) error {

pkg/customresourcestate/generate/generator/generate_integration_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"path"
2323
"testing"
2424

25+
"github.com/google/go-cmp/cmp"
2526
"sigs.k8s.io/controller-tools/pkg/genall"
2627
"sigs.k8s.io/controller-tools/pkg/loader"
2728
"sigs.k8s.io/controller-tools/pkg/markers"
@@ -73,10 +74,15 @@ func Test_Generate(t *testing.T) {
7374
t.Error(err)
7475
}
7576

76-
if string(expectedFile) != output {
77+
diff := cmp.Diff(string(expectedFile), output)
78+
if diff != "" {
7779
t.Log("output:")
7880
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`.")
8086
}
8187
}
8288

pkg/customresourcestate/generate/generator/testdata/foo_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

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
1722
//go:generate sh -c "go run ../../../../../ generate ./... > foo-config.yaml"
1823

1924
// +groupName=bar.example.com

pkg/customresourcestate/generate/markers/gvk.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func (gvkMarker) Help() *markers.DefinitionHelp {
5555
}
5656

5757
func (n gvkMarker) ApplyToResource(resource *customresourcestate.Resource) error {
58-
resource.MetricNamePrefix = &n.NamePrefix
58+
if n.NamePrefix != "" {
59+
resource.MetricNamePrefix = &n.NamePrefix
60+
}
5961
return nil
6062
}

0 commit comments

Comments
 (0)