@@ -21,6 +21,9 @@ import (
21
21
"log"
22
22
"os"
23
23
"path/filepath"
24
+ "runtime"
25
+ "strconv"
26
+ "strings"
24
27
25
28
"github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/util"
26
29
"github.com/spf13/cobra"
@@ -48,6 +51,11 @@ func AddInit(cmd *cobra.Command) {
48
51
}
49
52
50
53
func runInitRepo (cmd * cobra.Command , args []string ) {
54
+ version := runtime .Version ()
55
+ if versionCmp (version , "go1.10" ) < 0 {
56
+ log .Fatalf ("The go version is %v, must be 1.10+" , version )
57
+ }
58
+
51
59
if len (domain ) == 0 {
52
60
log .Fatal ("Must specify --domain" )
53
61
}
@@ -97,3 +105,29 @@ type templateArgs struct {
97
105
BoilerPlate string
98
106
Repo string
99
107
}
108
+
109
+ func versionCmp (v1 string , v2 string ) int {
110
+ v1s := strings .Split (strings .Replace (v1 , "go" , "" , 1 ), "." )
111
+ v2s := strings .Split (strings .Replace (v2 , "go" , "" , 1 ), "." )
112
+ for i := 0 ; i < len (v1s ) && i < len (v2s ); i ++ {
113
+ mv1 , err1 := strconv .Atoi (v1s [i ])
114
+ mv2 , err2 := strconv .Atoi (v2s [i ])
115
+ if err1 == nil && err2 == nil {
116
+ cmp := mv1 - mv2
117
+ if cmp > 0 {
118
+ return 1
119
+ } else if cmp < 0 {
120
+ return - 1
121
+ }
122
+ } else {
123
+ log .Fatalf ("Unexpected error comparing %v with %v" , v1 , v2 )
124
+ }
125
+ }
126
+ if len (v1s ) == len (v2s ) {
127
+ return 0
128
+ } else if len (v1s ) > len (v2s ) {
129
+ return 1
130
+ } else {
131
+ return - 1
132
+ }
133
+ }
0 commit comments