Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
凌波微步_大先生
dashboard
提交
a72ddd61
D
dashboard
项目概览
凌波微步_大先生
/
dashboard
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dashboard
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a72ddd61
编写于
11月 05, 2015
作者:
M
Mateusz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #51 from kubernetes/gulp-backend-test-tasks-implement-apiserverclient
Function that creates k8s apiserver client
上级
89a1882e
691565d2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
123 addition
and
3 deletion
+123
-3
build/serve.js
build/serve.js
+1
-1
src/app/backend/apiserverclient.go
src/app/backend/apiserverclient.go
+54
-0
src/app/backend/dashboard.go
src/app/backend/dashboard.go
+20
-2
src/test/backend/apiserverclient_test.go
src/test/backend/apiserverclient_test.go
+48
-0
未找到文件。
build/serve.js
浏览文件 @
a72ddd61
...
@@ -89,7 +89,7 @@ gulp.task('serve', ['index'], serveDevelopmentMode);
...
@@ -89,7 +89,7 @@ gulp.task('serve', ['index'], serveDevelopmentMode);
/**
/**
* Serves the application in production mode.
* Serves the application in production mode.
*/
*/
gulp
.
task
(
'
serve:prod
'
,
[
'
build-frontend
'
,
'
spawn-backend
'
],
function
()
{
gulp
.
task
(
'
serve:prod
'
,
[
'
build-frontend
'
],
function
()
{
browserSyncInit
(
conf
.
paths
.
dist
);
browserSyncInit
(
conf
.
paths
.
dist
);
});
});
...
...
src/app/backend/apiserverclient.go
0 → 100644
浏览文件 @
a72ddd61
// Copyright 2015 Google Inc. 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
backend
import
client
"k8s.io/kubernetes/pkg/client/unversioned"
// Factory that creates Kubernetes API clients.
type
ClientFactory
interface
{
// Creates new API client assuming that the binary runs in a cluster.
NewInCluster
()
(
*
client
.
Client
,
error
)
// Creates new API client from the given config.
New
(
*
client
.
Config
)
(
*
client
.
Client
,
error
)
}
// Creates new Kubernetes Apiserver client. When apiserverHost param is empty string the function
// assumes that it is running inside a Kubernetes cluster and attempts to discover the Apiserver.
// Otherwise, it connects to the Apiserver specified.
// apiserverHost param is in the format of protocol://address:port, e.g., http://localhost:8001.
func
CreateApiserverClient
(
apiserverHost
string
,
clientFactory
ClientFactory
)
(
*
client
.
Client
,
error
)
{
if
apiserverHost
==
""
{
return
clientFactory
.
NewInCluster
()
}
else
{
cfg
:=
client
.
Config
{
Host
:
apiserverHost
,
}
return
clientFactory
.
New
(
&
cfg
)
}
}
// Default implementation of the ClientFactory. It uses k8s.io package API.
type
ClientFactoryImpl
struct
{}
func
(
ClientFactoryImpl
)
New
(
cfg
*
client
.
Config
)
(
*
client
.
Client
,
error
)
{
return
client
.
New
(
cfg
)
}
func
(
ClientFactoryImpl
)
NewInCluster
()
(
*
client
.
Client
,
error
)
{
return
client
.
NewInCluster
()
}
src/app/backend/dashboard.go
浏览文件 @
a72ddd61
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
package
main
package
backend
import
(
import
(
"flag"
"flag"
...
@@ -24,15 +24,33 @@ import (
...
@@ -24,15 +24,33 @@ import (
)
)
var
(
var
(
argPort
=
pflag
.
Int
(
"port"
,
8080
,
"The port to listen to for incomming HTTP requests"
)
argPort
=
pflag
.
Int
(
"port"
,
8080
,
"The port to listen to for incoming HTTP requests"
)
argApiserverHost
=
pflag
.
String
(
"apiserver-host"
,
""
,
"The address of the Kubernetes Apiserver "
+
"to connect to in the format of protocol://address:port, e.g., "
+
"http://localhost:8001. If not specified, the assumption is that the binary runs in a"
+
"Kubernetes cluster and local discovery is attempted."
)
)
)
func
main
()
{
func
main
()
{
pflag
.
CommandLine
.
AddGoFlagSet
(
flag
.
CommandLine
)
pflag
.
CommandLine
.
AddGoFlagSet
(
flag
.
CommandLine
)
pflag
.
Parse
()
pflag
.
Parse
()
glog
.
Info
(
"Starting HTTP server on port "
,
*
argPort
)
glog
.
Info
(
"Starting HTTP server on port "
,
*
argPort
)
defer
glog
.
Flush
()
defer
glog
.
Flush
()
apiserverClient
,
err
:=
CreateApiserverClient
(
*
argApiserverHost
,
new
(
ClientFactoryImpl
))
if
err
!=
nil
{
glog
.
Fatal
(
err
)
}
serverAPIVersion
,
err
:=
apiserverClient
.
ServerAPIVersions
()
if
err
!=
nil
{
glog
.
Fatal
(
err
)
}
// Display Apiserver version. This is just for tests.
println
(
"Server API version: "
+
serverAPIVersion
.
GoString
())
// Run a HTTP server that serves static files from current directory.
// Run a HTTP server that serves static files from current directory.
// TODO(bryk): Disable directory listing.
// TODO(bryk): Disable directory listing.
http
.
Handle
(
"/"
,
http
.
FileServer
(
http
.
Dir
(
"./"
)))
http
.
Handle
(
"/"
,
http
.
FileServer
(
http
.
Dir
(
"./"
)))
...
...
src/test/backend/apiserverclient_test.go
0 → 100644
浏览文件 @
a72ddd61
// Copyright 2015 Google Inc. 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
backend
import
(
"github.com/dashboard/src/app/backend"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"testing"
)
var
fakeRemoteClient
=
new
(
client
.
Client
)
var
fakeInClusterClient
=
new
(
client
.
Client
)
type
FakeClientFactory
struct
{}
func
(
FakeClientFactory
)
New
(
cfg
*
client
.
Config
)
(
*
client
.
Client
,
error
)
{
return
fakeRemoteClient
,
nil
}
func
(
FakeClientFactory
)
NewInCluster
()
(
*
client
.
Client
,
error
)
{
return
fakeInClusterClient
,
nil
}
func
TestCreateApiserverClient_inCluster
(
t
*
testing
.
T
)
{
client
,
_
:=
backend
.
CreateApiserverClient
(
""
,
new
(
FakeClientFactory
))
if
client
!=
fakeInClusterClient
{
t
.
Fatal
(
"Expected in cluster client to be created"
)
}
}
func
TestCreateApiserverClient_remote
(
t
*
testing
.
T
)
{
client
,
_
:=
backend
.
CreateApiserverClient
(
"http://foo:bar"
,
new
(
FakeClientFactory
))
if
client
!=
fakeRemoteClient
{
t
.
Fatal
(
"Expected remote client to be created"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录