Bug 1866222

Summary: Should output all options when runing `operator-sdk init --help`
Product: OpenShift Container Platform Reporter: Jian Zhang <jiazha>
Component: Operator SDKAssignee: Jesus M. Rodriguez <jesusr>
Status: CLOSED ERRATA QA Contact: Fan Jia <jfan>
Severity: low Docs Contact:
Priority: low    
Version: 4.6CC: aos-bugs, chuo, estroczy, jesusr, jfan, jiazha
Target Milestone: ---Keywords: Reopened
Target Release: 4.8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: Default plugin was not being invoked when --help was passed on the CLI Consequence: By not invoking the default plugin, we would print out the bare minimum help message. Fix: Invoke the help function on the default plugin. Result: The user now sees a more meaningful help message when invoking the `operator-sdk init --help` command.
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-07-27 22:32:47 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jian Zhang 2020-08-05 06:16:55 UTC
Description of problem:
Should output all options when runing `operator-sdk init --help`.


Version-Release number of selected component (if applicable):
[root@preserve-olm-env operator-sdk]# operator-sdk version
operator-sdk version: "v1.0.0-alpha.2-4-gce96b75", commit: "ce96b751a9e377e4e138e76356bf2409ac1fc457", kubernetes version: "v1.18.2", go version: "go1.14 linux/amd64", GOOS: "linux", GOARCH: "amd64"

How reproducible:
always

Steps to Reproduce:
1. Run the `operator-sdk init --help` command.


Actual results:
Some options are not list. Such as, `--domian`, `--project-name`, `--license`, etc.

[root@preserve-olm-env operator-sdk]# operator-sdk init --help
Initialize a new project.

For further help about a specific project version, set --project-version.

Usage:
  operator-sdk init [flags]

Examples:
  # Help for initializing a project with version "2"
  operator-sdk init --project-version="2" -h

  # Help for initializing a project with version "3-alpha"
  operator-sdk init --project-version="3-alpha" -h

Flags:
  -h, --help                     help for init
      --plugins strings          Name and optionally version of the plugin to initialize the project with. Available plugins: ("ansible.sdk.operatorframework.io/v1", "go.kubebuilder.io/v2", "helm.sdk.operatorframework.io/v1")
      --project-version string   project version, possible values: ("2", "3-alpha") (default "3-alpha")

Global Flags:
      --verbose   Enable verbose logging



Expected results:
Should also output the `--domian`, `--project-name`, `--license`, etc options as the example shows. As follows:

Examples:
  # Scaffold a project using the apache2 license with "The Kubernetes authors" as owners
  operator-sdk init --project-version=2 --domain example.org --license apache2 --owner "The Kubernetes authors"


Flags:
      --domain string            domain for groups (default "my.domain")
      --fetch-deps               ensure dependencies are downloaded (default true)
  -h, --help                     help for init
      --license string           license to use to boilerplate, may be one of 'apache2', 'none' (default "apache2")
      --owner string             owner to add to the copyright
      --plugins strings          Name and optionally version of the plugin to initialize the project with. Available plugins: ("ansible.sdk.operatorframework.io/v1", "go.kubebuilder.io/v2", "helm.sdk.operatorframework.io/v1")
      --project-name string      name of this project
      --project-version string   project version, possible values: ("2", "3-alpha") (default "3-alpha")
      --repo string              name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.
      --skip-go-version-check    if specified, skip checking the Go version

Global Flags:
      --verbose   Enable verbose logging

Additional info:

Comment 1 Jesus M. Rodriguez 2020-08-05 14:15:27 UTC
This is intentional. init is now a dynamic CLI and will show different help depending on the --project-version and --plugins flags.

Comment 2 Jian Zhang 2020-08-06 00:59:21 UTC
Thanks for your formation! But, I still have some conerns.
As a end user, I want to check how to create a new operator project, so I run `operator-sdk init --help`.
But, the help info cannot list the full option so that help the end user to do that. I think we should list all the help info, at least the enough info to create a new project. Reopen it.

Comment 3 Joe Lanford 2020-08-06 14:54:21 UTC
The help text when running `operator-sdk init --help` says:

"For further help about a specific project version, set --project-version."

