mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
feat(cluster): Show the cluster health by showing the status of the underlying cluster components (#4022)
* feat(cluster): add tabs * feat(cluster): add cluster status informations to cluster detail view * feat(cluster): change data display * feat(cluster): prevent regular users to see cluster health * feat(kubernetes): reviewed ComponentStatus handling * refactor(kubernetes): review apiToModel for KubernetesComponentStatus * refactor(kubernetes): remove unused variable * refactor(kubernetes): clean hasUnhealthyComponentStatus code Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
This commit is contained in:
parent
833abb24cb
commit
f765c63c74
6 changed files with 142 additions and 3 deletions
21
app/kubernetes/component-status/converter.js
Normal file
21
app/kubernetes/component-status/converter.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import _ from 'lodash-es';
|
||||
import { KubernetesComponentStatus } from './models';
|
||||
|
||||
export class KubernetesComponentStatusConverter {
|
||||
/**
|
||||
* Convert API data to KubernetesComponentStatus model
|
||||
*/
|
||||
static apiToModel(data) {
|
||||
const res = new KubernetesComponentStatus();
|
||||
res.ComponentName = data.metadata.name;
|
||||
|
||||
const healthyCondition = _.find(data.conditions, { type: 'Healthy' });
|
||||
if (healthyCondition && healthyCondition.status === 'True') {
|
||||
res.Healthy = true;
|
||||
} else if (healthyCondition && healthyCondition.status === 'False') {
|
||||
res.ErrorMessage = healthyCondition.message;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
14
app/kubernetes/component-status/models.js
Normal file
14
app/kubernetes/component-status/models.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* KubernetesComponentStatus Model
|
||||
*/
|
||||
const _KubernetesComponentStatus = Object.freeze({
|
||||
ComponentName: '',
|
||||
Healthy: false,
|
||||
ErrorMessage: '',
|
||||
});
|
||||
|
||||
export class KubernetesComponentStatus {
|
||||
constructor() {
|
||||
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesComponentStatus)));
|
||||
}
|
||||
}
|
24
app/kubernetes/component-status/rest.js
Normal file
24
app/kubernetes/component-status/rest.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
angular.module('portainer.kubernetes').factory('KubernetesComponentStatus', [
|
||||
'$resource',
|
||||
'API_ENDPOINT_ENDPOINTS',
|
||||
'EndpointProvider',
|
||||
function KubernetesComponentStatusFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
|
||||
'use strict';
|
||||
return function () {
|
||||
const url = API_ENDPOINT_ENDPOINTS + '/:endpointId/kubernetes/api/v1' + '/componentstatuses/:id';
|
||||
return $resource(
|
||||
url,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
},
|
||||
{
|
||||
get: {
|
||||
method: 'GET',
|
||||
timeout: 15000,
|
||||
ignoreLoadingBar: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
},
|
||||
]);
|
34
app/kubernetes/component-status/service.js
Normal file
34
app/kubernetes/component-status/service.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import angular from 'angular';
|
||||
import PortainerError from 'Portainer/error';
|
||||
import _ from 'lodash-es';
|
||||
import { KubernetesComponentStatusConverter } from './converter';
|
||||
|
||||
class KubernetesComponentStatusService {
|
||||
/* @ngInject */
|
||||
constructor($async, KubernetesComponentStatus) {
|
||||
this.$async = $async;
|
||||
this.KubernetesComponentStatus = KubernetesComponentStatus;
|
||||
|
||||
this.getAsync = this.getAsync.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET
|
||||
*/
|
||||
async getAsync() {
|
||||
try {
|
||||
const data = await this.KubernetesComponentStatus().get().$promise;
|
||||
const res = _.map(data.items, (item) => KubernetesComponentStatusConverter.apiToModel(item));
|
||||
return res;
|
||||
} catch (err) {
|
||||
throw new PortainerError('Unable to retrieve cluster status', err);
|
||||
}
|
||||
}
|
||||
|
||||
get() {
|
||||
return this.$async(this.getAsync);
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesComponentStatusService;
|
||||
angular.module('portainer.kubernetes').service('KubernetesComponentStatusService', KubernetesComponentStatusService);
|
Loading…
Add table
Add a link
Reference in a new issue