Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
f022babe
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,体验更适合开发者的 AI 搜索 >>
提交
f022babe
编写于
3月 26, 2021
作者:
T
Tharun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refractored image command removeImages function
Signed-off-by:
N
Tharun
<
rajendrantharun@live.com
>
上级
e37f8bc1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
45 deletion
+36
-45
cmd/minikube/cmd/image.go
cmd/minikube/cmd/image.go
+2
-4
pkg/minikube/machine/cache_images.go
pkg/minikube/machine/cache_images.go
+34
-41
未找到文件。
cmd/minikube/cmd/image.go
浏览文件 @
f022babe
...
...
@@ -132,16 +132,14 @@ $ minikube image rm image busybox
$ minikube image unload image busybox
`
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Aliases
:
[]
string
{
"unload"
},
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
len
(
args
)
==
0
{
exit
.
Message
(
reason
.
Usage
,
"Please provide an image to remove via <minikube image rm IMAGE_NAME>"
)
}
profile
,
err
:=
config
.
LoadProfile
(
viper
.
GetString
(
config
.
ProfileName
))
if
err
!=
nil
{
exit
.
Error
(
reason
.
Usage
,
"loading profile"
,
err
)
}
if
err
:=
machine
.
RemoveImages
(
args
,
[]
*
config
.
Profile
{
profile
}
);
err
!=
nil
{
if
err
:=
machine
.
RemoveImages
(
args
,
profile
);
err
!=
nil
{
exit
.
Error
(
reason
.
GuestImageRemove
,
"Failed to remove image"
,
err
)
}
},
...
...
pkg/minikube/machine/cache_images.go
浏览文件 @
f022babe
...
...
@@ -294,12 +294,7 @@ func transferAndLoadImage(cr command.Runner, k8s config.KubernetesConfig, src st
}
// removeImages removes images from the container run time
func
removeImages
(
cc
*
config
.
ClusterConfig
,
runner
command
.
Runner
,
images
[]
string
)
error
{
cr
,
err
:=
cruntime
.
New
(
cruntime
.
Config
{
Type
:
cc
.
KubernetesConfig
.
ContainerRuntime
,
Runner
:
runner
})
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"runtime"
)
}
func
removeImages
(
cruntime
cruntime
.
Manager
,
images
[]
string
)
error
{
klog
.
Infof
(
"RemovingImages start: %s"
,
images
)
start
:=
time
.
Now
()
...
...
@@ -312,66 +307,64 @@ func removeImages(cc *config.ClusterConfig, runner command.Runner, images []stri
for
_
,
image
:=
range
images
{
image
:=
image
g
.
Go
(
func
()
error
{
return
cr
.
RemoveImage
(
image
)
return
cr
untime
.
RemoveImage
(
image
)
})
}
if
err
:=
g
.
Wait
();
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"removing images"
)
return
errors
.
Wrap
(
err
,
"
error
removing images"
)
}
klog
.
Infoln
(
"Successfully removed images"
)
return
nil
}
func
RemoveImages
(
images
[]
string
,
profile
s
[]
*
config
.
Profile
)
error
{
func
RemoveImages
(
images
[]
string
,
profile
*
config
.
Profile
)
error
{
api
,
err
:=
NewAPIClient
()
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"
api
"
)
return
errors
.
Wrap
(
err
,
"
error creating api client
"
)
}
defer
api
.
Close
()
succeeded
:=
[]
string
{}
failed
:=
[]
string
{}
for
_
,
p
:=
range
profiles
{
// loading images to all running profiles
pName
:=
p
.
Name
// capture the loop variable
pName
:=
profile
.
Name
c
,
err
:=
config
.
Load
(
pName
)
c
,
err
:=
config
.
Load
(
pName
)
if
err
!=
nil
{
klog
.
Errorf
(
"Failed to load profile %q: %v"
,
pName
,
err
)
return
errors
.
Wrapf
(
err
,
"error loading config for profile :%v"
,
pName
)
}
for
_
,
n
:=
range
c
.
Nodes
{
m
:=
config
.
MachineName
(
*
c
,
n
)
status
,
err
:=
Status
(
api
,
m
)
if
err
!=
nil
{
// Non-fatal because it may race with profile deletion
klog
.
Errorf
(
"Failed to load profile %q: %v"
,
pName
,
err
)
failed
=
append
(
failed
,
pName
)
klog
.
Warningf
(
"error getting status for %s: %v"
,
m
,
err
)
continue
}
for
_
,
n
:=
range
c
.
Nodes
{
m
:=
config
.
MachineName
(
*
c
,
n
)
status
,
err
:=
Status
(
api
,
m
)
if
status
==
state
.
Running
.
String
()
{
h
,
err
:=
api
.
Load
(
m
)
if
err
!=
nil
{
klog
.
Warningf
(
"error getting status for %s: %v"
,
m
,
err
)
failed
=
append
(
failed
,
m
)
klog
.
Warningf
(
"Failed to load machine %q: %v"
,
m
,
err
)
continue
}
if
status
==
state
.
Running
.
String
()
{
// the not running hosts will load on next start
h
,
err
:=
api
.
Load
(
m
)
if
err
!=
nil
{
klog
.
Warningf
(
"Failed to load machine %q: %v"
,
m
,
err
)
failed
=
append
(
failed
,
m
)
continue
}
cr
,
err
:=
CommandRunner
(
h
)
if
err
!=
nil
{
return
err
}
err
=
removeImages
(
c
,
cr
,
images
)
if
err
!=
nil
{
failed
=
append
(
failed
,
m
)
klog
.
Warningf
(
"Failed to remove images for profile %s. make sure the profile is running. %v"
,
pName
,
err
)
continue
}
succeeded
=
append
(
succeeded
,
m
)
runner
,
err
:=
CommandRunner
(
h
)
if
err
!=
nil
{
return
err
}
cruntime
,
err
:=
cruntime
.
New
(
cruntime
.
Config
{
Type
:
c
.
KubernetesConfig
.
ContainerRuntime
,
Runner
:
runner
})
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"error creating container runtime"
)
}
err
=
removeImages
(
cruntime
,
images
)
if
err
!=
nil
{
failed
=
append
(
failed
,
m
)
klog
.
Warningf
(
"Failed to remove images for profile %s %v"
,
pName
,
err
.
Error
())
continue
}
succeeded
=
append
(
succeeded
,
m
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录