@@ -193,57 +193,46 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, imageType string, use
193193
194194func downloadKubernetesSource (pkgDir , k8sIoDir , kubeVersion string ) error {
195195 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" )
205197
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 {
208202 return err
209203 }
210204
211- kubeTarDir := filepath .Join (k8sIoDir , fmt .Sprintf ("kubernetes-%s.tar.gz" , kubeVersion ))
212-
213- var vKubeVersion string
214205 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 ()
219212 if err != nil {
220- return err
213+ return fmt . Errorf ( "failed to clone kubernetes master: %s, err: %v" , out , err )
221214 }
222215 } 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+ }
229223
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+ }
234228
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+ }
239233
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 )
243235 }
244-
245- klog .V (4 ).Infof ("Successfully downloaded Kubernetes v%s to %s" , kubeVersion , k8sDir )
246-
247236 return nil
248237}
249238
0 commit comments