So running again with that flag gives the output specific to that project version:

    $ operator-sdk init --project-version=3-alpha -h
    Initialize a new project including vendor/ directory and Go package directories.

    Writes the following files:
    - a boilerplate license file
    - a PROJECT file with the domain and repo
    - a Makefile to build the project
    - a go.mod with project dependencies
    - a Kustomization.yaml for customizating manifests
    - a Patch file for customizing image for manager manifests
    - a Patch file for enabling prometheus metrics
    - a cmd/manager/main.go to run
    
    project will prompt the user to run 'dep ensure' after writing the project files.

    Usage:
      operator-sdk init [flags]
    
    Examples:
      # Scaffold a project using the apache2 license with "The Kubernetes authors" as owners
      operator-sdk init --project-version=2 --domain example.org --license apache2 --owner "The Kubernetes authors"
    
    
    Flags:
          --domain string            domain for groups (default "my.domain")
          --fetch-deps               ensure dependencies are downloaded (default true)
      -h, --help                     help for init
          --license string           license to use to boilerplate, may be one of 'apache2', 'none' (default "apache2")
          --owner string             owner to add to the copyright
          --plugins strings          Name and optionally version of the plugin to initialize the project with. Available plugins: ("ansible.sdk.operatorframework.io/v1", "go.kubebuilder.io/v2", "helm.sdk.operatorframework.io/v1")
          --project-name string      name of this project
          --project-version string   project version, possible values: ("2", "3-alpha") (default "3-alpha")
          --repo string              name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.
          --skip-go-version-check    if specified, skip checking the Go version
    
    Global Flags:
          --verbose   Enable verbose logging


The default --plugins value is `go.kubebuilder.io/v2`, hence the output for the Go plugin.

Further setting of the --plugins flag give help for non-default plugins:

    $ operator-sdk init --project-version=3-alpha --plugins=helm -h
    Initialize a new Helm-based operator project.
    
    Writes the following files:
    - a helm-charts directory with the chart(s) to build releases from
    - a watches.yaml file that defines the mapping between your API and a Helm chart
    - a PROJECT file with the domain and project layout configuration
    - a Makefile to build the project
    - a Kustomization.yaml for customizating manifests
    - a Patch file for customizing image for manager manifests
    - a Patch file for enabling prometheus metrics
    
    Usage:
      operator-sdk init [flags]
    
    Examples:
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --group=apps \
          --version=v1alpha1 \
          --kind=AppService
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --project-name=myapp
          --domain=example.com \
          --group=apps \
          --version=v1alpha1 \
          --kind=AppService
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --group=apps \
          --version=v1alpha1 \
          --kind=AppService \
          --helm-chart=myrepo/app
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --helm-chart=myrepo/app
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --helm-chart=myrepo/app \
          --helm-chart-version=1.2.3
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --helm-chart=app \
          --helm-chart-repo=https://charts.mycompany.com/
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --helm-chart=app \
          --helm-chart-repo=https://charts.mycompany.com/ \
          --helm-chart-version=1.2.3
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --helm-chart=/path/to/local/chart-directories/app/
    
      $ operator-sdk init --plugins=helm.sdk.operatorframework.io/v1 \
          --domain=example.com \
          --helm-chart=/path/to/local/chart-archives/app-1.2.3.tgz
    
    
    Flags:
          --project-version string      project version, possible values: ("2", "3-alpha") (default "3-alpha")
          --plugins strings             Name and optionally version of the plugin to initialize the project with. Available plugins: ("ansible.sdk.operatorframework.io/v1", "go.kubebuilder.io/v2", "helm.sdk.operatorframework.io/v1")
          --domain string               domain for groups (default "my.domain")
          --project-name string         name of this project, the default being directory name
          --group string                resource group
          --version string              resource version
          --kind string                 resource kind
          --helm-chart string           helm chart
          --helm-chart-repo string      helm chart repository
          --helm-chart-version string   helm chart version (default: latest)
          --crd-version string          crd version to generate (default "v1")
      -h, --help                        help for init
    
    Global Flags:
          --verbose   Enable verbose logging

This was an intentional change to overcome problems that we had with `operator-sdk new` where Go, Ansible, and Helm-specific flags would all show up together in the same help output. Now, each plugin has a separate help output. I think the fact that `operator-sdk init -h` asks users to re-run with more specific flags to see further help about specific projects versions and plugins is a reasonable tradeoff for increasing clarity and getting plugin-specific help text.

Comment 4 Jian Zhang 2020-08-07 02:24:44 UTC
Hi Joe,

Many thanks for your explanation! I see now, it looks good to me. But, there is a litte prroblem here:
As the help info shows, the default value of the `--project-version` is "3-alpha". I think I don't need to set the value if I want to use the default value, but it failed.

[root@preserve-olm-env data]# operator-sdk init  -h
...
      --project-version string   project version, possible values: ("2", "3-alpha") (default "3-alpha")

