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

Check go version #353

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@
[[constraint]]
branch = "master"
name = "sigs.k8s.io/controller-tools"

[[constraint]]
name = "github.com/Masterminds/semver"
version = "1.4.2"
53 changes: 38 additions & 15 deletions cmd/kubebuilder/initproject/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/Masterminds/semver"
"github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/util"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-tools/pkg/scaffold/manager"
"sigs.k8s.io/controller-tools/pkg/scaffold/project"
)


type initOptions struct {
domain string
copyright string
bazel bool
domain string
copyright string
bazel bool
controllerOnly bool
projectVersion string
projectOptions
Expand All @@ -52,20 +52,19 @@ func AddInit(cmd *cobra.Command) {
kubebuilder init repo --domain mydomain
`,
Run: func(cmd *cobra.Command, args []string) {
o.runInitRepo()
o.runInitRepo()
},
}

v0comment := "Works only with project-version v0, "
initCmd.Flags().StringVar(&o.domain, "domain", "", "domain for the API groups")
initCmd.Flags().StringVar(&o.copyright, "copyright", filepath.Join("hack", "boilerplate.go.txt"), v0comment + "Location of copyright boilerplate file.")
initCmd.Flags().BoolVar(&o.bazel, "bazel", false, v0comment + "if true, setup Bazel workspace artifacts")
initCmd.Flags().BoolVar(&o.controllerOnly, "controller-only", false, v0comment + "if true, setup controller only")
initCmd.Flags().StringVar(&o.copyright, "copyright", filepath.Join("hack", "boilerplate.go.txt"), v0comment+"Location of copyright boilerplate file.")
initCmd.Flags().BoolVar(&o.bazel, "bazel", false, v0comment+"if true, setup Bazel workspace artifacts")
initCmd.Flags().BoolVar(&o.controllerOnly, "controller-only", false, v0comment+"if true, setup controller only")
initCmd.Flags().StringVar(&o.projectVersion, "project-version", "v1", "if set to v0, init project with kubebuilder legacy version")


initCmd.Flags().BoolVar(
&o.dep, "dep", true,"if specified, determines whether dep will be used.")
&o.dep, "dep", true, "if specified, determines whether dep will be used.")
o.depFlag = initCmd.Flag("dep")

o.prj = projectForFlags(initCmd.Flags())
Expand All @@ -78,10 +77,8 @@ kubebuilder init repo --domain mydomain
}

func (o *initOptions) runInitRepo() {
version := runtime.Version()
if versionCmp(version, "go1.10") < 0 {
log.Fatalf("The go version is %v, must be 1.10+", version)
}
checkGoVersion()

if !depExists() {
log.Fatalf("Dep is not installed. Follow steps at: https://golang.github.io/dep/docs/installation.html")
}
Expand Down Expand Up @@ -129,6 +126,32 @@ func (o *initOptions) runInitRepo() {
"$ kubebuilder create resource\n")
}

func checkGoVersion() {
cmd := exec.Command("go", "version")
out, err := cmd.Output()
if err != nil {
log.Fatalf("Could not execute 'go version': %v", err)
}

split := strings.Split(string(out), " ")
if len(split) < 3 {
log.Fatalf("Invalid go version: %q", string(out))
}
goVersion := strings.TrimPrefix(split[2], "go")
if ver, err := semver.NewVersion(goVersion); err != nil {
if err != nil {
log.Fatalf("Invalid go version %q: %v", goVersion, err)
}
c, err := semver.NewConstraint(">= 1.10")
if err != nil {
log.Fatal("Invalid constraint: %v", err)
}
if !c.Check(ver) {
log.Fatalf("The go version is %v, must be 1.10+", goVersion)
}
}
}

func execute(path, templateName, templateValue string, data interface{}) {
dir, err := os.Getwd()
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions cmd/vendor/github.com/Masterminds/semver/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions cmd/vendor/github.com/Masterminds/semver/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions cmd/vendor/github.com/Masterminds/semver/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions cmd/vendor/github.com/Masterminds/semver/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading