1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 07:19:41 +02:00
portainer/app/kubernetes/services/storageService.js
Maxime Bajeux 61f97469ab
feat(application): Add the ability to use existing volumes when creating an application (#4044)
* feat(applications): update UI to use existing volumes

* feat(application): Add the ability to use existing volumes when creating an application

* feat(application): Existing persisted folders should default to associated volumes

* feat(application): add form validation to existing volume

* feat(application): remove the ability to use an existing volume with statefulset application

* feat(k8s/applications): minor UI update

* feat(k8s/application): minor UI update

* feat(volume): allow to increase volume size and few other things

* feat(volumes): add the ability to allow volume expansion

* fix(storage): fix the storage patch request

* fix(k8s/applications): remove conflict leftover

* feat(k8s/configure): minor UI update

* feat(k8s/volume): minor UI update

* fix(storage): change few things

Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
2020-08-07 16:40:24 +12:00

57 lines
1.7 KiB
JavaScript

import angular from 'angular';
import _ from 'lodash-es';
import PortainerError from 'Portainer/error';
import KubernetesStorageClassConverter from 'Kubernetes/converters/storageClass';
import { KubernetesCommonParams } from 'Kubernetes/models/common/params';
class KubernetesStorageService {
/* @ngInject */
constructor($async, KubernetesStorage) {
this.$async = $async;
this.KubernetesStorage = KubernetesStorage;
this.getAsync = this.getAsync.bind(this);
this.patchAsync = this.patchAsync.bind(this);
}
/**
* GET
*/
async getAsync(endpointId) {
try {
const params = {
endpointId: endpointId,
};
const classes = await this.KubernetesStorage().get(params).$promise;
const res = _.map(classes.items, (item) => KubernetesStorageClassConverter.apiToStorageClass(item));
return res;
} catch (err) {
throw new PortainerError('Unable to retrieve storage classes', err);
}
}
get(endpointId) {
return this.$async(this.getAsync, endpointId);
}
/**
* PATCH
*/
async patchAsync(oldStorageClass, newStorageClass) {
try {
const params = new KubernetesCommonParams();
params.id = newStorageClass.Name;
const payload = KubernetesStorageClassConverter.patchPayload(oldStorageClass, newStorageClass);
await this.KubernetesStorage().patch(params, payload).$promise;
} catch (err) {
throw new PortainerError('Unable to patch storage class', err);
}
}
patch(oldStorageClass, newStorageClass) {
return this.$async(this.patchAsync, oldStorageClass, newStorageClass);
}
}
export default KubernetesStorageService;
angular.module('portainer.kubernetes').service('KubernetesStorageService', KubernetesStorageService);