fix(application): Can't update application with persisted data, after the storage option is disabled on cluster (#4861)

* fix(application): Can't update application with persisted data, after the storage option is disabled on cluster

* refacto(application): Some code extraction requested for better maintenance
pull/4889/head
Maxime Bajeux 4 years ago committed by GitHub
parent 93eaccc878
commit cc9dd55b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -300,7 +300,7 @@ class KubernetesApplicationConverter {
formValues.ApplicationOwner = KubernetesCommonHelper.ownerToLabel(formValues.ApplicationOwner);
const claims = KubernetesPersistentVolumeClaimConverter.applicationFormValuesToVolumeClaims(formValues);
const rwx = _.find(claims, (item) => _.includes(item.StorageClass.AccessModes, 'RWX')) !== undefined;
const rwx = KubernetesApplicationHelper.hasRWX(claims);
const deployment =
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.REPLICATED &&

@ -62,7 +62,7 @@ class KubernetesPersistentVolumeClaimConverter {
res.metadata.name = pvc.Name;
res.metadata.namespace = pvc.Namespace;
res.spec.resources.requests.storage = pvc.Storage;
res.spec.storageClassName = pvc.StorageClass.Name;
res.spec.storageClassName = pvc.StorageClass ? pvc.StorageClass.Name : '';
res.metadata.labels.app = pvc.ApplicationName;
res.metadata.labels[KubernetesPortainerApplicationOwnerLabel] = pvc.ApplicationOwner;
res.metadata.labels[KubernetesPortainerApplicationNameLabel] = pvc.ApplicationName;

@ -349,6 +349,14 @@ class KubernetesApplicationHelper {
app.Volumes.push(volume);
});
}
static hasRWOOnly(formValues) {
return _.find(formValues.PersistedFolders, (item) => item.StorageClass && _.isEqual(item.StorageClass.AccessModes, ['RWO']));
}
static hasRWX(claims) {
return _.find(claims, (item) => item.StorageClass && _.includes(item.StorageClass.AccessModes, 'RWX')) !== undefined;
}
/* #endregion */
/* #region PLACEMENTS FV <> AFFINITY */

@ -462,7 +462,7 @@ class KubernetesCreateApplicationController {
// * The data access policy is set to ISOLATED
supportGlobalDeployment() {
const hasFolders = this.formValues.PersistedFolders.length !== 0;
const hasRWOOnly = _.find(this.formValues.PersistedFolders, (item) => _.isEqual(item.StorageClass.AccessModes, ['RWO']));
const hasRWOOnly = KubernetesApplicationHelper.hasRWOOnly(this.formValues);
const isIsolated = this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED;
if ((hasFolders && hasRWOOnly) || isIsolated) {
@ -483,7 +483,7 @@ class KubernetesCreateApplicationController {
// * The access policy is set to isolated
supportScalableReplicaDeployment() {
const hasFolders = this.formValues.PersistedFolders.length !== 0;
const hasRWOOnly = _.find(this.formValues.PersistedFolders, (item) => _.isEqual(item.StorageClass.AccessModes, ['RWO']));
const hasRWOOnly = KubernetesApplicationHelper.hasRWOOnly(this.formValues);
const isIsolated = this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED;
if (!hasFolders || isIsolated || (hasFolders && !hasRWOOnly)) {
@ -499,7 +499,7 @@ class KubernetesCreateApplicationController {
for (let i = 0; i < this.formValues.PersistedFolders.length; i++) {
const folder = this.formValues.PersistedFolders[i];
if (_.isEqual(folder.StorageClass.AccessModes, ['RWO'])) {
if (folder.StorageClass && _.isEqual(folder.StorageClass.AccessModes, ['RWO'])) {
storageOptions.push(folder.StorageClass.Name);
}
}

Loading…
Cancel
Save