Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
凌波微步_大先生
dashboard
提交
8cfcf64f
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,发现更多精彩内容 >>
提交
8cfcf64f
编写于
3月 08, 2016
作者:
M
Marcin Maciaszczyk
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #504 from maciaszczykm/go-refactoring
Refactor go code and fix link to go report card
上级
63758023
95c88f03
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
68 addition
and
51 deletion
+68
-51
README.md
README.md
+1
-1
src/app/backend/apihandler.go
src/app/backend/apihandler.go
+3
-1
src/app/backend/apiserverclient.go
src/app/backend/apiserverclient.go
+3
-5
src/app/backend/deploy.go
src/app/backend/deploy.go
+13
-11
src/app/backend/eventscommon.go
src/app/backend/eventscommon.go
+2
-2
src/app/backend/heapsterclient.go
src/app/backend/heapsterclient.go
+11
-6
src/app/backend/replicationcontrollerdetail.go
src/app/backend/replicationcontrollerdetail.go
+13
-10
src/app/backend/replicationcontrollerpods.go
src/app/backend/replicationcontrollerpods.go
+8
-5
src/app/backend/replicationcontrollerpodsmetrics.go
src/app/backend/replicationcontrollerpodsmetrics.go
+4
-3
src/app/backend/validateappname.go
src/app/backend/validateappname.go
+4
-3
src/test/backend/events_test.go
src/test/backend/events_test.go
+6
-4
未找到文件。
README.md
浏览文件 @
8cfcf64f
# Kubernetes Dashboard
[
![Build Status
](
https://travis-ci.org/kubernetes/dashboard.svg?branch=master
)
](https://travis-ci.org/kubernetes/dashboard)
[
![Coverage Status
](
https://codecov.io/github/bryk/dashboard/coverage.svg?branch=master
)
](https://codecov.io/github/bryk/dashboard?branch=master)
[
![Go Report Card
](
https://goreportcard.com/badge/github.com/kubernetes/dashboard
)
](https://goreportcard.com/
badge
/github.com/kubernetes/dashboard)
[
![Go Report Card
](
https://goreportcard.com/badge/github.com/kubernetes/dashboard
)
](https://goreportcard.com/
report
/github.com/kubernetes/dashboard)
Kubernetes Dashboard is a general purpose, web-based UI for Kubernetes clusters. It allows users to
manage applications running in the cluster and troubleshoot them, as well as manage the cluster
...
...
src/app/backend/apihandler.go
浏览文件 @
8cfcf64f
...
...
@@ -27,7 +27,7 @@ import (
const
(
// RequestLogString is a template for request log message.
RequestLogString
=
"Incoming %s %s %s request from %s"
RequestLogString
=
"Incoming %s %s %s request from %s"
// ResponseLogString is a template for response log message.
ResponseLogString
=
"Outcoming response to %s with %d status code"
...
...
@@ -189,6 +189,8 @@ func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient,
return
wsContainer
}
// ApiHandler is a representation of API handler. Structure contains client, Heaptster client and
// client configuration.
type
ApiHandler
struct
{
client
*
client
.
Client
heapsterClient
HeapsterClient
...
...
src/app/backend/apiserverclient.go
浏览文件 @
8cfcf64f
...
...
@@ -22,14 +22,12 @@ import (
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
)
// Create
s 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.
// Create
ApiserverClient 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/pathPrefix, e.g.,
// http://localhost:8001.
//
// CreateApiserverClient returns created client and its configuration.
func
CreateApiserverClient
(
apiserverHost
string
)
(
*
client
.
Client
,
clientcmd
.
ClientConfig
,
error
)
{
overrides
:=
&
clientcmd
.
ConfigOverrides
{}
...
...
src/app/backend/deploy.go
浏览文件 @
8cfcf64f
...
...
@@ -29,10 +29,11 @@ import (
)
const
(
// DescriptionAnnotationKey is annotation key for a description.
DescriptionAnnotationKey
=
"description"
)
//
S
pecification for an app deployment.
//
AppDeploymentSpec is a s
pecification for an app deployment.
type
AppDeploymentSpec
struct
{
// Name of the application.
Name
string
`json:"name"`
...
...
@@ -82,7 +83,7 @@ type AppDeploymentSpec struct {
RunAsPrivileged
bool
`json:"runAsPrivileged"`
}
//
S
pecification for deployment from file
//
AppDeploymentFromFileSpec is a s
pecification for deployment from file
type
AppDeploymentFromFileSpec
struct
{
// Name of the file
Name
string
`json:"name"`
...
...
@@ -91,7 +92,7 @@ type AppDeploymentFromFileSpec struct {
Content
string
`json:"content"`
}
//
S
pecification for deployment from file
//
AppDeploymentFromFileResponse is a s
pecification for deployment from file
type
AppDeploymentFromFileResponse
struct
{
// Name of the file
Name
string
`json:"name"`
...
...
@@ -103,7 +104,7 @@ type AppDeploymentFromFileResponse struct {
Error
string
`json:"error"`
}
// Port mapping for an application deployment.
// Port
Mapping is a specification of port
mapping for an application deployment.
type
PortMapping
struct
{
// Port that will be exposed on the service.
Port
int
`json:"port"`
...
...
@@ -124,7 +125,7 @@ type EnvironmentVariable struct {
Value
string
`json:"value"`
}
//
S
tructure representing label assignable to Pod/RC/Service
//
Label is a s
tructure representing label assignable to Pod/RC/Service
type
Label
struct
{
// Label key
Key
string
`json:"key"`
...
...
@@ -133,15 +134,15 @@ type Label struct {
Value
string
`json:"value"`
}
//
S
tructure representing supported protocol types for a service
//
Protocols is a s
tructure representing supported protocol types for a service
type
Protocols
struct
{
// Array containing supported protocol types e.g., ["TCP", "UDP"]
Protocols
[]
api
.
Protocol
`json:"protocols"`
}
// Deploy
s an app based on the given configuration. The app is deployed using the given client.
//
App deployment consists of a replication controller and an optional service. Both of them share
// common labels.
// Deploy
App deploys an app based on the given configuration. The app is deployed using the given
//
client. App deployment consists of a replication controller and an optional service. Both of them
//
share
common labels.
func
DeployApp
(
spec
*
AppDeploymentSpec
,
client
client
.
Interface
)
error
{
log
.
Printf
(
"Deploying %s application into %s namespace"
,
spec
.
Name
,
spec
.
Namespace
)
...
...
@@ -247,6 +248,7 @@ func DeployApp(spec *AppDeploymentSpec, client client.Interface) error {
}
}
// GetAvailableProtocols returns list of available protocols. Currently it is TCP and UDP.
func
GetAvailableProtocols
()
*
Protocols
{
return
&
Protocols
{
Protocols
:
[]
api
.
Protocol
{
api
.
ProtocolTCP
,
api
.
ProtocolUDP
}}
}
...
...
@@ -279,13 +281,13 @@ func getLabelsMap(labels []Label) map[string]string {
type
createObjectFromInfo
func
(
info
*
kubectlResource
.
Info
)
(
bool
,
error
)
//
I
mplementation of createObjectFromInfo
//
CreateObjectFromInfoFn is a i
mplementation of createObjectFromInfo
func
CreateObjectFromInfoFn
(
info
*
kubectlResource
.
Info
)
(
bool
,
error
)
{
createdResource
,
err
:=
kubectlResource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
info
.
Object
)
return
createdResource
!=
nil
,
err
}
// Deploys an app based on the given yaml or json file.
// Deploy
AppFromFile deploy
s an app based on the given yaml or json file.
func
DeployAppFromFile
(
spec
*
AppDeploymentFromFileSpec
,
createObjectFromInfoFn
createObjectFromInfo
,
clientConfig
clientcmd
.
ClientConfig
)
(
bool
,
error
)
{
const
(
...
...
src/app/backend/eventscommon.go
浏览文件 @
8cfcf64f
...
...
@@ -21,7 +21,7 @@ import (
"strings"
)
//
P
artial strings to correctly filter warning events.
//
FailedReasonPartials is an array of p
artial strings to correctly filter warning events.
// Have to be lower case for correct case insensitive comparison.
// Based on k8s official events reason file:
// https://github.com/kubernetes/kubernetes/blob/53f0f9d59860131c2be301a0054adfc86e43945d/pkg/kubelet/container/event.go
...
...
@@ -30,7 +30,7 @@ import (
var
FailedReasonPartials
=
[]
string
{
"failed"
,
"err"
,
"exceeded"
,
"invalid"
,
"unhealthy"
,
"mismatch"
,
"insufficient"
,
"conflict"
,
"outof"
,
"nil"
}
//
R
eturns warning pod events based on given list of pods.
//
GetPodsEventWarnings r
eturns warning pod events based on given list of pods.
// TODO(floreks) : Import and use Set instead of custom function to get rid of duplicates
func
GetPodsEventWarnings
(
client
client
.
Interface
,
pods
[]
api
.
Pod
)
(
result
[]
Event
,
err
error
)
{
for
_
,
pod
:=
range
pods
{
...
...
src/app/backend/heapsterclient.go
浏览文件 @
8cfcf64f
...
...
@@ -20,7 +20,7 @@ import (
client
"k8s.io/kubernetes/pkg/client/unversioned"
)
//
Clients for making
requests to a Heapster instance.
//
HeapsterClient is a client used to make
requests to a Heapster instance.
type
HeapsterClient
interface
{
// Creates a new GET HTTP request to heapster, specified by the path param, to the V1 API
// endpoint. The path param is without the API prefix, e.g.,
...
...
@@ -29,11 +29,13 @@ type HeapsterClient interface {
Get
(
path
string
)
*
client
.
Request
}
// In-cluster implementation of heapster client. Talks with heapster through service proxy.
// InClusterHeapsterClient is an in-cluster implementation of a Heapster client. Talks with Heapster
// through service proxy.
type
InClusterHeapsterClient
struct
{
client
*
client
.
Client
}
// InClusterHeapsterClient.Get creates request to given path.
func
(
c
InClusterHeapsterClient
)
Get
(
path
string
)
*
client
.
Request
{
return
c
.
client
.
Get
()
.
Prefix
(
"proxy"
)
.
Namespace
(
"kube-system"
)
.
...
...
@@ -42,18 +44,21 @@ func (c InClusterHeapsterClient) Get(path string) *client.Request {
Suffix
(
"/api/v1"
+
path
)
}
// Remote heapster client based implementation. Talks with heapster through raw RESTClient.
// RemoteHeapsterClient is an implementation of a remote Heapster client. Talks with Heapster
// through raw RESTClient.
type
RemoteHeapsterClient
struct
{
client
*
client
.
RESTClient
}
// RemoteHeapsterClient.Get creates request to given path.
func
(
c
RemoteHeapsterClient
)
Get
(
path
string
)
*
client
.
Request
{
return
c
.
client
.
Get
()
.
Suffix
(
path
)
}
// Creates new Heapster REST client. When heapsterHost param is empty string the function
// assumes that it is running inside a Kubernetes cluster and connects via service proxy.
// heapsterHost param is in the format of protocol://address:port, e.g., http://localhost:8002.
// CreateHeapsterRESTClient creates new Heapster REST client. When heapsterHost param is empty
// string the function assumes that it is running inside a Kubernetes cluster and connects via
// service proxy. heapsterHost param is in the format of protocol://address:port,
// e.g., http://localhost:8002.
func
CreateHeapsterRESTClient
(
heapsterHost
string
,
apiclient
*
client
.
Client
)
(
HeapsterClient
,
error
)
{
...
...
src/app/backend/replicationcontrollerdetail.go
浏览文件 @
8cfcf64f
...
...
@@ -84,13 +84,13 @@ type ServiceDetail struct {
// Name of the service.
Name
string
`json:"name"`
// Internal endpoints of all Kubernetes services that have the same label selector as
connected
// Replication Controller.
// Internal endpoints of all Kubernetes services that have the same label selector as
//
connected
Replication Controller.
// Endpoint is DNS name merged with ports.
InternalEndpoint
Endpoint
`json:"internalEndpoint"`
// External endpoints of all Kubernetes services that have the same label selector as
connected
// Replication Controller.
// External endpoints of all Kubernetes services that have the same label selector as
//
connected
Replication Controller.
// Endpoint is external IP address name merged with ports.
ExternalEndpoints
[]
Endpoint
`json:"externalEndpoints"`
...
...
@@ -116,13 +116,14 @@ type Endpoint struct {
Ports
[]
ServicePort
`json:"ports"`
}
//
Information needed to update replication controller
//
ReplicationControllerSpec contains information needed to update replication controller.
type
ReplicationControllerSpec
struct
{
// Replicas (pods) number in replicas set
Replicas
int
`json:"replicas"`
}
// Returns detailed information about the given replication controller in the given namespace.
// GetReplicationControllerDetail returns detailed information about the given replication
// controller in the given namespace.
func
GetReplicationControllerDetail
(
client
client
.
Interface
,
heapsterClient
HeapsterClient
,
namespace
,
name
string
)
(
*
ReplicationControllerDetail
,
error
)
{
log
.
Printf
(
"Getting details of %s replication controller in %s namespace"
,
name
,
namespace
)
...
...
@@ -194,8 +195,8 @@ func GetReplicationControllerDetail(client client.Interface, heapsterClient Heap
}
// TODO(floreks): This should be transactional to make sure that RC will not be deleted without pods
// Delete
s replication controller with given name in given namespace and related pods.
// Also deletes services related to replication controller if deleteServices is true.
// Delete
ReplicationController deletes replication controller with given name in given namespace and
//
related pods.
Also deletes services related to replication controller if deleteServices is true.
func
DeleteReplicationController
(
client
client
.
Interface
,
namespace
,
name
string
,
deleteServices
bool
)
error
{
...
...
@@ -227,7 +228,8 @@ func DeleteReplicationController(client client.Interface, namespace, name string
return
nil
}
// Deletes services related to replication controller with given name in given namespace.
// DeleteReplicationControllerServices deletes services related to replication controller with given
// name in given namespace.
func
DeleteReplicationControllerServices
(
client
client
.
Interface
,
namespace
,
name
string
)
error
{
log
.
Printf
(
"Deleting services related to %s replication controller from %s namespace"
,
name
,
namespace
)
...
...
@@ -259,7 +261,8 @@ func DeleteReplicationControllerServices(client client.Interface, namespace, nam
return
nil
}
// Updates number of replicas in Replication Controller based on Replication Controller Spec
// UpdateReplicasCount updates number of replicas in Replication Controller based on Replication
// Controller Spec
func
UpdateReplicasCount
(
client
client
.
Interface
,
namespace
,
name
string
,
replicationControllerSpec
*
ReplicationControllerSpec
)
error
{
log
.
Printf
(
"Updating replicas count to %d for %s replication controller from %s namespace"
,
...
...
src/app/backend/replicationcontrollerpods.go
浏览文件 @
8cfcf64f
...
...
@@ -32,7 +32,7 @@ func (a TotalRestartCountSorter) Less(i, j int) bool {
return
a
[
i
]
.
TotalRestartCount
>
a
[
j
]
.
TotalRestartCount
}
//
Information about
a Container that belongs to a Pod.
//
PodContainer is a representation of
a Container that belongs to a Pod.
type
PodContainer
struct
{
// Name of a Container.
Name
string
`json:"name"`
...
...
@@ -41,13 +41,15 @@ type PodContainer struct {
RestartCount
int
`json:"restartCount"`
}
// List of pods that belongs to a Replication Controller.
// ReplicationControllerPods is a representation of pods list that belongs to a Replication
// Controller.
type
ReplicationControllerPods
struct
{
// List of pods that belongs to a Replication Controller.
Pods
[]
ReplicationControllerPodWithContainers
`json:"pods"`
}
// Detailed information about a Pod that belongs to a Replication Controller.
// ReplicationControllerPodWithContainers is a representation of a Pod that belongs to a Replication
// Controller.
type
ReplicationControllerPodWithContainers
struct
{
// Name of the Pod.
Name
string
`json:"name"`
...
...
@@ -62,8 +64,9 @@ type ReplicationControllerPodWithContainers struct {
PodContainers
[]
PodContainer
`json:"podContainers"`
}
// Returns list of pods with containers for the given replication controller in the given namespace.
// Limit specify the number of records to return. There is no limit when given value is zero.
// GetReplicationControllerPods returns list of pods with containers for the given replication
// controller in the given namespace. Limit specify the number of records to return. There is no
// limit when given value is zero.
func
GetReplicationControllerPods
(
client
*
client
.
Client
,
namespace
,
name
string
,
limit
int
)
(
*
ReplicationControllerPods
,
error
)
{
log
.
Printf
(
"Getting list of pods from %s replication controller in %s namespace with limit %d"
,
name
,
...
...
src/app/backend/replicationcontrollerpodsmetrics.go
浏览文件 @
8cfcf64f
...
...
@@ -31,20 +31,21 @@ const (
memoryUsage
=
"memory-usage"
)
//
M
etrics map by pod name.
//
ReplicationControllerMetricsByPod is a m
etrics map by pod name.
type
ReplicationControllerMetricsByPod
struct
{
// Metrics map by pod name
MetricsMap
map
[
string
]
PodMetrics
`json:"metricsMap"`
}
//
S
ome sample measurement of a non-negative, integer quantity
//
MetricResult is a s
ome sample measurement of a non-negative, integer quantity
// (for example, memory usage in bytes observed at some moment)
type
MetricResult
struct
{
Timestamp
time
.
Time
`json:"timestamp"`
Value
uint64
`json:"value"`
}
// Pod metrics structure.
// PodMetrics is a structure representing pods metrics, contains information about CPU and memory
// usage.
type
PodMetrics
struct
{
// Most recent measure of CPU usage on all cores in nanoseconds.
CpuUsage
*
uint64
`json:"cpuUsage"`
...
...
src/app/backend/validateappname.go
浏览文件 @
8cfcf64f
...
...
@@ -21,7 +21,7 @@ import (
client
"k8s.io/kubernetes/pkg/client/unversioned"
)
//
S
pecification for application name validation request.
//
AppNameValiditySpec is a s
pecification for application name validation request.
type
AppNameValiditySpec
struct
{
// Name of the application.
Name
string
`json:"name"`
...
...
@@ -30,13 +30,14 @@ type AppNameValiditySpec struct {
Namespace
string
`json:"namespace"`
}
//
D
escribes validity of the application name.
//
AppNameValidity d
escribes validity of the application name.
type
AppNameValidity
struct
{
// True when the application name is valid.
Valid
bool
`json:"valid"`
}
// Validates application name. When error is returned, name validity could not be determined.
// ValidateAppName validates application name. When error is returned, name validity could not be
// determined.
func
ValidateAppName
(
spec
*
AppNameValiditySpec
,
client
client
.
Interface
)
(
*
AppNameValidity
,
error
)
{
log
.
Printf
(
"Validating %s application name in %s namespace"
,
spec
.
Name
,
spec
.
Namespace
)
...
...
src/test/backend/events_test.go
浏览文件 @
8cfcf64f
...
...
@@ -60,10 +60,10 @@ func TestAppendEvents(t *testing.T) {
},
Count
:
7
,
FirstTimestamp
:
unversioned
.
Time
{
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
Time
:
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
},
LastTimestamp
:
unversioned
.
Time
{
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
Time
:
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
},
Reason
:
"my-event-reason"
,
Type
:
api
.
EventTypeNormal
,
...
...
@@ -86,10 +86,12 @@ func TestAppendEvents(t *testing.T) {
SubObject
:
"my-event-subobject"
,
Count
:
7
,
FirstSeen
:
unversioned
.
Time
{
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
Time
:
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
},
LastSeen
:
unversioned
.
Time
{
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
Time
:
time
.
Date
(
2015
,
1
,
1
,
0
,
0
,
0
,
0
,
location
),
},
Reason
:
"my-event-reason"
,
Type
:
api
.
EventTypeNormal
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录