Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
b5b5b331
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,发现更多精彩内容 >>
提交
b5b5b331
编写于
5月 13, 2016
作者:
D
Dan Gillespie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
working kubeconfig setup
上级
ff7cb9ae
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
11 deletion
+78
-11
cmd/minikube/cmd/start.go
cmd/minikube/cmd/start.go
+62
-5
pkg/minikube/constants/constants.go
pkg/minikube/constants/constants.go
+7
-0
pkg/minikube/kubeconfig/config.go
pkg/minikube/kubeconfig/config.go
+7
-4
pkg/minikube/kubeconfig/config_test.go
pkg/minikube/kubeconfig/config_test.go
+2
-2
未找到文件。
cmd/minikube/cmd/start.go
浏览文件 @
b5b5b331
...
...
@@ -24,8 +24,10 @@ import (
"github.com/docker/machine/libmachine"
"github.com/spf13/cobra"
cfg
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/kubeconfig"
)
// startCmd represents the start command
...
...
@@ -68,11 +70,20 @@ func runStart(cmd *cobra.Command, args []string) {
kubeHost
=
strings
.
Replace
(
kubeHost
,
"tcp://"
,
"https://"
,
-
1
)
kubeHost
=
strings
.
Replace
(
kubeHost
,
":2376"
,
":443"
,
-
1
)
fmt
.
Printf
(
"Kubernetes is available at %s.
\n
"
,
kubeHost
)
fmt
.
Println
(
"Run this command to use the cluster: "
)
fmt
.
Printf
(
"kubectl config set-cluster minikube --server=%s --certificate-authority=$HOME/.minikube/apiserver.crt
\n
"
,
kubeHost
)
fmt
.
Println
(
"kubectl config set-credentials minikube --client-certificate=$HOME/.minikube/apiserver.crt --client-key=$HOME/.minikube/apiserver.key"
)
fmt
.
Println
(
"kubectl config set-context minikube --cluster=minikube --user=minikube"
)
fmt
.
Println
(
"kubectl config use-context minikube"
)
// setup kubeconfig
name
:=
constants
.
MinikubeContext
certAuth
:=
constants
.
MakeMiniPath
(
"apiserver.crt"
)
clientCert
:=
constants
.
MakeMiniPath
(
"apiserver.crt"
)
clientKey
:=
constants
.
MakeMiniPath
(
"apiserver.key"
)
active
,
err
:=
setupKubeconfig
(
name
,
kubeHost
,
certAuth
,
clientCert
,
clientKey
)
if
err
!=
nil
{
log
.
Println
(
"Error setting up kubeconfig: "
,
err
)
os
.
Exit
(
1
)
}
else
if
!
active
{
fmt
.
Println
(
"Run this command to use the cluster: "
)
fmt
.
Printf
(
"kubectl config use-context %s
\n
"
,
name
)
}
if
err
:=
cluster
.
GetCreds
(
host
);
err
!=
nil
{
log
.
Println
(
"Error configuring authentication: "
,
err
)
...
...
@@ -80,6 +91,52 @@ func runStart(cmd *cobra.Command, args []string) {
}
}
// setupKubeconfig reads config from disk, adds the minikube settings and writes it back.
// activeContext is true when minikube is the CurrentContext
// If no CurrentContext is set, the given name will be used.
func
setupKubeconfig
(
name
,
server
,
certAuth
,
cliCert
,
cliKey
string
)
(
activeContext
bool
,
err
error
)
{
configFile
:=
constants
.
KubeconfigPath
// read existing config or create new if does not exist
config
,
err
:=
kubeconfig
.
ReadConfigOrNew
(
configFile
)
if
err
!=
nil
{
return
false
,
err
}
clusterName
:=
name
cluster
:=
cfg
.
NewCluster
()
cluster
.
Server
=
server
cluster
.
CertificateAuthority
=
certAuth
config
.
Clusters
[
clusterName
]
=
cluster
// user
userName
:=
name
user
:=
cfg
.
NewAuthInfo
()
user
.
ClientCertificate
=
cliCert
user
.
ClientKey
=
cliKey
config
.
AuthInfos
[
userName
]
=
user
// context
contextName
:=
name
context
:=
cfg
.
NewContext
()
context
.
Cluster
=
clusterName
context
.
AuthInfo
=
userName
config
.
Contexts
[
contextName
]
=
context
// set current context to minikube if unset
if
len
(
config
.
CurrentContext
)
==
0
{
config
.
CurrentContext
=
contextName
}
// write back to disk
if
err
:=
kubeconfig
.
WriteConfig
(
config
,
configFile
);
err
!=
nil
{
return
false
,
err
}
// activeContext if current matches name
return
name
==
config
.
CurrentContext
,
nil
}
func
init
()
{
startCmd
.
Flags
()
.
StringVarP
(
&
localkubeURL
,
"localkube-url"
,
""
,
"https://storage.googleapis.com/tinykube/localkube"
,
"Location of the localkube binary"
)
startCmd
.
Flags
()
.
MarkHidden
(
"localkube-url"
)
...
...
pkg/minikube/constants/constants.go
浏览文件 @
b5b5b331
...
...
@@ -27,6 +27,13 @@ const MachineName = "minikubeVM"
// Fix for windows
var
Minipath
=
filepath
.
Join
(
os
.
Getenv
(
"HOME"
),
".minikube"
)
// TODO: Fix for windows
// KubeconfigPath is the path to the Kubernetes client config
var
KubeconfigPath
=
filepath
.
Join
(
os
.
Getenv
(
"HOME"
),
".kube"
,
"config"
)
// MinikubeContext is the kubeconfig context name used for minikube
const
MinikubeContext
=
"minikube"
// MakeMiniPath is a utility to calculate a relative path to our directory.
func
MakeMiniPath
(
fileName
string
)
string
{
return
filepath
.
Join
(
Minipath
,
fileName
)
...
...
pkg/minikube/kubeconfig/config.go
浏览文件 @
b5b5b331
...
...
@@ -11,11 +11,14 @@ import (
"k8s.io/kubernetes/pkg/runtime"
)
// ReadConfig retrieves Kubernetes client configuration from a file.
func
ReadConfig
(
filename
string
)
(
*
api
.
Config
,
error
)
{
// ReadConfigOrNew retrieves Kubernetes client configuration from a file.
// If no files exists, an empty configuration is returned.
func
ReadConfigOrNew
(
filename
string
)
(
*
api
.
Config
,
error
)
{
data
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not read config: %v"
,
err
)
if
os
.
IsNotExist
(
err
)
{
return
api
.
NewConfig
(),
nil
}
else
if
err
!=
nil
{
return
nil
,
err
}
// decode config, empty if no bytes
...
...
pkg/minikube/kubeconfig/config_test.go
浏览文件 @
b5b5b331
...
...
@@ -13,7 +13,7 @@ func TestEmptyConfig(t *testing.T) {
tmp
:=
tempFile
(
t
,
[]
byte
{})
defer
os
.
Remove
(
tmp
)
cfg
,
err
:=
ReadConfig
(
tmp
)
cfg
,
err
:=
ReadConfig
OrNew
(
tmp
)
if
err
!=
nil
{
t
.
Fatalf
(
"could not read config: %v"
,
err
)
}
...
...
@@ -48,7 +48,7 @@ func TestNewConfig(t *testing.T) {
t
.
Fatal
(
err
)
}
actual
,
err
:=
ReadConfig
(
filename
)
actual
,
err
:=
ReadConfig
OrNew
(
filename
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录