Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
4fe9ca5f
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,发现更多精彩内容 >>
提交
4fe9ca5f
编写于
2月 19, 2020
作者:
M
Medya Gh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
break done delete and prune into two funcs better error handling
上级
e1ffa5fb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
20 deletion
+49
-20
cmd/minikube/cmd/delete.go
cmd/minikube/cmd/delete.go
+16
-4
pkg/drivers/kic/oci/oci.go
pkg/drivers/kic/oci/oci.go
+7
-5
pkg/drivers/kic/oci/volumes.go
pkg/drivers/kic/oci/volumes.go
+26
-11
未找到文件。
cmd/minikube/cmd/delete.go
浏览文件 @
4fe9ca5f
...
...
@@ -118,11 +118,17 @@ func runDelete(cmd *cobra.Command, args []string) {
if
errs
!=
nil
&&
len
(
errs
)
>
0
{
// it will error if there is no container to delete
glog
.
Infof
(
"error delete containers by label %q (might be okay): %+v"
,
delLabel
,
err
)
}
errs
=
oci
.
DeleteAllVolumesByLabel
(
oci
.
Docker
,
delLabel
)
if
errs
!=
nil
&&
len
(
errs
)
>
0
{
// it will not error if there is nothing to delete
glog
.
Warningf
(
"error delete volumes by label %q (might be okay): %+v"
,
delLabel
,
errs
)
}
errs
=
oci
.
PruneAllVolumesByLabel
(
oci
.
Docker
,
delLabel
)
if
errs
!=
nil
&&
len
(
errs
)
>
0
{
// it will not error if there is nothing to delete
glog
.
Warningf
(
"error pruning volumes by label %q (might be okay): %+v"
,
delLabel
,
errs
)
}
errs
=
DeleteProfiles
(
profilesToDelete
)
if
len
(
errs
)
>
0
{
HandleDeletionErrors
(
errs
)
...
...
@@ -185,13 +191,19 @@ func DeleteProfiles(profiles []*pkg_config.Profile) []error {
func
deleteProfile
(
profile
*
pkg_config
.
Profile
)
error
{
viper
.
Set
(
pkg_config
.
MachineProfile
,
profile
.
Name
)
errs
:=
oci
.
DeleteAllContainersByLabel
(
oci
.
Docker
,
fmt
.
Sprintf
(
"%s=%s"
,
oci
.
ProfileLabelKey
,
profile
.
Name
))
delLabel
:=
fmt
.
Sprintf
(
"%s=%s"
,
oci
.
ProfileLabelKey
,
profile
.
Name
)
errs
:=
oci
.
DeleteAllContainersByLabel
(
oci
.
Docker
,
delLabel
)
if
errs
!=
nil
{
// it will error if there is no container to delete
glog
.
Infof
(
"
no left over kic container for %s found to delete. %+
v"
,
profile
.
Name
,
errs
)
glog
.
Infof
(
"
error deleting containers (might be okay):
\n
%
v"
,
profile
.
Name
,
errs
)
}
errs
=
oci
.
DeleteAllVolumesByLabel
(
oci
.
Docker
,
fmt
.
Sprintf
(
"%s=%s"
,
oci
.
ProfileLabelKey
,
profile
.
Name
)
)
errs
=
oci
.
DeleteAllVolumesByLabel
(
oci
.
Docker
,
delLabel
)
if
errs
!=
nil
{
// it will not error if there is nothing to delete
glog
.
Warningf
(
"error deleting left docker volumes. To see the list of volumes run: 'docker volume ls'
\n
:%+v"
,
errs
)
glog
.
Warningf
(
"error deleting volumes (might be okay).
\n
To see the list of volumes run: 'docker volume ls'
\n
:%v"
,
errs
)
}
errs
=
oci
.
PruneAllVolumesByLabel
(
oci
.
Docker
,
delLabel
)
if
errs
!=
nil
&&
len
(
errs
)
>
0
{
// it will not error if there is nothing to delete
glog
.
Warningf
(
"error pruning volume (might be okay):
\n
%v"
,
delLabel
,
errs
)
}
api
,
err
:=
machine
.
NewAPIClient
()
...
...
pkg/drivers/kic/oci/oci.go
浏览文件 @
4fe9ca5f
...
...
@@ -35,7 +35,7 @@ import (
)
// DeleteAllContainersByLabel deletes all containers that have a specific label
// if there
are no containers found with the
label, it will return nil
// if there
no containers found with the given
label, it will return nil
func
DeleteAllContainersByLabel
(
ociBin
string
,
label
string
)
[]
error
{
var
deleteErrs
[]
error
if
ociBin
==
Docker
{
...
...
@@ -431,13 +431,15 @@ func listContainersByLabel(ociBinary string, label string) ([]string, error) {
}
cmd
:=
exec
.
Command
(
ociBinary
,
"ps"
,
"-a"
,
"--filter"
,
fmt
.
Sprintf
(
"label=%s"
,
label
),
"--format"
,
"{{.Names}}"
)
stdout
,
err
:=
cmd
.
Output
()
outs
:=
strings
.
Split
(
strings
.
Replace
(
string
(
stdout
),
"
\r
"
,
""
,
-
1
),
"
\n
"
)
s
:=
bufio
.
NewScanner
(
bytes
.
NewReader
(
stdout
)
)
var
names
[]
string
for
_
,
o
:=
range
outs
{
if
strings
.
TrimSpace
(
o
)
!=
""
{
names
=
append
(
names
,
strings
.
TrimSpace
(
o
))
for
s
.
Scan
()
{
n
:=
strings
.
TrimSpace
(
s
.
Text
())
if
n
!=
""
{
names
=
append
(
names
,
n
)
}
}
return
names
,
err
}
...
...
pkg/drivers/kic/oci/volumes.go
浏览文件 @
4fe9ca5f
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
oci
import
(
"bufio"
"bytes"
"fmt"
"os/exec"
"strings"
...
...
@@ -27,10 +29,9 @@ import (
// DeleteAllVolumesByLabel deletes all volumes that have a specific label
// if there is no volume to delete it will return nil
// example: docker volume prune -f --filter label=name.minikube.sigs.k8s.io=minikube
func
DeleteAllVolumesByLabel
(
ociBin
string
,
label
string
)
[]
error
{
var
deleteErrs
[]
error
glog
.
Infof
(
"trying to
prun
e all %s volumes with label %s"
,
ociBin
,
label
)
glog
.
Infof
(
"trying to
delet
e all %s volumes with label %s"
,
ociBin
,
label
)
if
ociBin
==
Docker
{
if
err
:=
PointToHostDockerDaemon
();
err
!=
nil
{
return
[]
error
{
errors
.
Wrap
(
err
,
"point host docker-daemon"
)}
...
...
@@ -39,20 +40,34 @@ func DeleteAllVolumesByLabel(ociBin string, label string) []error {
vs
,
err
:=
allVolumesByLabel
(
ociBin
,
label
)
if
err
!=
nil
{
glog
.
Infof
(
"error listing volumes by label %q: %v"
,
label
,
err
)
return
[]
error
{
fmt
.
Errorf
(
"listing volumes by label %q: %v"
,
label
,
err
)}
}
for
_
,
v
:=
range
vs
{
cmd
:=
exec
.
Command
(
ociBin
,
"volume"
,
"rm"
,
"--force"
,
v
)
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
glog
.
Infof
(
"error deleting volume %s: output: %s"
,
v
,
string
(
out
))
deleteErrs
=
append
(
deleteErrs
,
err
)
deleteErrs
=
append
(
deleteErrs
,
fmt
.
Errorf
(
"deleting volume %s: output: %s"
,
v
,
string
(
out
)))
}
}
return
deleteErrs
}
// PruneAllVolumesByLabel deletes all volumes that have a specific label
// if there is no volume to delete it will return nil
// example: docker volume prune -f --filter label=name.minikube.sigs.k8s.io=minikube
func
PruneAllVolumesByLabel
(
ociBin
string
,
label
string
)
[]
error
{
var
deleteErrs
[]
error
glog
.
Infof
(
"trying to prune all %s volumes with label %s"
,
ociBin
,
label
)
if
ociBin
==
Docker
{
if
err
:=
PointToHostDockerDaemon
();
err
!=
nil
{
return
[]
error
{
errors
.
Wrap
(
err
,
"point host docker-daemon"
)}
}
}
// try to prune afterwards just in case delete didn't go through
cmd
:=
exec
.
Command
(
ociBin
,
"volume"
,
"prune"
,
"-f"
,
"--filter"
,
"label="
+
label
)
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
deleteErrs
=
append
(
deleteErrs
,
errors
.
Wrapf
(
err
,
"prune volume
%s"
,
string
(
out
)))
deleteErrs
=
append
(
deleteErrs
,
errors
.
Wrapf
(
err
,
"prune volume
by label %s: %s"
,
label
,
string
(
out
)))
}
return
deleteErrs
}
...
...
@@ -62,13 +77,13 @@ func DeleteAllVolumesByLabel(ociBin string, label string) []error {
func
allVolumesByLabel
(
ociBin
string
,
label
string
)
([]
string
,
error
)
{
cmd
:=
exec
.
Command
(
ociBin
,
"volume"
,
"ls"
,
"--filter"
,
"label="
+
label
,
"--format"
,
"{{.Name}}"
)
stdout
,
err
:=
cmd
.
Output
()
outs
:=
strings
.
Split
(
strings
.
Replace
(
string
(
stdout
),
"
\r
"
,
""
,
-
1
),
"
\n
"
)
s
:=
bufio
.
NewScanner
(
bytes
.
NewReader
(
stdout
)
)
var
vols
[]
string
for
_
,
o
:=
range
outs
{
if
strings
.
TrimSpace
(
o
)
!=
""
{
vols
=
append
(
vols
,
strings
.
TrimSpace
(
o
))
for
s
.
Scan
()
{
v
:=
strings
.
TrimSpace
(
s
.
Text
())
if
v
!=
""
{
vols
=
append
(
vols
,
v
)
}
}
return
vols
,
err
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录