Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the kubebuilder edit command for the project layout #1747

Closed
prafull01 opened this issue Oct 28, 2020 · 3 comments · Fixed by #1754
Closed

Validate the kubebuilder edit command for the project layout #1747

prafull01 opened this issue Oct 28, 2020 · 3 comments · Fixed by #1754
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@prafull01
Copy link
Contributor

prafull01 commented Oct 28, 2020

Scenario1: When I am trying to run edit command without any inputs with no api created, throws following error

prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ ../bin/kubebuilder edit
Error: failed to edit project with version "3-alpha": can't find "COPY apis/ apis/"
Usage:
  kubebuilder edit [flags]

Examples:
# Enable the multigroup layout
        kubebuilder edit --multigroup

        # Disable the multigroup layout
        kubebuilder edit --multigroup=false
	

Flags:
  -h, --help         help for edit
      --multigroup   enable or disable multigroup layout

2020/10/28 11:07:49 failed to edit project with version "3-alpha": can't find "COPY apis/ apis/"

Scenario2: The same command I ran after creating one api and moving the scaffolding to multi group. The kb edit command without any inputs moved the project scaffolding to single group.

prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ ./bin/kubebuilder create api --group praf --kind Lakers --version v1
Create Resource [y/n]
y
Create Controller [y/n]
y
Writing scaffold for you to edit...
api/v1/lakers_types.go
controllers/lakers_controller.go
Running make:
$ make
/home/prafull/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager main.go
prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ ../bin/kubebuilder edit --multigroup=true

prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ cat PROJECT 
domain: my.domain
layout: go.kubebuilder.io/v3-alpha
multigroup: true
projectName: proj
repo: sigs.k8s.io/kubebuilder
resources:
- group: praf
  kind: Lakers
  version: v1
version: 3-alpha

prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ ../bin/kubebuilder edit 

prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ cat PROJECT 
domain: my.domain
layout: go.kubebuilder.io/v3-alpha
projectName: proj
repo: sigs.k8s.io/kubebuilder
resources:
- group: praf
  kind: Lakers
  version: v1
version: 3-alpha

Add a validation if the project is already on the same scaffolding and if yes, then don't try to edit it.

@prafull01 prafull01 added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 28, 2020
@prafull01
Copy link
Contributor Author

/assign

@prafull01
Copy link
Contributor Author

This happens because kb edit command sets the default value as false. However when editing the scaffolding already on same type, throws error. However this error should be catch in the validation itself and proper message should be shown to user

@prafull01 prafull01 changed the title Validate the kubebuilder edit command for the inputs Validate the kubebuilder edit command for the project layout Oct 29, 2020
@prafull01
Copy link
Contributor Author

The current implementation also fails if we try to edit a project which is already on the same type. Current, failure happens in the PostScaffolding of the kb edit command.

prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ ../bin/kubebuilder edit --multigroup=true
prafull@EMPID18004:~/go/src/github.com/prafull01/kubebuilder/proj$ ../bin/kubebuilder edit --multigroup=true
Error: failed to edit project with version "3-alpha": can't find "COPY api/ api/"
Usage:
  kubebuilder edit [flags]

Examples:
# Enable the multigroup layout
        kubebuilder edit --multigroup

        # Disable the multigroup layout
        kubebuilder edit --multigroup=false
	

Flags:
  -h, --help         help for edit
      --multigroup   enable or disable multigroup layout

2020/10/30 00:13:52 failed to edit project with version "3-alpha": can't find "COPY api/ api/"

This change will give more clear message to the user that he is already on the same type of the project layout.

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
2 participants