Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
9b964853
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,发现更多精彩内容 >>
未验证
提交
9b964853
编写于
11月 13, 2020
作者:
M
Medya Ghazizadeh
提交者:
GitHub
11月 13, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9672 from sadlil/driver-alias
Add Support for driver name alias
上级
a0af6ae2
d6c0256b
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
72 addition
and
4 deletion
+72
-4
cmd/minikube/cmd/start.go
cmd/minikube/cmd/start.go
+6
-0
pkg/minikube/driver/driver.go
pkg/minikube/driver/driver.go
+14
-0
pkg/minikube/registry/drvs/kvm2/kvm2.go
pkg/minikube/registry/drvs/kvm2/kvm2.go
+1
-0
pkg/minikube/registry/registry.go
pkg/minikube/registry/registry.go
+23
-4
pkg/minikube/registry/registry_test.go
pkg/minikube/registry/registry_test.go
+28
-0
未找到文件。
cmd/minikube/cmd/start.go
浏览文件 @
9b964853
...
...
@@ -660,6 +660,12 @@ func validateSpecifiedDriver(existing *config.ClusterConfig) {
return
}
// hostDriver always returns original driver name even if an alias is used to start minikube.
// For all next start with alias needs to be check against the host driver aliases.
if
driver
.
IsAlias
(
old
,
requested
)
{
return
}
exit
.
Advice
(
reason
.
GuestDrvMismatch
,
`The existing "{{.name}}" cluster was created using the "{{.old}}" driver, which is incompatible with requested "{{.new}}" driver.`
,
...
...
pkg/minikube/driver/driver.go
浏览文件 @
9b964853
...
...
@@ -53,6 +53,9 @@ const (
HyperV
=
"hyperv"
// Parallels driver
Parallels
=
"parallels"
// AliasKVM is driver name alias for kvm2
AliasKVM
=
"kvm"
)
var
(
...
...
@@ -283,6 +286,17 @@ func Status(name string) registry.DriverState {
}
}
// IsAlias checks if an alias belongs to provided driver by name.
func
IsAlias
(
name
,
alias
string
)
bool
{
d
:=
registry
.
Driver
(
name
)
for
_
,
da
:=
range
d
.
Alias
{
if
da
==
alias
{
return
true
}
}
return
false
}
// SetLibvirtURI sets the URI to perform libvirt health checks against
func
SetLibvirtURI
(
v
string
)
{
klog
.
Infof
(
"Setting default libvirt URI to %s"
,
v
)
...
...
pkg/minikube/registry/drvs/kvm2/kvm2.go
浏览文件 @
9b964853
...
...
@@ -43,6 +43,7 @@ const (
func
init
()
{
if
err
:=
registry
.
Register
(
registry
.
DriverDef
{
Name
:
driver
.
KVM2
,
Alias
:
[]
string
{
driver
.
AliasKVM
},
Config
:
configure
,
Status
:
status
,
Priority
:
registry
.
Preferred
,
...
...
pkg/minikube/registry/registry.go
浏览文件 @
9b964853
...
...
@@ -86,6 +86,9 @@ type DriverDef struct {
// Name of the machine driver. It has to be unique.
Name
string
// Alias contains a list of machine driver aliases. Each alias should also be unique.
Alias
[]
string
// Config is a function that emits a configured driver struct
Config
Configurator
...
...
@@ -110,12 +113,14 @@ func (d DriverDef) String() string {
type
driverRegistry
struct
{
drivers
map
[
string
]
DriverDef
driversByAlias
map
[
string
]
DriverDef
lock
sync
.
RWMutex
}
func
newRegistry
()
*
driverRegistry
{
return
&
driverRegistry
{
drivers
:
make
(
map
[
string
]
DriverDef
),
driversByAlias
:
make
(
map
[
string
]
DriverDef
),
}
}
...
...
@@ -129,6 +134,13 @@ func (r *driverRegistry) Register(def DriverDef) error {
}
r
.
drivers
[
def
.
Name
]
=
def
for
_
,
alias
:=
range
def
.
Alias
{
if
_
,
ok
:=
r
.
driversByAlias
[
alias
];
ok
{
return
fmt
.
Errorf
(
"alias %q is already registered: %+v"
,
alias
,
def
)
}
r
.
driversByAlias
[
alias
]
=
def
}
return
nil
}
...
...
@@ -150,5 +162,12 @@ func (r *driverRegistry) List() []DriverDef {
func
(
r
*
driverRegistry
)
Driver
(
name
string
)
DriverDef
{
r
.
lock
.
RLock
()
defer
r
.
lock
.
RUnlock
()
return
r
.
drivers
[
name
]
def
,
ok
:=
r
.
drivers
[
name
]
if
ok
{
return
def
}
// Check if we have driver def with name as alias
return
r
.
driversByAlias
[
name
]
}
pkg/minikube/registry/registry_test.go
浏览文件 @
9b964853
...
...
@@ -63,3 +63,31 @@ func TestList(t *testing.T) {
t
.
Errorf
(
"list mismatch (-want +got):
\n
%s"
,
diff
)
}
}
func
TestDriverAlias
(
t
*
testing
.
T
)
{
foo
:=
DriverDef
{
Name
:
"foo"
,
Alias
:
[]
string
{
"foo-alias"
}}
r
:=
newRegistry
()
if
err
:=
r
.
Register
(
foo
);
err
!=
nil
{
t
.
Errorf
(
"Register = %v, expected nil"
,
err
)
}
d
:=
r
.
Driver
(
"foo"
)
if
d
.
Empty
()
{
t
.
Errorf
(
"driver.Empty = true, expected false"
)
}
d
=
r
.
Driver
(
"foo-alias"
)
if
d
.
Empty
()
{
t
.
Errorf
(
"driver.Empty = true, expected false"
)
}
if
diff
:=
cmp
.
Diff
(
r
.
List
(),
[]
DriverDef
{
foo
});
diff
!=
""
{
t
.
Errorf
(
"list mismatch (-want +got):
\n
%s"
,
diff
)
}
d
=
r
.
Driver
(
"bar"
)
if
!
d
.
Empty
()
{
t
.
Errorf
(
"driver.Empty = false, expected true"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录