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