portainer/app/kubernetes/endpoint/converter.js

21 lines
729 B
JavaScript
Raw Normal View History

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;