kubernetes-sigs / cloud-provider-equinix-metal

Kubernetes Cloud Provider for Equinix Metal (formerly Packet Cloud Controller Manager)
https://deploy.equinix.com/labs/cloud-provider-equinix-metal
Apache License 2.0
73 stars 26 forks source link

convert options to CLI args #472

Open displague opened 8 months ago

displague commented 8 months ago

The README.md today reflects only four options that can be defined via CLI. The pattern of METAL_ env vars and JSON config files (cloud-sa.json) is consistent with how Metal CLI is managed today: https://github.com/equinix/metal-cli/blob/main/internal/cli/root.go#L116-L171. By making the options (defined in README.md) CLI args, users will have a full set of methods to define options: args, env, config. This will improve the user experience through better discoverability and documentation of options.

As in Metal CLI, Viper could be used to replace the environment fetching code in CPEM: https://github.com/kubernetes-sigs/cloud-provider-equinix-metal/blob/45dde1a565767e17e4a515a092a46c5ee4f3e744/metal/config.go#L96-L199

Once these arguments are defined via the CLI, they can included in the --help output and included in generated markdown generation (replacing the hand-maintained README.md table):

diff --git a/main.go b/main.go
index bc35f40..dcc4908 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,8 @@ import (
        cloudcontrollerconfig "k8s.io/cloud-provider/app/config"
        "k8s.io/cloud-provider/options"
        "k8s.io/component-base/cli"
+       "github.com/spf13/cobra/doc"
+       "github.com/spf13/cobra"
        cliflag "k8s.io/component-base/cli/flag"
        _ "k8s.io/component-base/logs/json/register"
        _ "k8s.io/component-base/metrics/prometheus/clientgo" // for client metric registration
@@ -34,6 +36,25 @@ func main() {

        fss := cliflag.NamedFlagSets{}
        command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers, fss, wait.NeverStop)
+       command.AddCommand(&cobra.Command{
+               Use:   `docs <destination>`,
+               Short: "Generate command markdown documentation.",
+               Long:  "Generates command markdown documentation in the specified directory. Each command gets a markdown file.",
+               Example: `  # Generate documentation in the ./docs directory:
+       metal docs ./docs`,
+
+               DisableFlagsInUseLine: true,
+               Args:                  cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
+               PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
+                       cmd.SilenceUsage = true
+                       return nil
+               },
+               RunE: func(cmd *cobra.Command, args []string) error {
+                       cmd.SilenceUsage = true
+                       dest := args[0]
+                       return doc.GenMarkdownTree(cmd.Parent(), dest)
+               },
+       })
        code := cli.Run(command)
        os.Exit(code)
 }

The generated documentation could then be included in the docs/ directory (docs/cmd/?).

k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 4 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 3 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 3 months ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes-sigs/cloud-provider-equinix-metal/issues/472#issuecomment-2028529541): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
cprivitere commented 1 month ago

/reopen

k8s-ci-robot commented 1 month ago

@cprivitere: Reopened this issue.

In response to [this](https://github.com/kubernetes-sigs/cloud-provider-equinix-metal/issues/472#issuecomment-2110610522): >/reopen Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
cprivitere commented 1 month ago

/remove-lifecycle rotten

cprivitere commented 1 month ago

/triage accepted