[root@preserve-olm-env data]# operator-sdk init --project-version  -h
FATA[0000] invalid project version "-h": invalid value for project version (regex used for validation is '[1-9][0-9]*(-(alpha|beta))?') 

Seems like it don't use the default value if I set nothing, is it a problem? Thanks! Feel free to change the status back, thanks!
[root@preserve-olm-env data]# operator-sdk init --project-version
flag needs an argument: --project-version
Usage of base:
  -h, --help                     print help
      --plugins string           plugins to run
      --project-version string   project version (default "3-alpha")
flag needs an argument: --project-version

Comment 5 Jesus M. Rodriguez 2020-08-20 18:16:10 UTC
Moving this to 4.7 because this is a bug against Operator SDK 1.0 which is not downstreaming with 4.6.

Comment 8 Eric Stroczynski 2021-01-18 20:23:14 UTC
Fixed by https://github.com/kubernetes-sigs/kubebuilder/pull/1937 in kubebuilder, dependency needs to be updated in operator-sdk.

Comment 9 Jesus M. Rodriguez 2021-03-18 22:39:03 UTC
Fixed in operator-sdk v1.5.0 upstream.

[jesusr@transam operator-sdk{v1.5.x}]$ operator-sdk version
operator-sdk version: "v1.5.0", commit: "98f30d59ade2d911a7a8c76f0169a7de0dec37a0", kubernetes version: "v1.19.4", go version: "go1.15.8", GOOS: "linux", GOARCH: "amd64"
[jesusr@transam operator-sdk{v1.5.x}]$ operator-sdk init --help
Initialize a new project including vendor/ directory and Go package directories.

Writes the following files:
- a boilerplate license file
- a PROJECT file with the domain and repo
- a Makefile to build the project
- a go.mod with project dependencies
- a Kustomization.yaml for customizating manifests
- a Patch file for customizing image for manager manifests
- a Patch file for enabling prometheus metrics
- a main.go to run

Usage:
  operator-sdk init [flags]

Examples:
  # Scaffold a project using the apache2 license with "The Kubernetes authors" as owners
  operator-sdk init --project-version=2 --domain example.org --license apache2 --owner "The Kubernetes authors"


Flags:
      --component-config        create a versioned ComponentConfig file, may be 'true' or 'false'
      --domain string           domain for groups (default "my.domain")
      --fetch-deps              ensure dependencies are downloaded (default true)
  -h, --help                    help for init
      --license string          license to use to boilerplate, may be one of 'apache2', 'none' (default "apache2")
      --owner string            owner to add to the copyright
      --project-name string     name of this project
      --repo string             name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.
      --skip-go-version-check   if specified, skip checking the Go version

Global Flags:
      --plugins strings          plugin keys of the plugin to initialize the project with
      --project-version string   project version
      --verbose                  Enable verbose logging

Comment 10 Fan Jia 2021-03-19 07:46:32 UTC
verified
operator-sdk version: "scorecard-kuttl/v2.0.0-11-gddd4ff3", commit: "ddd4ff3d58d935c45bcb0933e0caf9233fe52893", kubernetes version: "v1.19.4", go version: "go1.14", GOOS: "linux", GOARCH: "amd64"

# operator-sdk init --help
Initialize a new project including vendor/ directory and Go package directories.

Writes the following files:
- a boilerplate license file
- a PROJECT file with the domain and repo
- a Makefile to build the project
- a go.mod with project dependencies
- a Kustomization.yaml for customizating manifests
- a Patch file for customizing image for manager manifests
- a Patch file for enabling prometheus metrics
- a main.go to run

Usage:
  operator-sdk init [flags]

Examples:
  # Scaffold a project using the apache2 license with "The Kubernetes authors" as owners
  operator-sdk init --project-version=2 --domain example.org --license apache2 --owner "The Kubernetes authors"


Flags:
      --component-config        create a versioned ComponentConfig file, may be 'true' or 'false'
      --domain string           domain for groups (default "my.domain")
      --fetch-deps              ensure dependencies are downloaded (default true)
  -h, --help                    help for init
      --license string          license to use to boilerplate, may be one of 'apache2', 'none' (default "apache2")
      --owner string            owner to add to the copyright
      --project-name string     name of this project
      --repo string             name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.
      --skip-go-version-check   if specified, skip checking the Go version

Global Flags:
      --plugins strings          plugin keys of the plugin to initialize the project with
      --project-version string   project version
      --verbose                  Enable verbose logging

Comment 13 errata-xmlrpc 2021-07-27 22:32:47 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: OpenShift Container Platform 4.8.2 bug fix and security update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2021:2438