1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00
portainer/app/kubernetes/pod/service.js
Maxime Bajeux 00389a7da9
feat(k8s/application): Support multi-container pods applications (#4208)
* feat(application): Support multi-container pods applications

* feat(application): Support multi-container pods applications

* fix(application): use only one pod in app details and fix logs and console links

* fix(application): show all containers in containers datatable

* fix(application): fix order by pod name

* feat(k8s/application): minor UI update

* feat(k8s/application): minor UI update

* feat(k8s/application): minor UI update

* feat(k8s/application): minor UI update

* feat(k8s/application): minor UI update

* fix(application): fix persisted folders in application details

Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
2020-08-14 11:27:10 +12:00

79 lines
2.1 KiB
JavaScript

import _ from 'lodash-es';
import angular from 'angular';
import PortainerError from 'Portainer/error';
import { KubernetesCommonParams } from 'Kubernetes/models/common/params';
import KubernetesPodConverter from 'Kubernetes/pod/converter';
class KubernetesPodService {
/* @ngInject */
constructor($async, KubernetesPods) {
this.$async = $async;
this.KubernetesPods = KubernetesPods;
this.getAllAsync = this.getAllAsync.bind(this);
this.logsAsync = this.logsAsync.bind(this);
this.deleteAsync = this.deleteAsync.bind(this);
}
/**
* GET ALL
*/
async getAllAsync(namespace) {
try {
const data = await this.KubernetesPods(namespace).get().$promise;
return _.map(data.items, (item) => KubernetesPodConverter.apiToModel(item));
} catch (err) {
throw new PortainerError('Unable to retrieve pods', err);
}
}
get(namespace) {
return this.$async(this.getAllAsync, namespace);
}
/**
* Logs
*
* @param {string} namespace
* @param {string} podName
* @param {string} containerName
*/
async logsAsync(namespace, podName, containerName) {
try {
const params = new KubernetesCommonParams();
params.id = podName;
if (containerName) {
params.container = containerName;
}
const data = await this.KubernetesPods(namespace).logs(params).$promise;
return data.logs.length === 0 ? [] : data.logs.split('\n');
} catch (err) {
throw new PortainerError('Unable to retrieve pod logs', err);
}
}
logs(namespace, podName, containerName) {
return this.$async(this.logsAsync, namespace, podName, containerName);
}
/**
* DELETE
*/
async deleteAsync(pod) {
try {
const params = new KubernetesCommonParams();
params.id = pod.Name;
const namespace = pod.Namespace;
await this.KubernetesPods(namespace).delete(params).$promise;
} catch (err) {
throw new PortainerError('Unable to remove pod', err);
}
}
delete(pod) {
return this.$async(this.deleteAsync, pod);
}
}
export default KubernetesPodService;
angular.module('portainer.kubernetes').service('KubernetesPodService', KubernetesPodService);