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