@@ -206,57 +206,46 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, imageType string, use
206
206
207
207
func downloadKubernetesSource (pkgDir , k8sIoDir , kubeVersion string ) error {
208
208
k8sDir := filepath .Join (k8sIoDir , "kubernetes" )
209
- /*
210
- // TODO: Download a fresh copy every time until mutate manifests hardcoding existing image is solved.
211
- if _, err := os.Stat(k8sDir); !os.IsNotExist(err) {
212
- klog.Infof("Staging Kubernetes already found at %s, skipping download", k8sDir)
213
- return nil
214
- }
215
- */
216
-
217
- klog .V (4 ).Infof ("Staging Kubernetes folder not found, downloading now" )
209
+ klog .V (4 ).Infof ("Downloading Kubernetes source" )
218
210
219
- err := os .MkdirAll (k8sIoDir , 0777 )
220
- if err != nil {
211
+ if err := os .MkdirAll (k8sIoDir , 0777 ); err != nil {
212
+ return err
213
+ }
214
+ if err := os .RemoveAll (k8sDir ); err != nil {
221
215
return err
222
216
}
223
217
224
- kubeTarDir := filepath .Join (k8sIoDir , fmt .Sprintf ("kubernetes-%s.tar.gz" , kubeVersion ))
225
-
226
- var vKubeVersion string
227
218
if kubeVersion == "master" {
228
- vKubeVersion = kubeVersion
229
- // A hack to be able to build Kubernetes in this nested place
230
- // KUBE_GIT_VERSION_FILE set to file to load kube version from
231
- err = os .Setenv ("KUBE_GIT_VERSION_FILE" , filepath .Join (pkgDir , "test" , "k8s-integration" , ".dockerized-kube-version-defs" ))
219
+ // Clone of master. We cannot download the master version from the archive, because the k8s
220
+ // version is not set, which affects which APIs are removed in the running cluster. We cannot
221
+ // use a shallow clone, because in order to find the revision git searches through the tags,
222
+ // and tags are not fetched in a shallow clone. Not using a shallow clone adds about 700M to the
223
+ // ~5G archive directory, after make quick-release, so this is not disastrous.
224
+ out , err := exec .Command ("git" , "clone" , "https://github.com/kubernetes/kubernetes" , k8sDir ).CombinedOutput ()
232
225
if err != nil {
233
- return err
226
+ return fmt . Errorf ( "failed to clone kubernetes master: %s, err: %v" , out , err )
234
227
}
235
228
} else {
236
- vKubeVersion = "v" + kubeVersion
237
- }
238
- out , err := exec .Command ("curl" , "-L" , fmt .Sprintf ("https://github.com/kubernetes/kubernetes/archive/%s.tar.gz" , vKubeVersion ), "-o" , kubeTarDir ).CombinedOutput ()
239
- if err != nil {
240
- return fmt .Errorf ("failed to curl kubernetes version %s: %s, err: %v" , kubeVersion , out , err )
241
- }
229
+ // Download from the release archives rather than cloning the repo.
230
+ vKubeVersion := "v" + kubeVersion
231
+ kubeTarDir := filepath .Join (k8sIoDir , fmt .Sprintf ("kubernetes-%s.tar.gz" , kubeVersion ))
232
+ out , err := exec .Command ("curl" , "-L" , fmt .Sprintf ("https://github.com/kubernetes/kubernetes/archive/%s.tar.gz" , vKubeVersion ), "-o" , kubeTarDir ).CombinedOutput ()
233
+ if err != nil {
234
+ return fmt .Errorf ("failed to curl kubernetes version %s: %s, err: %v" , kubeVersion , out , err )
235
+ }
242
236
243
- out , err = exec .Command ("tar" , "-C" , k8sIoDir , "-xvf" , kubeTarDir ).CombinedOutput ()
244
- if err != nil {
245
- return fmt .Errorf ("failed to untar %s: %s, err: %v" , kubeTarDir , out , err )
246
- }
237
+ out , err = exec .Command ("tar" , "-C" , k8sIoDir , "-xvf" , kubeTarDir ).CombinedOutput ()
238
+ if err != nil {
239
+ return fmt .Errorf ("failed to untar %s: %s, err: %v" , kubeTarDir , out , err )
240
+ }
247
241
248
- err = os .RemoveAll ( k8sDir )
249
- if err != nil {
250
- return err
251
- }
242
+ err = os .Rename ( filepath . Join ( k8sIoDir , fmt . Sprintf ( "kubernetes-%s" , kubeVersion )), k8sDir )
243
+ if err != nil {
244
+ return err
245
+ }
252
246
253
- err = os .Rename (filepath .Join (k8sIoDir , fmt .Sprintf ("kubernetes-%s" , kubeVersion )), k8sDir )
254
- if err != nil {
255
- return err
247
+ klog .V (4 ).Infof ("Successfully downloaded Kubernetes v%s to %s" , kubeVersion , k8sDir )
256
248
}
257
-
258
- klog .V (4 ).Infof ("Successfully downloaded Kubernetes v%s to %s" , kubeVersion , k8sDir )
259
-
260
249
return nil
261
250
}
262
251
0 commit comments