Skip to content

Commit

Permalink
implemented vendor update
Browse files Browse the repository at this point in the history
  • Loading branch information
droot committed Jul 12, 2018
1 parent 4dcef22 commit 41533b9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
28 changes: 17 additions & 11 deletions cmd/kubebuilder/initproject/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import (
)

type projectOptions struct {
prj *project.Project
bp *project.Boilerplate
gopkg *project.GopkgToml
mgr *manager.Cmd
dkr *manager.Dockerfile
dep bool
prj *project.Project
bp *project.Boilerplate
gopkg *project.GopkgToml
mgr *manager.Cmd
dkr *manager.Dockerfile
dep bool
depFlag *flag.Flag
}

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

s = &scaffold.Scaffold{}
err = s.Execute(input.Options{ProjectPath: p.Path, BoilerplatePath: b.Path},
o.gopkg, o.mgr, &project.Makefile{}, o.dkr, &manager.APIs{}, &manager.Controller{}, &manager.Config{},
o.gopkg,
o.mgr,
&project.Makefile{},
o.dkr,
&manager.APIs{},
&manager.Controller{},
&manager.Config{},
&project.GitIgnore{})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -141,7 +147,7 @@ kubebuilder init --domain k8s.io --license apache2 --owner "The Kubernetes autho
// projectForFlags registers flags for Project fields and returns the Project
func projectForFlags(f *flag.FlagSet) *project.Project {
p := &project.Project{}
f.StringVar(&p.Repo, "repo", "", v1comment + "name of the github repo. "+
f.StringVar(&p.Repo, "repo", "", v1comment+"name of the github repo. "+
"defaults to the go package of the current working directory.")
p.Version = "2"
p.Domain = "k8s.io"
Expand All @@ -151,10 +157,10 @@ func projectForFlags(f *flag.FlagSet) *project.Project {
// boilerplateForFlags registers flags for Boilerplate fields and returns the Boilerplate
func boilerplateForFlags(f *flag.FlagSet) *project.Boilerplate {
b := &project.Boilerplate{}
f.StringVar(&b.Path, "path", "", v1comment + "path for boilerplate")
f.StringVar(&b.Path, "path", "", v1comment+"path for boilerplate")
f.StringVar(&b.License, "license", "apache2",
v1comment + "license to use to boilerplate. Maybe one of apache2,none")
v1comment+"license to use to boilerplate. Maybe one of apache2,none")
f.StringVar(&b.Owner, "owner", "",
v1comment + "Owner to add to the copyright")
v1comment+"Owner to add to the copyright")
return b
}
4 changes: 2 additions & 2 deletions cmd/kubebuilder/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ After the scaffold is written, api will run make on the project.
cmd.AddCommand(apiCmd)
}

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

Expand Down
3 changes: 1 addition & 2 deletions cmd/kubebuilder/v1/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (

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

cmd.Example = `# Initialize your project
kubebuilder init --domain example.com --license apache2 --owner "The Kubernetes authors"
Expand Down
29 changes: 29 additions & 0 deletions cmd/kubebuilder/v1/vendor_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package v1

import (
"log"

"github.com/spf13/cobra"
"sigs.k8s.io/controller-tools/pkg/scaffold"
"sigs.k8s.io/controller-tools/pkg/scaffold/input"
"sigs.k8s.io/controller-tools/pkg/scaffold/project"
)

func vendorUpdateCmd() *cobra.Command {
return &cobra.Command{
Use: "update",
Short: "updates vendor dependencies.",
Long: `updates vendor dependencies.`,
Example: `Update the vendor dependencies:
kubebuilder update vendor
`,
Run: func(cmd *cobra.Command, args []string) {
dieIfNoProject()
err := (&scaffold.Scaffold{}).Execute(input.Options{},
&project.GopkgToml{})
if err != nil {
log.Fatalf("error updating vendor dependecies %v", err)
}
},
}
}
1 change: 1 addition & 0 deletions testv0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ build_kb
setup_envs

prepare_testdir_under_gopath

test_crd_validation
test_generated_controller

Expand Down

0 comments on commit 41533b9

Please sign in to comment.