Skip to content

Commit 01a605a

Browse files
authored
Merge pull request #305 from droot/vendor-update-cmd
implemented vendor update
2 parents 4dcef22 + 41533b9 commit 01a605a

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

cmd/kubebuilder/initproject/project.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import (
3434
)
3535

3636
type projectOptions struct {
37-
prj *project.Project
38-
bp *project.Boilerplate
39-
gopkg *project.GopkgToml
40-
mgr *manager.Cmd
41-
dkr *manager.Dockerfile
42-
dep bool
37+
prj *project.Project
38+
bp *project.Boilerplate
39+
gopkg *project.GopkgToml
40+
mgr *manager.Cmd
41+
dkr *manager.Dockerfile
42+
dep bool
4343
depFlag *flag.Flag
4444
}
4545

@@ -65,7 +65,13 @@ func (o *projectOptions) RunInit() {
6565

6666
s = &scaffold.Scaffold{}
6767
err = s.Execute(input.Options{ProjectPath: p.Path, BoilerplatePath: b.Path},
68-
o.gopkg, o.mgr, &project.Makefile{}, o.dkr, &manager.APIs{}, &manager.Controller{}, &manager.Config{},
68+
o.gopkg,
69+
o.mgr,
70+
&project.Makefile{},
71+
o.dkr,
72+
&manager.APIs{},
73+
&manager.Controller{},
74+
&manager.Config{},
6975
&project.GitIgnore{})
7076
if err != nil {
7177
log.Fatal(err)
@@ -141,7 +147,7 @@ kubebuilder init --domain k8s.io --license apache2 --owner "The Kubernetes autho
141147
// projectForFlags registers flags for Project fields and returns the Project
142148
func projectForFlags(f *flag.FlagSet) *project.Project {
143149
p := &project.Project{}
144-
f.StringVar(&p.Repo, "repo", "", v1comment + "name of the github repo. "+
150+
f.StringVar(&p.Repo, "repo", "", v1comment+"name of the github repo. "+
145151
"defaults to the go package of the current working directory.")
146152
p.Version = "2"
147153
p.Domain = "k8s.io"
@@ -151,10 +157,10 @@ func projectForFlags(f *flag.FlagSet) *project.Project {
151157
// boilerplateForFlags registers flags for Boilerplate fields and returns the Boilerplate
152158
func boilerplateForFlags(f *flag.FlagSet) *project.Boilerplate {
153159
b := &project.Boilerplate{}
154-
f.StringVar(&b.Path, "path", "", v1comment + "path for boilerplate")
160+
f.StringVar(&b.Path, "path", "", v1comment+"path for boilerplate")
155161
f.StringVar(&b.License, "license", "apache2",
156-
v1comment + "license to use to boilerplate. Maybe one of apache2,none")
162+
v1comment+"license to use to boilerplate. Maybe one of apache2,none")
157163
f.StringVar(&b.Owner, "owner", "",
158-
v1comment + "Owner to add to the copyright")
164+
v1comment+"Owner to add to the copyright")
159165
return b
160166
}

cmd/kubebuilder/v1/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ After the scaffold is written, api will run make on the project.
159159
cmd.AddCommand(apiCmd)
160160
}
161161

162-
// DieIfNoProject checks to make sure the command is run from a directory containing a project file.
162+
// dieIfNoProject checks to make sure the command is run from a directory containing a project file.
163163
func dieIfNoProject() {
164164
if _, err := os.Stat("PROJECT"); os.IsNotExist(err) {
165-
log.Fatalf("Command must be run from a diretory containing %s", "PROJECT")
165+
log.Fatalf("Command must be run from a directory containing %s", "PROJECT")
166166
}
167167
}
168168

cmd/kubebuilder/v1/commands.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222

2323
func AddCmds(cmd *cobra.Command) {
2424
AddAPICommand(cmd)
25-
// TODO: User update commands from controller-tools once it is available
26-
//update.AddUpdate(cmd)
25+
cmd.AddCommand(vendorUpdateCmd())
2726

2827
cmd.Example = `# Initialize your project
2928
kubebuilder init --domain example.com --license apache2 --owner "The Kubernetes authors"

cmd/kubebuilder/v1/vendor_update.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package v1
2+
3+
import (
4+
"log"
5+
6+
"github.com/spf13/cobra"
7+
"sigs.k8s.io/controller-tools/pkg/scaffold"
8+
"sigs.k8s.io/controller-tools/pkg/scaffold/input"
9+
"sigs.k8s.io/controller-tools/pkg/scaffold/project"
10+
)
11+
12+
func vendorUpdateCmd() *cobra.Command {
13+
return &cobra.Command{
14+
Use: "update",
15+
Short: "updates vendor dependencies.",
16+
Long: `updates vendor dependencies.`,
17+
Example: `Update the vendor dependencies:
18+
kubebuilder update vendor
19+
`,
20+
Run: func(cmd *cobra.Command, args []string) {
21+
dieIfNoProject()
22+
err := (&scaffold.Scaffold{}).Execute(input.Options{},
23+
&project.GopkgToml{})
24+
if err != nil {
25+
log.Fatalf("error updating vendor dependecies %v", err)
26+
}
27+
},
28+
}
29+
}

testv0.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ build_kb
522522
setup_envs
523523

524524
prepare_testdir_under_gopath
525+
525526
test_crd_validation
526527
test_generated_controller
527528

0 commit comments

Comments
 (0)