Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
3f478fa0
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,发现更多精彩内容 >>
提交
3f478fa0
编写于
7月 28, 2016
作者:
A
Aaron Prindle
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Having working minikube service & minikube dashboard wait until ready
functionality using endpoints.
上级
029e4312
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
6 deletion
+87
-6
cmd/minikube/cmd/dashboard.go
cmd/minikube/cmd/dashboard.go
+17
-3
cmd/minikube/cmd/service.go
cmd/minikube/cmd/service.go
+34
-1
pkg/minikube/cluster/cluster.go
pkg/minikube/cluster/cluster.go
+36
-2
未找到文件。
cmd/minikube/cmd/dashboard.go
浏览文件 @
3f478fa0
...
...
@@ -19,13 +19,15 @@ package cmd
import
(
"fmt"
"os"
"time"
"github.com/docker/machine/libmachine"
"github.com/golang/glog"
"github.com/pkg/browser"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
commonutil
"k8s.io/minikube/pkg/util"
)
var
(
...
...
@@ -40,9 +42,20 @@ var dashboardCmd = &cobra.Command{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
api
:=
libmachine
.
NewClient
(
constants
.
Minipath
,
constants
.
MakeMiniPath
(
"certs"
))
defer
api
.
Close
()
url
,
err
:=
cluster
.
GetServiceURL
(
api
,
"kube-system"
,
"kubernetes-dashboard"
)
cluster
.
EnsureMinikubeRunningOrExit
(
api
)
namespace
:=
"kube-system"
service
:=
"kubernetes-dashboard"
if
err
:=
commonutil
.
RetryAfter
(
20
,
func
()
error
{
return
CheckService
(
namespace
,
service
)
},
6
*
time
.
Second
);
err
!=
nil
{
fmt
.
Println
(
"Could not find healthy pod being pointed to by %s: %s"
,
service
,
err
)
os
.
Exit
(
1
)
}
url
,
err
:=
cluster
.
GetServiceURL
(
api
,
namespace
,
service
)
if
err
!=
nil
{
glog
.
Errorln
(
"Error accessing the kubernetes dashboard (is minikube running?): Error: "
,
err
)
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Fprintln
(
os
.
Stderr
,
"Check that minikube is running."
)
os
.
Exit
(
1
)
}
if
dashboardURLMode
{
...
...
@@ -51,6 +64,7 @@ var dashboardCmd = &cobra.Command{
fmt
.
Fprintln
(
os
.
Stdout
,
"Opening kubernetes dashboard in default browser..."
)
browser
.
OpenURL
(
url
)
}
},
}
...
...
cmd/minikube/cmd/service.go
浏览文件 @
3f478fa0
...
...
@@ -19,12 +19,15 @@ package cmd
import
(
"fmt"
"os"
"time"
"github.com/docker/machine/libmachine"
"github.com/pkg/browser"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
commonutil
"k8s.io/minikube/pkg/util"
)
var
(
...
...
@@ -44,9 +47,15 @@ var serviceCmd = &cobra.Command{
}
service
:=
args
[
0
]
api
:=
libmachine
.
NewClient
(
constants
.
Minipath
,
constants
.
MakeMiniPath
(
"certs"
))
defer
api
.
Close
()
cluster
.
EnsureMinikubeRunningOrExit
(
api
)
if
err
:=
commonutil
.
RetryAfter
(
20
,
func
()
error
{
return
CheckService
(
namespace
,
service
)
},
6
*
time
.
Second
);
err
!=
nil
{
fmt
.
Println
(
"Could not find finalized endpoint being pointed to by %s: %s"
,
service
,
err
)
os
.
Exit
(
1
)
}
url
,
err
:=
cluster
.
GetServiceURL
(
api
,
namespace
,
service
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
...
...
@@ -67,3 +76,27 @@ func init() {
serviceCmd
.
Flags
()
.
BoolVar
(
&
serviceURLMode
,
"url"
,
false
,
"Display the kubernetes service URL in the CLI instead of opening it in the default browser"
)
RootCmd
.
AddCommand
(
serviceCmd
)
}
// CheckService waits for the specified service to be ready by returning an error until the service is up
// The check is done by polling the endpoint associated with the service and when the endpoint exists, returning no error->service-online
func
CheckService
(
namespace
string
,
service
string
)
error
{
endpoints
,
err
:=
cluster
.
GetKubernetesEndpointsWithNamespace
(
namespace
)
if
err
!=
nil
{
return
err
}
endpoint
,
err
:=
endpoints
.
Get
(
service
)
if
err
!=
nil
{
return
err
}
if
len
(
endpoint
.
Subsets
)
==
0
{
fmt
.
Printf
(
"Waiting, endpoint for service: %s is not ready yet...
\n
"
,
service
)
return
fmt
.
Errorf
(
"Endpoint for service: %s is not ready yet
\n
"
,
service
)
}
for
_
,
subset
:=
range
endpoint
.
Subsets
{
if
len
(
subset
.
NotReadyAddresses
)
!=
0
{
fmt
.
Printf
(
"Waiting, endpoint for service: %s is not ready yet...
\n
"
,
service
)
return
fmt
.
Errorf
(
"Endpoint for service: %s is not ready yet
\n
"
,
service
)
}
}
return
nil
}
pkg/minikube/cluster/cluster.go
浏览文件 @
3f478fa0
...
...
@@ -563,8 +563,12 @@ type serviceGetter interface {
Get
(
name
string
)
(
*
kubeApi
.
Service
,
error
)
}
type
endpointGetter
interface
{
Get
(
name
string
)
(
*
kubeApi
.
Endpoints
,
error
)
}
func
getServicePort
(
namespace
,
service
string
)
(
int
,
error
)
{
services
,
err
:=
g
etKubernetesServicesWithNamespace
(
namespace
)
services
,
err
:=
G
etKubernetesServicesWithNamespace
(
namespace
)
if
err
!=
nil
{
return
0
,
err
}
...
...
@@ -586,7 +590,7 @@ func getServicePortFromServiceGetter(services serviceGetter, service string) (in
return
nodePort
,
nil
}
func
g
etKubernetesServicesWithNamespace
(
namespace
string
)
(
serviceGetter
,
error
)
{
func
G
etKubernetesServicesWithNamespace
(
namespace
string
)
(
serviceGetter
,
error
)
{
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
configOverrides
:=
&
clientcmd
.
ConfigOverrides
{}
kubeConfig
:=
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
loadingRules
,
configOverrides
)
...
...
@@ -601,3 +605,33 @@ func getKubernetesServicesWithNamespace(namespace string) (serviceGetter, error)
services
:=
client
.
Services
(
namespace
)
return
services
,
nil
}
func
GetKubernetesEndpointsWithNamespace
(
namespace
string
)
(
endpointGetter
,
error
)
{
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
configOverrides
:=
&
clientcmd
.
ConfigOverrides
{}
kubeConfig
:=
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
loadingRules
,
configOverrides
)
config
,
err
:=
kubeConfig
.
ClientConfig
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error creating kubeConfig: %s"
,
err
)
}
client
,
err
:=
unversioned
.
New
(
config
)
if
err
!=
nil
{
return
nil
,
err
}
endpoints
:=
client
.
Endpoints
(
namespace
)
return
endpoints
,
nil
}
// EnsureMinikubeRunningOrExit checks that minikube has a status available and that
// that the status is `Running`, otherwise it will exit
func
EnsureMinikubeRunningOrExit
(
api
libmachine
.
API
)
{
s
,
err
:=
GetHostStatus
(
api
)
if
err
!=
nil
{
glog
.
Errorln
(
"Error getting machine status:"
,
err
)
os
.
Exit
(
1
)
}
if
s
!=
state
.
Running
.
String
()
{
fmt
.
Fprintln
(
os
.
Stdout
,
"minikube is not currently running so the service cannot be accessed"
)
os
.
Exit
(
1
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录