You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/kubernetes/endpoint/converter.js

31 lines
1.1 KiB

import { KubernetesEndpoint, KubernetesEndpointAnnotationLeader, KubernetesEndpointSubset } 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];
}
if (data.subsets) {
res.Subsets = _.map(data.subsets, (item) => {
const subset = new KubernetesEndpointSubset();
subset.Ips = _.map(item.addresses, 'ip');
const port = _.find(item.ports, { name: 'https' });
subset.Port = port ? port.port : undefined;
return subset;
});
}
return res;
}
}
export default KubernetesEndpointConverter;