@@ -24,7 +24,7 @@ import (
24
24
"os/exec"
25
25
"path/filepath"
26
26
27
- "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil "
27
+ "github.com/operator-framework/operator-sdk/internal/util/projutil "
28
28
"github.com/operator-framework/operator-sdk/pkg/scaffold"
29
29
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
30
30
"github.com/operator-framework/operator-sdk/pkg/test"
@@ -132,16 +132,12 @@ func verifyTestManifest(image string) {
132
132
}
133
133
}
134
134
135
- const (
136
- mainGo = "./cmd/manager/main.go"
137
- )
138
-
139
135
func buildFunc (cmd * cobra.Command , args []string ) {
140
136
if len (args ) != 1 {
141
137
log .Fatalf ("build command needs exactly 1 argument" )
142
138
}
143
139
144
- cmdutil .MustInProjectRoot ()
140
+ projutil .MustInProjectRoot ()
145
141
goBuildEnv := append (os .Environ (), "GOOS=linux" , "GOARCH=amd64" , "CGO_ENABLED=0" )
146
142
wd , err := os .Getwd ()
147
143
if err != nil {
@@ -150,8 +146,8 @@ func buildFunc(cmd *cobra.Command, args []string) {
150
146
151
147
// Don't need to buld go code if Ansible Operator
152
148
if mainExists () {
153
- managerDir := filepath .Join (cmdutil .CheckAndGetCurrPkg (), "cmd/manager" )
154
- outputBinName := filepath .Join (wd , "build/_output/bin" , filepath .Base (wd ))
149
+ managerDir := filepath .Join (projutil .CheckAndGetCurrPkg (), scaffold . ManagerDir )
150
+ outputBinName := filepath .Join (wd , scaffold . BuildBinDir , filepath .Base (wd ))
155
151
buildCmd := exec .Command ("go" , "build" , "-o" , outputBinName , managerDir )
156
152
buildCmd .Env = goBuildEnv
157
153
o , err := buildCmd .CombinedOutput ()
@@ -178,20 +174,22 @@ func buildFunc(cmd *cobra.Command, args []string) {
178
174
fmt .Fprintln (os .Stdout , string (o ))
179
175
180
176
if enableTests {
181
- buildTestCmd := exec .Command ("go" , "test" , "-c" , "-o" , filepath .Join (wd , "build/_output/bin" , filepath .Base (wd )+ "-test" ), testLocationBuild + "/..." )
177
+ testBinary := filepath .Join (wd , scaffold .BuildBinDir , filepath .Base (wd )+ "-test" )
178
+ buildTestCmd := exec .Command ("go" , "test" , "-c" , "-o" , testBinary , testLocationBuild + "/..." )
182
179
buildTestCmd .Env = goBuildEnv
183
180
o , err := buildTestCmd .CombinedOutput ()
184
181
if err != nil {
185
182
log .Fatalf ("failed to build test binary: %v (%v)" , err , string (o ))
186
183
}
187
184
fmt .Fprintln (os .Stdout , string (o ))
188
185
// if a user is using an older sdk repo as their library, make sure they have required build files
189
- _ , err = os .Stat ("build/test-framework/Dockerfile" )
186
+ testDockerfile := filepath .Join (scaffold .BuildTestDir , scaffold .DockerfileFile )
187
+ _ , err = os .Stat (testDockerfile )
190
188
if err != nil && os .IsNotExist (err ) {
191
189
192
- absProjectPath := cmdutil .MustGetwd ()
190
+ absProjectPath := projutil .MustGetwd ()
193
191
cfg := & input.Config {
194
- Repo : cmdutil .CheckAndGetCurrPkg (),
192
+ Repo : projutil .CheckAndGetCurrPkg (),
195
193
AbsProjectPath : absProjectPath ,
196
194
ProjectName : filepath .Base (wd ),
197
195
}
@@ -207,7 +205,7 @@ func buildFunc(cmd *cobra.Command, args []string) {
207
205
}
208
206
}
209
207
210
- testDbcmd := exec .Command ("docker" , "build" , "." , "-f" , "build/test-framework/Dockerfile" , "-t" , image , "--build-arg" , "NAMESPACEDMAN=" + namespacedManBuild , "--build-arg" , "BASEIMAGE=" + baseImageName )
208
+ testDbcmd := exec .Command ("docker" , "build" , "." , "-f" , testDockerfile , "-t" , image , "--build-arg" , "NAMESPACEDMAN=" + namespacedManBuild , "--build-arg" , "BASEIMAGE=" + baseImageName )
211
209
o , err = testDbcmd .CombinedOutput ()
212
210
if err != nil {
213
211
log .Fatalf ("failed to output build image %s: %v (%s)" , image , err , string (o ))
@@ -219,8 +217,6 @@ func buildFunc(cmd *cobra.Command, args []string) {
219
217
}
220
218
221
219
func mainExists () bool {
222
- if _ , err := os .Stat (mainGo ); err == nil {
223
- return true
224
- }
225
- return false
220
+ _ , err := os .Stat (filepath .Join (scaffold .ManagerDir , scaffold .CmdFile ))
221
+ return err == nil
226
222
}
0 commit comments