@@ -222,38 +222,27 @@ func downloadKubernetesSource(pkgDir, k8sIoDir, kubeVersion string) error {
222222 return err
223223 }
224224
225+ // We clone rather than download from release archives, because the file naming has not been
226+ // stable. For example, in late 2021 it appears that archives of minor versions (eg v1.21.tgz)
227+ // stopped and was replaced with just patch version.
225228 if kubeVersion == "master" {
226- // Clone of master. We cannot download the master version from the archive, because the k8s
227- // version is not set, which affects which APIs are removed in the running cluster. We cannot
228- // use a shallow clone, because in order to find the revision git searches through the tags,
229- // and tags are not fetched in a shallow clone. Not using a shallow clone adds about 700M to the
230- // ~5G archive directory, after make quick-release, so this is not disastrous.
229+ // Clone of master. We cannot use a shallow clone, because the k8s version is not set, and
230+ // in order to find the revision git searches through the tags, and tags are not fetched in
231+ // a shallow clone. Not using a shallow clone adds about 700M to the ~5G archive directory,
232+ // after make quick-release, so this is not disastrous.
231233 klog .Info ("cloning k8s master" )
232234 out , err := exec .Command ("git" , "clone" , "https://github.com/kubernetes/kubernetes" , k8sDir ).CombinedOutput ()
233235 if err != nil {
234236 return fmt .Errorf ("failed to clone kubernetes master: %s, err: %v" , out , err )
235237 }
236238 } else {
237- // Download from the release archives rather than cloning the repo .
239+ // Shallow clone of a release branch .
238240 vKubeVersion := "v" + kubeVersion
239- kubeTarDir := filepath .Join (k8sIoDir , fmt .Sprintf ("kubernetes-%s.tar.gz" , kubeVersion ))
240- klog .Infof ("Pulling archive for %s" , vKubeVersion )
241- out , err := exec .Command ("curl" , "-L" , fmt .Sprintf ("https://github.com/kubernetes/kubernetes/archive/%s.tar.gz" , vKubeVersion ), "-o" , kubeTarDir ).CombinedOutput ()
241+ klog .Infof ("shallow clone of k8s %s" , vKubeVersion )
242+ out , err := exec .Command ("git" , "clone" , "--depth" , "1" , "https://github.com/kubernetes/kubernetes" , k8sDir ).CombinedOutput ()
242243 if err != nil {
243- return fmt .Errorf ("failed to curl kubernetes version %s: %s, err: %v" , kubeVersion , out , err )
244+ return fmt .Errorf ("failed to clone kubernetes %s: %s, err: %v" , vKubeVersion , out , err )
244245 }
245-
246- out , err = exec .Command ("tar" , "-C" , k8sIoDir , "-xvf" , kubeTarDir ).CombinedOutput ()
247- if err != nil {
248- return fmt .Errorf ("failed to untar %s: %s, err: %v" , kubeTarDir , out , err )
249- }
250-
251- err = os .Rename (filepath .Join (k8sIoDir , fmt .Sprintf ("kubernetes-%s" , kubeVersion )), k8sDir )
252- if err != nil {
253- return err
254- }
255-
256- klog .Infof ("Successfully downloaded Kubernetes v%s to %s" , kubeVersion , k8sDir )
257246 }
258247 return nil
259248}
0 commit comments