提交 80d8c4f8 编写于 作者: P Piotr Bryk

Merge pull request #78 from bryk/replica-set-list

Rename microservice list view to replica set view
......@@ -37,14 +37,14 @@ func CreateHttpApiHandler(client *client.Client) http.Handler {
Writes(AppDeployment{}))
wsContainer.Add(deployWs)
microserviceListWs := new(restful.WebService)
microserviceListWs.Path("/api/microservice").
replicaSetListWs := new(restful.WebService)
replicaSetListWs.Path("/api/replicaset").
Produces(restful.MIME_JSON)
microserviceListWs.Route(
microserviceListWs.GET("").
To(apiHandler.handleGetMicroserviceList).
Writes(MicroserviceList{}))
wsContainer.Add(microserviceListWs)
replicaSetListWs.Route(
replicaSetListWs.GET("").
To(apiHandler.handleGetReplicaSetList).
Writes(ReplicaSetList{}))
wsContainer.Add(replicaSetListWs)
return wsContainer
}
......@@ -68,11 +68,11 @@ func (apiHandler *ApiHandler) handleDeploy(request *restful.Request, response *r
response.WriteHeaderAndEntity(http.StatusCreated, cfg)
}
// Handles get microservice list API call.
func (apiHandler *ApiHandler) handleGetMicroserviceList(
// Handles get Replica Set list API call.
func (apiHandler *ApiHandler) handleGetReplicaSetList(
request *restful.Request, response *restful.Response) {
result, err := GetMicroserviceList(apiHandler.client)
result, err := GetReplicaSetList(apiHandler.client)
if err != nil {
handleInternalError(response, err)
return
......
......@@ -21,25 +21,18 @@ import (
"k8s.io/kubernetes/pkg/labels"
)
// List of microservices in the cluster.
type MicroserviceList struct {
// Unordered list of microservices.
Microservices []Microservice `json:"microservices"`
// List of Replica Sets in the cluster.
type ReplicaSetList struct {
// Unordered list of Replica Sets.
ReplicaSets []ReplicaSet `json:"replicaSets"`
}
// Microservice is a Kubernetes replica set plus zero or more Kubernetes services.
type Microservice struct {
// Name of the microservice, derived from the replica set.
// Kubernetes Replica Set (aka. Replication Controller) plus zero or more Kubernetes services that
// target the Replica Set.
type ReplicaSet struct {
// Name of the Replica Set.
Name string `json:"name"`
// Replica set that represents the microservice.
ReplicaSet ReplicaSet `json:"replicaSet"`
// TODO(bryk): Add service field here.
}
// Replica set model to represent in the user interface.
type ReplicaSet struct {
// Number of pods that are currently running.
PodsRunning int `json:"podsRunning"`
......@@ -48,10 +41,12 @@ type ReplicaSet struct {
// Container images of the replica set.
ContainerImages []string `json:"containerImages"`
// TODO(bryk): Add service information here.
}
// Returns a list of all microservices in the cluster.
func GetMicroserviceList(client *client.Client) (*MicroserviceList, error) {
// Returns a list of all Replica Sets in the cluster.
func GetReplicaSetList(client *client.Client) (*ReplicaSetList, error) {
list, err := client.ReplicationControllers(api.NamespaceAll).
List(labels.Everything(), fields.Everything())
......@@ -59,24 +54,22 @@ func GetMicroserviceList(client *client.Client) (*MicroserviceList, error) {
return nil, err
}
microserviceList := &MicroserviceList{}
replicaSetList := &ReplicaSetList{}
for _, element := range list.Items {
for _, replicaSet := range list.Items {
var containerImages []string
for _, container := range element.Spec.Template.Spec.Containers {
for _, container := range replicaSet.Spec.Template.Spec.Containers {
containerImages = append(containerImages, container.Image)
}
microserviceList.Microservices = append(microserviceList.Microservices, Microservice{
Name: element.ObjectMeta.Name,
ReplicaSet: ReplicaSet{
ContainerImages: containerImages,
PodsRunning: element.Status.Replicas,
PodsDesired: element.Spec.Replicas,
},
replicaSetList.ReplicaSets = append(replicaSetList.ReplicaSets, ReplicaSet{
Name: replicaSet.ObjectMeta.Name,
ContainerImages: containerImages,
PodsRunning: replicaSet.Status.Replicas,
PodsDesired: replicaSet.Spec.Replicas,
})
}
return microserviceList, nil
return replicaSetList, nil
}
......@@ -50,20 +50,18 @@ backendApi.AppDeployment;
/**
* @typedef {{
* microservices: !Array<!backendApi.Microservice>
* replicaSets: !Array<!backendApi.ReplicaSet>
* }}
*/
backendApi.MicroserviceList;
backendApi.ReplicaSetList;
/**
* @typedef {{
* name: string,
* replicaSet: {
* podsRunning: number,
* podsDesired: number,
* containerImages: !Array<string>
* }
* podsRunning: number,
* podsDesired: number,
* containerImages: !Array<string>
* }}
*/
backendApi.Microservice;
backendApi.ReplicaSet;
......@@ -19,8 +19,8 @@
import chromeModule from './chrome/chrome.module';
import deployModule from './deploy/deploy.module';
import indexConfig from './index.config';
import replicaSetListModule from './replicasetlist/replicasetlist.module';
import routeConfig from './index.route';
import microserviceListModule from './microservicelist/microservicelist.module';
import zerostateModule from './zerostate/zerostate.module';
......@@ -36,7 +36,7 @@ export default angular.module(
'ui.router',
chromeModule.name,
deployModule.name,
microserviceListModule.name,
replicaSetListModule.name,
zerostateModule.name,
])
.config(indexConfig)
......
......@@ -14,19 +14,19 @@
/**
* Controller for the service list view.
* Controller for the replica set list view.
*
* @final
*/
export default class MicroserviceListController {
export default class ReplicaSetListController {
/**
* @param {!angular.$log} $log
* @param {!angular.$resource} $resource
* @ngInject
*/
constructor($log, $resource) {
/** @export {!Array<backendApi.Microservice>} */
this.microservices = [];
/** @export {!Array<backendApi.ReplicaSet>} */
this.replicaSets = [];
this.initialize_($log, $resource);
}
......@@ -37,14 +37,14 @@ export default class MicroserviceListController {
* @private
*/
initialize_($log, $resource) {
/** @type {!angular.Resource<!backendApi.MicroserviceList>} */
let resource = $resource('/api/microservice');
/** @type {!angular.Resource<!backendApi.ReplicaSetList>} */
let resource = $resource('/api/replicaset');
resource.get((microserviceList) => {
$log.info('Successfully fetched microservice list: ', microserviceList);
this.microservices = microserviceList.microservices;
resource.get((replicaSetList) => {
$log.info('Successfully fetched Replica Set list: ', replicaSetList);
this.replicaSets = replicaSetList.replicaSets;
}, (err) => {
$log.error('Error fetching microservice list: ', err);
$log.error('Error fetching Replica Set list: ', err);
});
}
}
......@@ -15,16 +15,16 @@ limitations under the License.
-->
<div layout="row" layout-wrap layout-margin layout-align="center center">
<md-card ng-repeat="microservice in ctrl.microservices">
<md-card-content class="kd-microservice-card">
<md-card ng-repeat="replicaSet in ctrl.replicaSets">
<md-card-content class="kd-replicaset-card">
<div layout="row" layout-align="space-between center">
<span flex>{{microservice.name}}</span>
<md-button flex class="md-icon-button kd-microservice-card-menu">
<span flex>{{replicaSet.name}}</span>
<md-button flex class="md-icon-button kd-replicaset-card-menu">
<md-icon md-font-library="material-icons">more_vert</md-icon>
</md-button>
</div>
<div class="md-caption">
<span>{{microservice.replicaSet.podsRunning}} pods running</span>
<span>{{replicaSet.podsRunning}} pods running</span>
</div>
</md-card-content>
</md-card >
......
......@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import stateConfig from './microservicelist.state';
import stateConfig from './replicasetlist.state';
/**
* Angular module for the microservice list view.
* Angular module for the Replica Set list view.
*
* The view shows microservices running in the cluster and allows to manage them.
* The view shows Replica Sets running in the cluster and allows to manage them.
*/
export default angular.module(
'kubernetesDashboard.microserviceList',
'kubernetesDashboard.replicaSetList',
[
'ngMaterial',
'ui.router',
......
// 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.
.kd-microservice-card {
padding-top: 0;
width: 400px;
// 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.
.kd-replicaset-card {
padding-top: 0;
width: 400px;
}
.kd-replicaset-card-menu {
max-width: 48px;
}
.kd-microservice-card-menu {
max-width: 48px;
}
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import MicroserviceListController from './microservicelist.controller';
import ReplicaSetListController from './replicasetlist.controller';
/**
......@@ -22,10 +22,10 @@ import MicroserviceListController from './microservicelist.controller';
* @ngInject
*/
export default function stateConfig($stateProvider) {
$stateProvider.state('microservicelist', {
controller: MicroserviceListController,
$stateProvider.state('replicasetlist', {
controller: ReplicaSetListController,
controllerAs: 'ctrl',
url: '/microservicelist',
templateUrl: 'microservicelist/microservicelist.html',
url: '/replicasetlist',
templateUrl: 'replicasetlist/replicasetlist.html',
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册