Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
b0f685c0
M
minikube
项目概览
Chu Peng 楚鹏
/
minikube
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
minikube
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b0f685c0
编写于
2月 20, 2020
作者:
P
Priya Wadhwa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move all preloading code into preload package
上级
19fa2966
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
21 deletion
+30
-21
pkg/drivers/kic/kic.go
pkg/drivers/kic/kic.go
+5
-1
pkg/drivers/kic/oci/volumes.go
pkg/drivers/kic/oci/volumes.go
+6
-8
pkg/drivers/kic/preload/preload.go
pkg/drivers/kic/preload/preload.go
+12
-6
pkg/minikube/node/cache.go
pkg/minikube/node/cache.go
+7
-6
未找到文件。
pkg/drivers/kic/kic.go
浏览文件 @
b0f685c0
...
...
@@ -22,6 +22,7 @@ import (
"os/exec"
"strconv"
"strings"
"time"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
...
...
@@ -88,10 +89,13 @@ func (d *Driver) Create() error {
ContainerPort
:
constants
.
DockerDaemonPort
,
},
)
volumeName
,
err
:=
oci
.
CreatePreloadedImagesVolume
(
d
.
NodeConfig
.
KubernetesVersion
)
t
:=
time
.
Now
()
glog
.
Infof
(
"Starting creating preloaded images volume"
)
volumeName
,
err
:=
oci
.
CreatePreloadedImagesVolume
(
d
.
NodeConfig
.
KubernetesVersion
,
BaseImage
)
if
err
!=
nil
{
glog
.
Infof
(
"Unable to create preloaded images volume: %v"
,
err
)
}
glog
.
Infof
(
"Finished creating preloaded images volume in %d seconds"
,
time
.
Since
(
t
)
.
Seconds
())
params
.
PreloadedVolume
=
volumeName
fmt
.
Println
(
"Setting params.preloadedvolume = "
,
volumeName
)
err
=
oci
.
CreateContainerNode
(
params
)
...
...
pkg/drivers/kic/oci/volumes.go
浏览文件 @
b0f685c0
...
...
@@ -21,12 +21,11 @@ import (
"bytes"
"fmt"
"os/exec"
"path"
"strings"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/
minikube/localpath
"
"k8s.io/minikube/pkg/
drivers/kic/preload
"
)
// DeleteAllVolumesByLabel deletes all volumes that have a specific label
...
...
@@ -91,7 +90,7 @@ func allVolumesByLabel(ociBin string, label string) ([]string, error) {
}
// CreatePreloadedImagesVolume creates a volume with preloaded images
func
CreatePreloadedImagesVolume
(
k8sVersion
string
)
(
string
,
error
)
{
func
CreatePreloadedImagesVolume
(
k8sVersion
,
baseImage
string
)
(
string
,
error
)
{
if
err
:=
PointToHostDockerDaemon
();
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"point host docker-daemon"
)
}
...
...
@@ -102,10 +101,9 @@ func CreatePreloadedImagesVolume(k8sVersion string) (string, error) {
if
err
:=
createDockerVolume
(
volumeName
);
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"creating docker volume"
)
}
targetDir
:=
localpath
.
MakeMiniPath
(
"cache"
,
"preloaded-tarball"
)
tarballPath
:=
path
.
Join
(
targetDir
,
fmt
.
Sprintf
(
"%s.tar"
,
k8sVersion
))
tarballPath
:=
preload
.
TarballPath
(
k8sVersion
)
if
err
:=
extractTarballToVolume
(
tarballPath
,
volumeName
);
err
!=
nil
{
if
err
:=
extractTarballToVolume
(
tarballPath
,
volumeName
,
baseImage
);
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"extracting tarball to volume"
)
}
return
volumeName
,
nil
...
...
@@ -129,11 +127,11 @@ func dockerVolumeExists(name string) bool {
return
false
}
func
extractTarballToVolume
(
tarballPath
,
volumeName
string
)
error
{
func
extractTarballToVolume
(
tarballPath
,
volumeName
,
imageName
string
)
error
{
if
err
:=
PointToHostDockerDaemon
();
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"point host docker-daemon"
)
}
cmd
:=
exec
.
Command
(
Docker
,
"run"
,
"--rm"
,
"-
v"
,
fmt
.
Sprintf
(
"%s:/preloaded.tar:ro"
,
tarballPath
),
"-v"
,
fmt
.
Sprintf
(
"%s:/extractDir"
,
volumeName
),
"busybox"
,
"tar"
,
"
xvf"
,
"/preloaded.tar"
,
"-C"
,
"/extractDir"
)
cmd
:=
exec
.
Command
(
Docker
,
"run"
,
"--rm"
,
"-
-entrypoint"
,
"/bin/bash"
,
"-v"
,
fmt
.
Sprintf
(
"%s:/preloaded.tar:ro"
,
tarballPath
),
"-v"
,
fmt
.
Sprintf
(
"%s:/extractDir"
,
volumeName
),
imageName
,
"tar"
,
"-I"
,
"lz4"
,
"-
xvf"
,
"/preloaded.tar"
,
"-C"
,
"/extractDir"
)
fmt
.
Println
(
cmd
.
Args
)
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"output %s"
,
string
(
out
))
...
...
pkg/drivers/kic/
cache
.go
→
pkg/drivers/kic/
preload/preload
.go
浏览文件 @
b0f685c0
/*
Copyright 20
19
The Kubernetes Authors All rights reserved.
Copyright 20
20
The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
...
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
kic
package
preload
import
(
"fmt"
...
...
@@ -26,17 +26,23 @@ import (
"k8s.io/minikube/pkg/minikube/localpath"
)
//
CachePreloadedTarball caches the preloaded images tarball on the host machine
func
CachePreloadedTarball
(
k8sVersion
string
)
error
{
//
TarballPath returns the path to the preloaded tarball
func
TarballPath
(
k8sVersion
string
)
string
{
targetDir
:=
localpath
.
MakeMiniPath
(
"cache"
,
"preloaded-tarball"
)
targetFilepath
:=
path
.
Join
(
targetDir
,
fmt
.
Sprintf
(
"%s.tar"
,
k8sVersion
))
targetFilepath
:=
path
.
Join
(
targetDir
,
fmt
.
Sprintf
(
"preloaded-images-k8s-%s.tar.lz4"
,
k8sVersion
))
return
targetFilepath
}
// CacheTarball caches the preloaded images tarball on the host machine
func
CacheTarball
(
k8sVersion
string
)
error
{
targetFilepath
:=
TarballPath
(
k8sVersion
)
if
_
,
err
:=
os
.
Stat
(
targetFilepath
);
err
==
nil
{
glog
.
Infof
(
"Found %s in cache, skipping downloading"
,
targetFilepath
)
return
nil
}
url
:=
fmt
.
Sprintf
(
"https://storage.googleapis.com/minikube-docker-volume-tarballs/
%s-k8s-%s.tar"
,
Version
,
k8sVersion
)
url
:=
fmt
.
Sprintf
(
"https://storage.googleapis.com/minikube-docker-volume-tarballs/
preloaded-images-k8s-%s.tar"
,
k8sVersion
)
glog
.
Infof
(
"Downloading %s to %s"
,
url
,
targetFilepath
)
return
download
.
ToFile
(
url
,
targetFilepath
,
download
.
FileOptions
{
Mkdirs
:
download
.
MkdirAll
})
}
pkg/minikube/node/cache.go
浏览文件 @
b0f685c0
...
...
@@ -25,6 +25,7 @@ import (
"golang.org/x/sync/errgroup"
cmdcfg
"k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/drivers/kic"
"k8s.io/minikube/pkg/drivers/kic/preload"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
...
...
@@ -51,17 +52,17 @@ func handleDownloadOnly(cacheGroup *errgroup.Group, k8sVersion, driverName strin
if
!
viper
.
GetBool
(
"download-only"
)
{
return
}
var
kicArtifactsGroup
errgroup
.
Group
if
driver
.
IsKIC
(
driverName
)
{
// for kic we need to find what port docker/podman chose for us
// Download kic base image and preloaded images tarball
beginDownloadKicArtifacts
(
&
kicArtifactsGroup
,
k8sVersion
)
}
if
err
:=
doCacheBinaries
(
k8sVersion
);
err
!=
nil
{
exit
.
WithError
(
"Failed to cache binaries"
,
err
)
}
if
_
,
err
:=
CacheKubectlBinary
(
k8sVersion
);
err
!=
nil
{
exit
.
WithError
(
"Failed to cache kubectl"
,
err
)
}
var
kicArtifactsGroup
errgroup
.
Group
if
driver
.
IsKIC
(
driverName
)
{
// for kic we need to find what port docker/podman chose for us
// Download kic base image and preloaded images tarball
beginDownloadKicArtifacts
(
&
kicArtifactsGroup
,
k8sVersion
)
}
waitCacheRequiredImages
(
cacheGroup
)
waitDownloadKicArtifacts
(
&
kicArtifactsGroup
)
if
err
:=
saveImagesToTarFromConfig
();
err
!=
nil
{
...
...
@@ -96,7 +97,7 @@ func beginDownloadKicArtifacts(g *errgroup.Group, k8sVersion string) {
g
.
Go
(
func
()
error
{
glog
.
Info
(
"Caching tarball of preloaded images"
)
return
kic
.
CachePreloaded
Tarball
(
k8sVersion
)
return
preload
.
Cache
Tarball
(
k8sVersion
)
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录