1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

feat(k8s/cluster): Show the cluster leader (#4027)

* feat(cluster): Show the cluster leader

* feat(cluster): Restrict leader label only to admin users

* feat(kubernetes): minor UI update

* feat(endpoint):  move all KubernetesEndpoint related code to a single endpoint sub-folder and change few things

* fix(k8s/cluster): fix conflict leftover

* feat(k8s/cluster): review component leader UX

* refactor(k8s/node): remove useless call to endpoints

* refactor(k8s/endpoint): relocate variable declaration

Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
This commit is contained in:
Maxime Bajeux 2020-07-20 00:49:49 +02:00 committed by GitHub
parent f765c63c74
commit 94676df329
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 162 additions and 16 deletions

View file

@ -0,0 +1,20 @@
import { KubernetesEndpoint, KubernetesEndpointAnnotationLeader } from 'Kubernetes/endpoint/models';
import _ from 'lodash-es';
class KubernetesEndpointConverter {
static apiToEndpoint(data) {
const res = new KubernetesEndpoint();
res.Id = data.metadata.uid;
res.Name = data.metadata.name;
res.Namespace = data.metadata.namespace;
const leaderAnnotation = data.metadata.annotations ? data.metadata.annotations[KubernetesEndpointAnnotationLeader] : '';
if (leaderAnnotation) {
const parsedJson = JSON.parse(leaderAnnotation);
const split = _.split(parsedJson.holderIdentity, '_');
res.HolderIdentity = split[0];
}
return res;
}
}
export default KubernetesEndpointConverter;

View file

@ -0,0 +1,17 @@
export const KubernetesEndpointAnnotationLeader = 'control-plane.alpha.kubernetes.io/leader';
/**
* KubernetesEndpoint Model
*/
const _KubernetesEndpoint = Object.freeze({
Id: '',
Name: '',
Namespace: '',
HolderIdentity: '',
});
export class KubernetesEndpoint {
constructor() {
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesEndpoint)));
}
}

View file

@ -0,0 +1,25 @@
angular.module('portainer.kubernetes').factory('KubernetesEndpoints', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
function KubernetesEndpointsFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
'use strict';
return function (namespace) {
const url = API_ENDPOINT_ENDPOINTS + '/:endpointId/kubernetes/api/v1' + (namespace ? '/namespaces/:namespace' : '') + '/endpoints/:id';
return $resource(
url,
{
endpointId: EndpointProvider.endpointID,
namespace: namespace,
},
{
get: {
method: 'GET',
timeout: 15000,
ignoreLoadingBar: true,
},
}
);
};
},
]);

View file

@ -0,0 +1,33 @@
import _ from 'lodash-es';
import angular from 'angular';
import PortainerError from 'Portainer/error';
import KubernetesEndpointConverter from 'Kubernetes/endpoint/converter';
class KubernetesEndpointService {
/* @ngInject */
constructor($async, KubernetesEndpoints) {
this.$async = $async;
this.KubernetesEndpoints = KubernetesEndpoints;
this.getAllAsync = this.getAllAsync.bind(this);
}
/**
* GET
*/
async getAllAsync(namespace) {
try {
const data = await this.KubernetesEndpoints(namespace).get().$promise;
return _.map(data.items, (item) => KubernetesEndpointConverter.apiToEndpoint(item));
} catch (err) {
throw new PortainerError('Unable to retrieve endpoints', err);
}
}
get(namespace) {
return this.$async(this.getAllAsync, namespace);
}
}
export default KubernetesEndpointService;
angular.module('portainer.kubernetes').service('KubernetesEndpointService', KubernetesEndpointService);