41
41
saFile = flag .String ("service-account-file" , "" , "path of service account file" )
42
42
deployOverlayName = flag .String ("deploy-overlay-name" , "" , "which kustomize overlay to deploy the driver with" )
43
43
localK8sDir = flag .String ("local-k8s-dir" , "" , "local kubernetes/kubernetes directory to run e2e tests from" )
44
+ doDriverBuild = flag .Bool ("do-driver-build" , true , "building the driver from source" )
44
45
)
45
46
46
47
func init () {
@@ -100,14 +101,16 @@ func handle() error {
100
101
}
101
102
}()
102
103
103
- * stagingImage = fmt .Sprintf ("gcr.io/%s/gcp-persistent-disk-csi-driver" , project )
104
+ if * doDriverBuild {
105
+ * stagingImage = fmt .Sprintf ("gcr.io/%s/gcp-persistent-disk-csi-driver" , project )
104
106
105
- // TODO: once https://github.com/kubernetes-sigs/kustomize/issues/402 is implemented,
106
- // we no longer need to do this templating work and can just edit the image registry directly.
107
- overlayDir := getOverlayDir (pkgDir , * deployOverlayName )
108
- err = fillinOverlayTemplate (overlayDir , * stagingImage )
109
- if err != nil {
110
- return fmt .Errorf ("tmpOverlayDir setup failed: %v" , err )
107
+ // TODO: once https://github.com/kubernetes-sigs/kustomize/issues/402 is implemented,
108
+ // we no longer need to do this templating work and can just edit the image registry directly.
109
+ overlayDir := getOverlayDir (pkgDir , * deployOverlayName )
110
+ err = fillinOverlayTemplate (overlayDir , * stagingImage )
111
+ if err != nil {
112
+ return fmt .Errorf ("tmpOverlayDir setup failed: %v" , err )
113
+ }
111
114
}
112
115
113
116
if _ , ok := os .LookupEnv ("USER" ); ! ok {
@@ -118,21 +121,23 @@ func handle() error {
118
121
}
119
122
}
120
123
121
- err := pushImage (pkgDir , * stagingImage , stagingVersion )
122
- if err != nil {
123
- return fmt .Errorf ("failed pushing image: %v" , err )
124
- }
125
- defer func () {
126
- if * teardownCluster {
127
- err = deleteImage (* stagingImage , stagingVersion )
128
- if err != nil {
129
- glog .Errorf ("failed to delete image: %v" , err )
130
- }
124
+ if * doDriverBuild {
125
+ err := pushImage (pkgDir , * stagingImage , stagingVersion )
126
+ if err != nil {
127
+ return fmt .Errorf ("failed pushing image: %v" , err )
131
128
}
132
- }()
129
+ defer func () {
130
+ if * teardownCluster {
131
+ err = deleteImage (* stagingImage , stagingVersion )
132
+ if err != nil {
133
+ glog .Errorf ("failed to delete image: %v" , err )
134
+ }
135
+ }
136
+ }()
137
+ }
133
138
134
139
if * bringupCluster {
135
- err = downloadKubernetesSource (pkgDir , k8sIoDir , * kubeVersion )
140
+ err : = downloadKubernetesSource (pkgDir , k8sIoDir , * kubeVersion )
136
141
if err != nil {
137
142
return fmt .Errorf ("failed to download Kubernetes source: %v" , err )
138
143
}
@@ -150,14 +155,14 @@ func handle() error {
150
155
151
156
if * teardownCluster {
152
157
defer func () {
153
- err = clusterDown (k8sDir )
158
+ err : = clusterDown (k8sDir )
154
159
if err != nil {
155
160
glog .Errorf ("failed to cluster down: %v" , err )
156
161
}
157
162
}()
158
163
}
159
164
160
- err = installDriver (goPath , pkgDir , k8sDir , * stagingImage , stagingVersion , * deployOverlayName )
165
+ err : = installDriver (goPath , pkgDir , k8sDir , * stagingImage , stagingVersion , * deployOverlayName , * doDriverBuild )
161
166
if * teardownDriver {
162
167
defer func () {
163
168
// TODO (#140): collect driver logs
@@ -260,30 +265,32 @@ func getOverlayDir(pkgDir, deployOverlayName string) string {
260
265
return filepath .Join (pkgDir , "deploy" , "kubernetes" , "overlays" , deployOverlayName )
261
266
}
262
267
263
- func installDriver (goPath , pkgDir , k8sDir , stagingImage , stagingVersion , deployOverlayName string ) error {
264
- // Install kustomize
265
- out , err := exec .Command (filepath .Join (pkgDir , "deploy" , "kubernetes" , "install-kustomize.sh" )).CombinedOutput ()
266
- if err != nil {
267
- return fmt .Errorf ("failed to install kustomize: %s, err: %v" , out , err )
268
- }
268
+ func installDriver (goPath , pkgDir , k8sDir , stagingImage , stagingVersion , deployOverlayName string , doDriverBuild bool ) error {
269
+ if doDriverBuild {
270
+ // Install kustomize
271
+ out , err := exec .Command (filepath .Join (pkgDir , "deploy" , "kubernetes" , "install-kustomize.sh" )).CombinedOutput ()
272
+ if err != nil {
273
+ return fmt .Errorf ("failed to install kustomize: %s, err: %v" , out , err )
274
+ }
269
275
270
- // Edit ci kustomization to use given image tag
271
- overlayDir := getOverlayDir (pkgDir , deployOverlayName )
272
- err = os .Chdir (overlayDir )
273
- if err != nil {
274
- return fmt .Errorf ("failed to change to overlay directory: %s, err: %v" , out , err )
275
- }
276
+ // Edit ci kustomization to use given image tag
277
+ overlayDir := getOverlayDir (pkgDir , deployOverlayName )
278
+ err = os .Chdir (overlayDir )
279
+ if err != nil {
280
+ return fmt .Errorf ("failed to change to overlay directory: %s, err: %v" , out , err )
281
+ }
276
282
277
- // TODO (#138): in a local environment this is going to modify the actual kustomize files.
278
- // maybe a copy should be made instead
279
- out , err = exec .Command (
280
- filepath .Join (pkgDir , "bin" , "kustomize" ),
281
- "edit" ,
282
- "set" ,
283
- "imagetag" ,
284
- fmt .Sprintf ("%s:%s" , stagingImage , stagingVersion )).CombinedOutput ()
285
- if err != nil {
286
- return fmt .Errorf ("failed to edit kustomize: %s, err: %v" , out , err )
283
+ // TODO (#138): in a local environment this is going to modify the actual kustomize files.
284
+ // maybe a copy should be made instead
285
+ out , err = exec .Command (
286
+ filepath .Join (pkgDir , "bin" , "kustomize" ),
287
+ "edit" ,
288
+ "set" ,
289
+ "imagetag" ,
290
+ fmt .Sprintf ("%s:%s" , stagingImage , stagingVersion )).CombinedOutput ()
291
+ if err != nil {
292
+ return fmt .Errorf ("failed to edit kustomize: %s, err: %v" , out , err )
293
+ }
287
294
}
288
295
289
296
// setup service account file for secret creation
@@ -293,7 +300,7 @@ func installDriver(goPath, pkgDir, k8sDir, stagingImage, stagingVersion, deployO
293
300
defer os .Remove (filepath .Dir (tmpSaFile ))
294
301
295
302
// Need to copy it to name the file "cloud-sa.json"
296
- out , err = exec .Command ("cp" , * saFile , tmpSaFile ).CombinedOutput ()
303
+ out , err : = exec .Command ("cp" , * saFile , tmpSaFile ).CombinedOutput ()
297
304
if err != nil {
298
305
return fmt .Errorf ("error copying service account key: %s, err: %v" , out , err )
299
306
}
0 commit comments