Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Oct 12, 2023
1 parent 0b045d6 commit 415c7d5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/cli-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Usage:

Available Commands:
completion Generate completion script for kube-state-metrics.
generate Generate custom resource metrics configuration from go-code markers.
generate Generate custom resource metrics configuration from go-code markers (experimental).
help Help about any command
version Print version information.

Expand Down
2 changes: 1 addition & 1 deletion pkg/customresourcestate/generate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
// GenerateCommand runs the kube-state-metrics custom resource config generator.
var GenerateCommand = &cobra.Command{
Use: "generate [flags] /path/to/package [/path/to/package]",
Short: "Generate custom resource metrics configuration from go-code markers.",
Short: "Generate custom resource metrics configuration from go-code markers (experimental).",
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path"
"testing"

"github.com/google/go-cmp/cmp"
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/loader"
"sigs.k8s.io/controller-tools/pkg/markers"
Expand Down Expand Up @@ -73,10 +74,15 @@ func Test_Generate(t *testing.T) {
t.Error(err)
}

if string(expectedFile) != output {
diff := cmp.Diff(string(expectedFile), output)
if diff != "" {
t.Log("output:")
t.Log(output)
t.Error("Expected output to match file testdata/foo-config.yaml")
t.Log("diff:")
t.Log(diff)
t.Log("Expected output to match file `testdata/foo-config.yaml` but it does not.")
t.Log("If the change is intended, use `go generate ./pkg/customresourcestate/generate/generator/testdata` to regenerate the `testdata/foo-config.yaml` file.")
t.Error("Detected a diff between the output of the integration test and the file `testdata/foo-config.yaml`.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Changes to this file may require to regenerate the `foo-config.yaml`. Otherwise the
// tests in ../generate_integration_test.go may fail.
// The below marker can be used to regenerate the `foo-config.yaml` file by running
// the following command:
// $ go generate ./pkg/customresourcestate/generate/generator/testdata
//go:generate sh -c "go run ../../../../../ generate ./... > foo-config.yaml"

// +groupName=bar.example.com
Expand Down
4 changes: 3 additions & 1 deletion pkg/customresourcestate/generate/markers/gvk.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (gvkMarker) Help() *markers.DefinitionHelp {
}

func (n gvkMarker) ApplyToResource(resource *customresourcestate.Resource) error {
resource.MetricNamePrefix = &n.NamePrefix
if n.NamePrefix != "" {
resource.MetricNamePrefix = &n.NamePrefix
}
return nil
}

0 comments on commit 415c7d5

Please sign in to comment.