Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
3477e4bd
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 搜索 >>
提交
3477e4bd
编写于
11月 15, 2017
作者:
P
Priya Wadhwa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add cache flag to minikube
上级
10f2bb57
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
213 addition
and
0 deletion
+213
-0
cmd/minikube/cmd/cache.go
cmd/minikube/cmd/cache.go
+116
-0
cmd/minikube/cmd/config/config.go
cmd/minikube/cmd/config/config.go
+71
-0
cmd/minikube/cmd/config/util.go
cmd/minikube/cmd/config/util.go
+5
-0
pkg/minikube/machine/cache_images.go
pkg/minikube/machine/cache_images.go
+21
-0
未找到文件。
cmd/minikube/cmd/cache.go
0 → 100644
浏览文件 @
3477e4bd
/*
Copyright 2017 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
cmd
import
(
"fmt"
"github.com/spf13/cobra"
cmdConfig
"k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/sshutil"
"os"
)
// cacheCmd represents the cache command
var
cacheCmd
=
&
cobra
.
Command
{
Use
:
"cache"
,
Short
:
"Add or delete an image from the local cache."
,
Long
:
"Add or delete an image from the local cache."
,
}
// addCacheCmd represents the cache add command
var
addCacheCmd
=
&
cobra
.
Command
{
Use
:
"add"
,
Short
:
"Add an image to local cache."
,
Long
:
"Add an image to local cache."
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
api
,
err
:=
machine
.
NewAPIClient
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error getting client: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
defer
api
.
Close
()
machine
.
CacheImages
(
args
,
constants
.
ImageCacheDir
)
h
,
err
:=
api
.
Load
(
config
.
GetMachineName
())
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error getting api client: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
client
,
err
:=
sshutil
.
NewSSHClient
(
h
.
Driver
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error getting ssh client: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
cmdRunner
:=
bootstrapper
.
NewSSHRunner
(
client
)
machine
.
LoadImages
(
cmdRunner
,
args
,
constants
.
ImageCacheDir
)
err
=
cmdConfig
.
AddToConfigArray
(
"cache"
,
images
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error adding cached images to config file: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
},
}
// deleteCacheCmd represents the cache delete command
var
deleteCacheCmd
=
&
cobra
.
Command
{
Use
:
"delete"
,
Short
:
"Delete an image from the local cache."
,
Long
:
"Delete an image from the local cache."
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
api
,
err
:=
machine
.
NewAPIClient
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error getting client: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
defer
api
.
Close
()
h
,
err
:=
api
.
Load
(
config
.
GetMachineName
())
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error getting api client: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
client
,
err
:=
sshutil
.
NewSSHClient
(
h
.
Driver
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error getting ssh client: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
cmdRunner
:=
bootstrapper
.
NewSSHRunner
(
client
)
machine
.
DeleteImages
(
cmdRunner
,
args
)
err
=
cmdConfig
.
DeleteFromConfigArray
(
"cache"
,
args
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error deleting images from cache: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
},
}
func
init
()
{
cacheCmd
.
AddCommand
(
addCacheCmd
)
cacheCmd
.
AddCommand
(
deleteCacheCmd
)
RootCmd
.
AddCommand
(
cacheCmd
)
}
cmd/minikube/cmd/config/config.go
浏览文件 @
3477e4bd
...
...
@@ -36,6 +36,7 @@ type setFn func(string, string) error
type
Setting
struct
{
name
string
set
func
(
config
.
MinikubeConfig
,
string
,
string
)
error
setArray
func
(
config
.
MinikubeConfig
,
string
,
[]
string
)
error
validations
[]
setFn
callbacks
[]
setFn
}
...
...
@@ -193,6 +194,10 @@ var settings = []Setting{
name
:
"disable-driver-mounts"
,
set
:
SetBool
,
},
{
name
:
"cache"
,
setArray
:
SetStringArray
,
},
}
var
ConfigCmd
=
&
cobra
.
Command
{
...
...
@@ -213,6 +218,72 @@ func configurableFields() string {
return
strings
.
Join
(
fields
,
"
\n
"
)
}
func
AddToConfigArray
(
name
string
,
images
[]
string
)
error
{
s
,
err
:=
findSetting
(
name
)
if
err
!=
nil
{
return
err
}
// Set the values
configFile
,
err
:=
config
.
ReadConfig
()
if
err
!=
nil
{
return
err
}
values
:=
configFile
[
name
]
if
values
!=
nil
{
for
_
,
v
:=
range
values
.
([]
interface
{})
{
images
=
append
(
images
,
v
.
(
string
))
}
}
err
=
s
.
setArray
(
configFile
,
name
,
images
)
if
err
!=
nil
{
return
err
}
// Write the values
return
WriteConfig
(
configFile
)
}
func
DeleteFromConfigArray
(
name
string
,
images
[]
string
)
error
{
s
,
err
:=
findSetting
(
name
)
if
err
!=
nil
{
return
err
}
// Set the values
configFile
,
err
:=
config
.
ReadConfig
()
if
err
!=
nil
{
return
err
}
values
:=
configFile
[
name
]
var
finalImages
[]
string
if
values
!=
nil
{
for
_
,
v
:=
range
values
.
([]
interface
{})
{
addImage
:=
true
for
_
,
image
:=
range
images
{
if
v
.
(
string
)
==
image
{
addImage
=
false
}
}
if
addImage
{
finalImages
=
append
(
finalImages
,
v
.
(
string
))
}
}
}
err
=
s
.
setArray
(
configFile
,
name
,
finalImages
)
if
err
!=
nil
{
return
err
}
// Write the values
return
WriteConfig
(
configFile
)
}
// WriteConfig writes a minikube config to the JSON file
func
WriteConfig
(
m
config
.
MinikubeConfig
)
error
{
f
,
err
:=
os
.
Create
(
constants
.
ConfigFile
)
...
...
cmd/minikube/cmd/config/util.go
浏览文件 @
3477e4bd
...
...
@@ -60,6 +60,11 @@ func SetString(m config.MinikubeConfig, name string, val string) error {
return
nil
}
func
SetStringArray
(
m
config
.
MinikubeConfig
,
name
string
,
val
[]
string
)
error
{
m
[
name
]
=
val
return
nil
}
func
SetInt
(
m
config
.
MinikubeConfig
,
name
string
,
val
string
)
error
{
i
,
err
:=
strconv
.
Atoi
(
val
)
if
err
!=
nil
{
...
...
pkg/minikube/machine/cache_images.go
浏览文件 @
3477e4bd
...
...
@@ -98,6 +98,27 @@ func LoadImages(cmd bootstrapper.CommandRunner, images []string, cacheDir string
return
nil
}
// DeleteImages deletes images from local daemon
func
DeleteImages
(
cmd
bootstrapper
.
CommandRunner
,
images
[]
string
)
error
{
var
g
errgroup
.
Group
for
_
,
image
:=
range
images
{
image
:=
image
g
.
Go
(
func
()
error
{
dockerDeleteCmd
:=
"docker rmi "
+
image
if
err
:=
cmd
.
Run
(
dockerDeleteCmd
);
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"deleting docker image: %s"
,
image
)
}
return
nil
})
}
if
err
:=
g
.
Wait
();
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"deleting cached images"
)
}
glog
.
Infoln
(
"Successfully deleted cached images."
)
return
nil
}
// # ParseReference cannot have a : in the directory path
func
sanitizeCacheDir
(
image
string
)
string
{
if
runtime
.
GOOS
==
"windows"
&&
hasWindowsDriveLetter
(
image
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录