Skip to content

Commit 102bcae

Browse files
committed
cmd/operator-sdk,internal/util/projutil: fix comment, reuse checkGoModules
1 parent 107bbf0 commit 102bcae

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

cmd/operator-sdk/main.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package main
1616

1717
import (
18-
"fmt"
1918
"os"
2019

2120
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
@@ -93,8 +92,8 @@ func checkGoModulesForCmd(cmd *cobra.Command) (err error) {
9392
if skipCheckForCmd(cmd) {
9493
return nil
9594
}
96-
// Do not perform this check if the project is non-Go, as they will be
97-
// using go modules.
95+
// Do not perform this check if the project is non-Go, as they will not
96+
// be using go modules.
9897
if !projutil.IsOperatorGo() {
9998
return nil
10099
}
@@ -105,7 +104,7 @@ func checkGoModulesForCmd(cmd *cobra.Command) (err error) {
105104
return nil
106105
}
107106

108-
return checkGoModules()
107+
return projutil.CheckGoModules()
109108
}
110109

111110
var commandsToSkip = map[string]struct{}{
@@ -132,15 +131,3 @@ func skipCheckForCmd(cmd *cobra.Command) (skip bool) {
132131
})
133132
return skip
134133
}
135-
136-
func checkGoModules() error {
137-
goModOn, err := projutil.GoModOn()
138-
if err != nil {
139-
return err
140-
}
141-
if !goModOn {
142-
return fmt.Errorf(`using go modules requires GO111MODULE="on", "auto", or unset.` +
143-
` More info: https://github.com/operator-framework/operator-sdk/blob/master/doc/user-guide.md#go-modules`)
144-
}
145-
return nil
146-
}

cmd/operator-sdk/new/cmd.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,8 @@ func doGoScaffold() error {
178178
s.BoilerplatePath = headerFile
179179
}
180180

181-
if goModOn, merr := projutil.GoModOn(); merr != nil {
182-
return merr
183-
} else if !goModOn {
184-
return errors.New(`using go modules requires GO111MODULE="on", "auto", or unset.` +
185-
` More info: https://github.com/operator-framework/operator-sdk/blob/master/doc/user-guide.md#go-modules`)
181+
if err := projutil.CheckGoModules(); err != nil {
182+
return err
186183
}
187184

188185
err := s.Execute(cfg,

internal/util/projutil/project_util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,16 @@ func CheckRepo(repo string) error {
256256
}
257257
return nil
258258
}
259+
260+
// CheckGoModules ensures that go modules are enabled.
261+
func CheckGoModules() error {
262+
goModOn, err := GoModOn()
263+
if err != nil {
264+
return err
265+
}
266+
if !goModOn {
267+
return fmt.Errorf(`using go modules requires GO111MODULE="on", "auto", or unset.` +
268+
` More info: https://github.com/operator-framework/operator-sdk/blob/master/doc/user-guide.md#go-modules`)
269+
}
270+
return nil
271+
}

0 commit comments

Comments
 (0)