2020-07-05 23:21:03 +00:00
|
|
|
import angular from 'angular';
|
2021-02-26 15:50:33 +00:00
|
|
|
import _ from 'lodash-es';
|
2020-07-05 23:21:03 +00:00
|
|
|
import filesizeParser from 'filesize-parser';
|
|
|
|
import * as JsonPatch from 'fast-json-patch';
|
2021-10-19 00:21:54 +00:00
|
|
|
import { RegistryTypes } from '@/portainer/models/registryTypes';
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
KubernetesApplicationDataAccessPolicies,
|
|
|
|
KubernetesApplicationDeploymentTypes,
|
|
|
|
KubernetesApplicationPublishingTypes,
|
|
|
|
KubernetesApplicationQuotaDefaults,
|
2020-08-07 04:40:24 +00:00
|
|
|
KubernetesApplicationTypes,
|
2020-08-13 23:56:53 +00:00
|
|
|
KubernetesApplicationPlacementTypes,
|
2021-09-07 00:37:26 +00:00
|
|
|
KubernetesDeploymentTypes,
|
2020-07-05 23:21:03 +00:00
|
|
|
} from 'Kubernetes/models/application/models';
|
|
|
|
import {
|
|
|
|
KubernetesApplicationConfigurationFormValue,
|
|
|
|
KubernetesApplicationConfigurationFormValueOverridenKey,
|
|
|
|
KubernetesApplicationConfigurationFormValueOverridenKeyTypes,
|
|
|
|
KubernetesApplicationEnvironmentVariableFormValue,
|
|
|
|
KubernetesApplicationFormValues,
|
|
|
|
KubernetesApplicationPersistedFolderFormValue,
|
|
|
|
KubernetesApplicationPublishedPortFormValue,
|
2020-08-13 23:56:53 +00:00
|
|
|
KubernetesApplicationPlacementFormValue,
|
2021-02-26 15:50:33 +00:00
|
|
|
KubernetesFormValidationReferences,
|
2020-07-05 23:21:03 +00:00
|
|
|
} from 'Kubernetes/models/application/formValues';
|
|
|
|
import KubernetesFormValidationHelper from 'Kubernetes/helpers/formValidationHelper';
|
|
|
|
import KubernetesApplicationConverter from 'Kubernetes/converters/application';
|
|
|
|
import KubernetesResourceReservationHelper from 'Kubernetes/helpers/resourceReservationHelper';
|
|
|
|
import { KubernetesServiceTypes } from 'Kubernetes/models/service/models';
|
2020-08-04 22:08:11 +00:00
|
|
|
import KubernetesApplicationHelper from 'Kubernetes/helpers/application/index';
|
2020-08-07 04:40:24 +00:00
|
|
|
import KubernetesVolumeHelper from 'Kubernetes/helpers/volumeHelper';
|
2021-08-26 14:00:59 +00:00
|
|
|
import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
|
2020-08-13 23:56:53 +00:00
|
|
|
import { KubernetesNodeHelper } from 'Kubernetes/node/helper';
|
2022-11-07 06:03:11 +00:00
|
|
|
import { updateIngress, getIngresses } from '@/react/kubernetes/ingresses/service';
|
2022-10-07 03:55:11 +00:00
|
|
|
import { confirmUpdateAppIngress } from '@/portainer/services/modal.service/prompt';
|
2023-02-07 03:33:57 +00:00
|
|
|
import { placementOptions } from './placementTypes';
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
class KubernetesCreateApplicationController {
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region CONSTRUCTOR */
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
/* @ngInject */
|
|
|
|
constructor(
|
2021-09-29 00:58:04 +00:00
|
|
|
$scope,
|
2020-07-05 23:21:03 +00:00
|
|
|
$async,
|
|
|
|
$state,
|
|
|
|
Notifications,
|
|
|
|
Authentication,
|
|
|
|
ModalService,
|
|
|
|
KubernetesResourcePoolService,
|
|
|
|
KubernetesApplicationService,
|
|
|
|
KubernetesStackService,
|
|
|
|
KubernetesConfigurationService,
|
|
|
|
KubernetesNodeService,
|
2020-08-12 23:30:23 +00:00
|
|
|
KubernetesIngressService,
|
2020-07-14 05:39:13 +00:00
|
|
|
KubernetesPersistentVolumeClaimService,
|
2021-07-14 09:15:21 +00:00
|
|
|
KubernetesVolumeService,
|
2021-08-31 21:08:01 +00:00
|
|
|
RegistryService,
|
2021-09-07 00:37:26 +00:00
|
|
|
StackService,
|
2021-08-31 21:08:01 +00:00
|
|
|
KubernetesNodesLimitsService
|
2020-07-05 23:21:03 +00:00
|
|
|
) {
|
2021-09-29 00:58:04 +00:00
|
|
|
this.$scope = $scope;
|
2020-07-05 23:21:03 +00:00
|
|
|
this.$async = $async;
|
|
|
|
this.$state = $state;
|
|
|
|
this.Notifications = Notifications;
|
|
|
|
this.Authentication = Authentication;
|
|
|
|
this.ModalService = ModalService;
|
|
|
|
this.KubernetesResourcePoolService = KubernetesResourcePoolService;
|
|
|
|
this.KubernetesApplicationService = KubernetesApplicationService;
|
|
|
|
this.KubernetesStackService = KubernetesStackService;
|
|
|
|
this.KubernetesConfigurationService = KubernetesConfigurationService;
|
|
|
|
this.KubernetesNodeService = KubernetesNodeService;
|
2020-08-07 04:40:24 +00:00
|
|
|
this.KubernetesVolumeService = KubernetesVolumeService;
|
2020-08-12 23:30:23 +00:00
|
|
|
this.KubernetesIngressService = KubernetesIngressService;
|
2020-07-05 23:21:03 +00:00
|
|
|
this.KubernetesPersistentVolumeClaimService = KubernetesPersistentVolumeClaimService;
|
2021-07-14 09:15:21 +00:00
|
|
|
this.RegistryService = RegistryService;
|
2021-09-07 00:37:26 +00:00
|
|
|
this.StackService = StackService;
|
2021-08-31 21:08:01 +00:00
|
|
|
this.KubernetesNodesLimitsService = KubernetesNodesLimitsService;
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
this.ApplicationDeploymentTypes = KubernetesApplicationDeploymentTypes;
|
|
|
|
this.ApplicationDataAccessPolicies = KubernetesApplicationDataAccessPolicies;
|
|
|
|
this.ApplicationPublishingTypes = KubernetesApplicationPublishingTypes;
|
2020-08-13 23:56:53 +00:00
|
|
|
this.ApplicationPlacementTypes = KubernetesApplicationPlacementTypes;
|
2020-08-07 04:40:24 +00:00
|
|
|
this.ApplicationTypes = KubernetesApplicationTypes;
|
2020-07-05 23:21:03 +00:00
|
|
|
this.ApplicationConfigurationFormValueOverridenKeyTypes = KubernetesApplicationConfigurationFormValueOverridenKeyTypes;
|
|
|
|
this.ServiceTypes = KubernetesServiceTypes;
|
2021-09-07 00:37:26 +00:00
|
|
|
this.KubernetesDeploymentTypes = KubernetesDeploymentTypes;
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2023-02-07 03:33:57 +00:00
|
|
|
this.placementOptions = placementOptions;
|
|
|
|
|
2021-07-14 09:15:21 +00:00
|
|
|
this.state = {
|
2021-09-07 00:37:26 +00:00
|
|
|
appType: this.KubernetesDeploymentTypes.APPLICATION_FORM,
|
|
|
|
updateWebEditorInProgress: false,
|
2021-07-14 09:15:21 +00:00
|
|
|
actionInProgress: false,
|
|
|
|
useLoadBalancer: false,
|
|
|
|
useServerMetrics: false,
|
|
|
|
sliders: {
|
|
|
|
cpu: {
|
|
|
|
min: 0,
|
|
|
|
max: 0,
|
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
min: 0,
|
|
|
|
max: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodes: {
|
|
|
|
memory: 0,
|
|
|
|
cpu: 0,
|
|
|
|
},
|
2021-08-31 21:08:01 +00:00
|
|
|
namespaceLimits: {
|
|
|
|
memory: 0,
|
|
|
|
cpu: 0,
|
|
|
|
},
|
2021-07-14 09:15:21 +00:00
|
|
|
resourcePoolHasQuota: false,
|
|
|
|
viewReady: false,
|
|
|
|
availableSizeUnits: ['MB', 'GB', 'TB'],
|
|
|
|
alreadyExists: false,
|
|
|
|
duplicates: {
|
|
|
|
environmentVariables: new KubernetesFormValidationReferences(),
|
|
|
|
persistedFolders: new KubernetesFormValidationReferences(),
|
|
|
|
configurationPaths: new KubernetesFormValidationReferences(),
|
|
|
|
existingVolumes: new KubernetesFormValidationReferences(),
|
|
|
|
publishedPorts: {
|
|
|
|
containerPorts: new KubernetesFormValidationReferences(),
|
|
|
|
nodePorts: new KubernetesFormValidationReferences(),
|
|
|
|
ingressRoutes: new KubernetesFormValidationReferences(),
|
|
|
|
loadBalancerPorts: new KubernetesFormValidationReferences(),
|
|
|
|
},
|
|
|
|
placements: new KubernetesFormValidationReferences(),
|
|
|
|
},
|
|
|
|
isEdit: this.$state.params.namespace && this.$state.params.name,
|
|
|
|
persistedFoldersUseExistingVolumes: false,
|
|
|
|
pullImageValidity: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.isAdmin = this.Authentication.isAdmin();
|
|
|
|
|
|
|
|
this.editChanges = [];
|
|
|
|
|
|
|
|
this.storageClasses = [];
|
|
|
|
this.state.useLoadBalancer = false;
|
|
|
|
this.state.useServerMetrics = false;
|
|
|
|
|
|
|
|
this.formValues = new KubernetesApplicationFormValues();
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
this.updateApplicationAsync = this.updateApplicationAsync.bind(this);
|
|
|
|
this.deployApplicationAsync = this.deployApplicationAsync.bind(this);
|
2021-03-24 18:27:32 +00:00
|
|
|
this.setPullImageValidity = this.setPullImageValidity.bind(this);
|
2021-09-07 00:37:26 +00:00
|
|
|
this.onChangeFileContent = this.onChangeFileContent.bind(this);
|
2021-09-29 00:58:04 +00:00
|
|
|
this.onServicePublishChange = this.onServicePublishChange.bind(this);
|
2022-10-07 03:55:11 +00:00
|
|
|
this.checkIngressesToUpdate = this.checkIngressesToUpdate.bind(this);
|
|
|
|
this.confirmUpdateApplicationAsync = this.confirmUpdateApplicationAsync.bind(this);
|
2023-02-07 03:33:57 +00:00
|
|
|
this.onDataAccessPolicyChange = this.onDataAccessPolicyChange.bind(this);
|
|
|
|
this.onChangeDeploymentType = this.onChangeDeploymentType.bind(this);
|
|
|
|
this.supportGlobalDeployment = this.supportGlobalDeployment.bind(this);
|
|
|
|
this.onChangePlacementType = this.onChangePlacementType.bind(this);
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2023-02-07 03:33:57 +00:00
|
|
|
onChangePlacementType(value) {
|
|
|
|
this.$scope.$evalAsync(() => {
|
|
|
|
this.formValues.PlacementType = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeDeploymentType(value) {
|
|
|
|
this.$scope.$evalAsync(() => {
|
|
|
|
this.formValues.DeploymentType = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-07 00:37:26 +00:00
|
|
|
onChangeFileContent(value) {
|
|
|
|
if (this.stackFileContent.replace(/(\r\n|\n|\r)/gm, '') !== value.replace(/(\r\n|\n|\r)/gm, '')) {
|
|
|
|
this.state.isEditorDirty = true;
|
|
|
|
this.stackFileContent = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 03:33:57 +00:00
|
|
|
onDataAccessPolicyChange(value) {
|
|
|
|
this.$scope.$evalAsync(() => {
|
|
|
|
this.formValues.DataAccessPolicy = value;
|
|
|
|
this.resetDeploymentType();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-07 00:37:26 +00:00
|
|
|
async updateApplicationViaWebEditor() {
|
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
const confirmed = await this.ModalService.confirmAsync({
|
|
|
|
title: 'Are you sure?',
|
|
|
|
message: 'Any changes to this application will be overriden and may cause a service interruption. Do you wish to continue?',
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
label: 'Update',
|
|
|
|
className: 'btn-warning',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (!confirmed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.state.updateWebEditorInProgress = true;
|
|
|
|
await this.StackService.updateKubeStack({ EndpointId: this.endpoint.Id, Id: this.application.StackId }, this.stackFileContent, null);
|
|
|
|
this.state.isEditorDirty = false;
|
2021-09-24 08:21:50 +00:00
|
|
|
await this.$state.reload(this.$state.current);
|
2021-09-07 00:37:26 +00:00
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Failed redeploying application');
|
|
|
|
} finally {
|
|
|
|
this.state.updateWebEditorInProgress = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async uiCanExit() {
|
|
|
|
if (this.stackFileContent && this.state.isEditorDirty) {
|
|
|
|
return this.ModalService.confirmWebEditorDiscard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:27:32 +00:00
|
|
|
setPullImageValidity(validity) {
|
|
|
|
this.state.pullImageValidity = validity;
|
|
|
|
}
|
|
|
|
|
2021-10-19 00:21:54 +00:00
|
|
|
imageValidityIsValid() {
|
|
|
|
return this.state.pullImageValidity || this.formValues.ImageModel.Registry.Type !== RegistryTypes.DOCKERHUB;
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
onChangeName() {
|
|
|
|
const existingApplication = _.find(this.applications, { Name: this.formValues.Name });
|
|
|
|
this.state.alreadyExists = (this.state.isEdit && existingApplication && this.application.Id !== existingApplication.Id) || (!this.state.isEdit && existingApplication);
|
|
|
|
}
|
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
/* #region AUTO SCALER UI MANAGEMENT */
|
2020-08-04 22:08:11 +00:00
|
|
|
unselectAutoScaler() {
|
|
|
|
if (this.formValues.DeploymentType === this.ApplicationDeploymentTypes.GLOBAL) {
|
|
|
|
this.formValues.AutoScaler.IsUsed = false;
|
|
|
|
}
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-08-04 22:08:11 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region CONFIGURATION UI MANAGEMENT */
|
2020-07-05 23:21:03 +00:00
|
|
|
addConfiguration() {
|
|
|
|
let config = new KubernetesApplicationConfigurationFormValue();
|
|
|
|
config.SelectedConfiguration = this.configurations[0];
|
|
|
|
this.formValues.Configurations.push(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeConfiguration(index) {
|
|
|
|
this.formValues.Configurations.splice(index, 1);
|
|
|
|
this.onChangeConfigurationPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
overrideConfiguration(index) {
|
|
|
|
const config = this.formValues.Configurations[index];
|
|
|
|
config.Overriden = true;
|
|
|
|
config.OverridenKeys = _.map(_.keys(config.SelectedConfiguration.Data), (key) => {
|
|
|
|
const res = new KubernetesApplicationConfigurationFormValueOverridenKey();
|
|
|
|
res.Key = key;
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
resetConfiguration(index) {
|
|
|
|
const config = this.formValues.Configurations[index];
|
|
|
|
config.Overriden = false;
|
|
|
|
config.OverridenKeys = [];
|
|
|
|
this.onChangeConfigurationPath();
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
clearConfigurations() {
|
|
|
|
this.formValues.Configurations = [];
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
onChangeConfigurationPath() {
|
2020-08-12 23:30:23 +00:00
|
|
|
this.state.duplicates.configurationPaths.refs = [];
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
const paths = _.reduce(
|
|
|
|
this.formValues.Configurations,
|
|
|
|
(result, config) => {
|
|
|
|
const uniqOverridenKeysPath = _.uniq(_.map(config.OverridenKeys, 'Path'));
|
|
|
|
return _.concat(result, uniqOverridenKeysPath);
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
const duplicatePaths = KubernetesFormValidationHelper.getDuplicates(paths);
|
|
|
|
|
|
|
|
_.forEach(this.formValues.Configurations, (config, index) => {
|
|
|
|
_.forEach(config.OverridenKeys, (overridenKey, keyIndex) => {
|
|
|
|
const findPath = _.find(duplicatePaths, (path) => path === overridenKey.Path);
|
|
|
|
if (findPath) {
|
2020-08-12 23:30:23 +00:00
|
|
|
this.state.duplicates.configurationPaths.refs[index + '_' + keyIndex] = findPath;
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
this.state.duplicates.configurationPaths.hasRefs = Object.keys(this.state.duplicates.configurationPaths.refs).length > 0;
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region ENVIRONMENT UI MANAGEMENT */
|
2020-07-05 23:21:03 +00:00
|
|
|
addEnvironmentVariable() {
|
|
|
|
this.formValues.EnvironmentVariables.push(new KubernetesApplicationEnvironmentVariableFormValue());
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:46:26 +00:00
|
|
|
restoreEnvironmentVariable(item) {
|
|
|
|
item.NeedsDeletion = false;
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 13:46:26 +00:00
|
|
|
removeEnvironmentVariable(item) {
|
|
|
|
const index = this.formValues.EnvironmentVariables.indexOf(item);
|
|
|
|
if (index !== -1) {
|
|
|
|
const envVar = this.formValues.EnvironmentVariables[index];
|
|
|
|
if (!envVar.IsNew) {
|
|
|
|
envVar.NeedsDeletion = true;
|
|
|
|
} else {
|
|
|
|
this.formValues.EnvironmentVariables.splice(index, 1);
|
|
|
|
}
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
this.onChangeEnvironmentName();
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
onChangeEnvironmentName() {
|
|
|
|
this.state.duplicates.environmentVariables.refs = KubernetesFormValidationHelper.getDuplicates(_.map(this.formValues.EnvironmentVariables, 'Name'));
|
2021-02-26 15:50:33 +00:00
|
|
|
this.state.duplicates.environmentVariables.hasRefs = Object.keys(this.state.duplicates.environmentVariables.refs).length > 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region PERSISTENT FOLDERS UI MANAGEMENT */
|
2020-07-05 23:21:03 +00:00
|
|
|
addPersistedFolder() {
|
|
|
|
let storageClass = {};
|
|
|
|
if (this.storageClasses.length > 0) {
|
|
|
|
storageClass = this.storageClasses[0];
|
|
|
|
}
|
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
const newPf = new KubernetesApplicationPersistedFolderFormValue(storageClass);
|
|
|
|
this.formValues.PersistedFolders.push(newPf);
|
2020-07-05 23:21:03 +00:00
|
|
|
this.resetDeploymentType();
|
|
|
|
}
|
|
|
|
|
|
|
|
restorePersistedFolder(index) {
|
|
|
|
this.formValues.PersistedFolders[index].NeedsDeletion = false;
|
2021-02-26 15:50:33 +00:00
|
|
|
this.validatePersistedFolders();
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
resetPersistedFolders() {
|
|
|
|
this.formValues.PersistedFolders = _.forEach(this.formValues.PersistedFolders, (persistedFolder) => {
|
|
|
|
persistedFolder.ExistingVolume = null;
|
|
|
|
persistedFolder.UseNewVolume = true;
|
|
|
|
});
|
2021-02-26 15:50:33 +00:00
|
|
|
this.validatePersistedFolders();
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
removePersistedFolder(index) {
|
|
|
|
if (this.state.isEdit && this.formValues.PersistedFolders[index].PersistentVolumeClaimName) {
|
|
|
|
this.formValues.PersistedFolders[index].NeedsDeletion = true;
|
|
|
|
} else {
|
|
|
|
this.formValues.PersistedFolders.splice(index, 1);
|
|
|
|
}
|
2021-02-26 15:50:33 +00:00
|
|
|
this.validatePersistedFolders();
|
|
|
|
}
|
|
|
|
|
|
|
|
useNewVolume(index) {
|
|
|
|
this.formValues.PersistedFolders[index].UseNewVolume = true;
|
|
|
|
this.formValues.PersistedFolders[index].ExistingVolume = null;
|
|
|
|
this.state.persistedFoldersUseExistingVolumes = !_.reduce(this.formValues.PersistedFolders, (acc, pf) => acc && pf.UseNewVolume, true);
|
|
|
|
this.validatePersistedFolders();
|
|
|
|
}
|
|
|
|
|
|
|
|
useExistingVolume(index) {
|
|
|
|
this.formValues.PersistedFolders[index].UseNewVolume = false;
|
|
|
|
this.state.persistedFoldersUseExistingVolumes = _.find(this.formValues.PersistedFolders, { UseNewVolume: false }) ? true : false;
|
|
|
|
if (this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED) {
|
|
|
|
this.formValues.DataAccessPolicy = this.ApplicationDataAccessPolicies.SHARED;
|
|
|
|
this.resetDeploymentType();
|
|
|
|
}
|
|
|
|
this.validatePersistedFolders();
|
|
|
|
}
|
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region PERSISTENT FOLDERS ON CHANGE VALIDATION */
|
|
|
|
validatePersistedFolders() {
|
2020-07-05 23:21:03 +00:00
|
|
|
this.onChangePersistedFolderPath();
|
2020-08-07 04:40:24 +00:00
|
|
|
this.onChangeExistingVolumeSelection();
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
onChangePersistedFolderPath() {
|
|
|
|
this.state.duplicates.persistedFolders.refs = KubernetesFormValidationHelper.getDuplicates(
|
|
|
|
_.map(this.formValues.PersistedFolders, (persistedFolder) => {
|
|
|
|
if (persistedFolder.NeedsDeletion) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return persistedFolder.ContainerPath;
|
|
|
|
})
|
|
|
|
);
|
2021-02-26 15:50:33 +00:00
|
|
|
this.state.duplicates.persistedFolders.hasRefs = Object.keys(this.state.duplicates.persistedFolders.refs).length > 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onChangeExistingVolumeSelection() {
|
|
|
|
this.state.duplicates.existingVolumes.refs = KubernetesFormValidationHelper.getDuplicates(
|
|
|
|
_.map(this.formValues.PersistedFolders, (persistedFolder) => {
|
2021-02-26 15:50:33 +00:00
|
|
|
if (persistedFolder.NeedsDeletion) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
return persistedFolder.ExistingVolume ? persistedFolder.ExistingVolume.PersistentVolumeClaim.Name : '';
|
|
|
|
})
|
|
|
|
);
|
2021-02-26 15:50:33 +00:00
|
|
|
this.state.duplicates.existingVolumes.hasRefs = Object.keys(this.state.duplicates.existingVolumes.refs).length > 0;
|
2020-08-07 04:40:24 +00:00
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-08-07 04:40:24 +00:00
|
|
|
|
2020-08-13 23:56:53 +00:00
|
|
|
/* #region PLACEMENT UI MANAGEMENT */
|
|
|
|
addPlacement() {
|
|
|
|
const placement = new KubernetesApplicationPlacementFormValue();
|
|
|
|
const label = this.nodesLabels[0];
|
|
|
|
placement.Label = label;
|
|
|
|
placement.Value = label.Values[0];
|
|
|
|
this.formValues.Placements.push(placement);
|
2020-08-15 22:11:56 +00:00
|
|
|
this.onChangePlacement();
|
2020-08-13 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restorePlacement(index) {
|
|
|
|
this.formValues.Placements[index].NeedsDeletion = false;
|
2020-08-15 22:11:56 +00:00
|
|
|
this.onChangePlacement();
|
2020-08-13 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
removePlacement(index) {
|
|
|
|
if (this.state.isEdit && !this.formValues.Placements[index].IsNew) {
|
|
|
|
this.formValues.Placements[index].NeedsDeletion = true;
|
|
|
|
} else {
|
|
|
|
this.formValues.Placements.splice(index, 1);
|
|
|
|
}
|
2020-08-15 22:11:56 +00:00
|
|
|
this.onChangePlacement();
|
2020-08-13 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 22:11:56 +00:00
|
|
|
// call all validation functions when a placement is added/removed/restored
|
|
|
|
onChangePlacement() {
|
|
|
|
this.onChangePlacementLabelValidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePlacementLabel(index) {
|
2020-08-13 23:56:53 +00:00
|
|
|
this.formValues.Placements[index].Value = this.formValues.Placements[index].Label.Values[0];
|
2020-08-15 22:11:56 +00:00
|
|
|
this.onChangePlacementLabelValidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePlacementLabelValidate() {
|
|
|
|
const state = this.state.duplicates.placements;
|
|
|
|
const source = _.map(this.formValues.Placements, (p) => (p.NeedsDeletion ? undefined : p.Label.Key));
|
|
|
|
const duplicates = KubernetesFormValidationHelper.getDuplicates(source);
|
|
|
|
state.refs = duplicates;
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = Object.keys(duplicates).length > 0;
|
2020-08-13 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* #endregion */
|
|
|
|
|
2021-11-30 04:14:52 +00:00
|
|
|
/* #region PUBLISHED PORTS UI MANAGEMENT */
|
2021-09-29 00:58:04 +00:00
|
|
|
onServicePublishChange() {
|
2021-11-30 04:14:52 +00:00
|
|
|
// enable publishing with no previous ports exposed
|
|
|
|
if (this.formValues.IsPublishingService && !this.formValues.PublishedPorts.length) {
|
|
|
|
this.addPublishedPort();
|
2021-09-29 00:58:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// service update
|
|
|
|
if (this.formValues.IsPublishingService) {
|
|
|
|
this.formValues.PublishedPorts.forEach((port) => (port.NeedsDeletion = false));
|
|
|
|
} else {
|
2021-11-30 04:14:52 +00:00
|
|
|
// delete new ports, mark old ports to be deleted
|
2021-09-29 00:58:04 +00:00
|
|
|
this.formValues.PublishedPorts = this.formValues.PublishedPorts.filter((port) => !port.IsNew).map((port) => ({ ...port, NeedsDeletion: true }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
addPublishedPort() {
|
|
|
|
const p = new KubernetesApplicationPublishedPortFormValue();
|
2021-08-31 21:43:11 +00:00
|
|
|
const ingresses = this.ingresses;
|
2021-11-30 04:14:52 +00:00
|
|
|
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
|
|
|
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
|
|
|
|
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Hosts[0] : undefined;
|
|
|
|
p.IngressHosts = ingresses && ingresses.length ? ingresses[0].Hosts : undefined;
|
|
|
|
}
|
2021-01-15 01:51:36 +00:00
|
|
|
if (this.formValues.PublishedPorts.length) {
|
|
|
|
p.Protocol = this.formValues.PublishedPorts[0].Protocol;
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
this.formValues.PublishedPorts.push(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetPublishedPorts() {
|
2021-08-31 21:43:11 +00:00
|
|
|
const ingresses = this.ingresses;
|
2020-08-12 23:30:23 +00:00
|
|
|
_.forEach(this.formValues.PublishedPorts, (p) => {
|
|
|
|
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
|
2021-04-27 17:51:13 +00:00
|
|
|
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Hosts[0] : undefined;
|
2020-08-07 04:40:24 +00:00
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
restorePublishedPort(index) {
|
|
|
|
this.formValues.PublishedPorts[index].NeedsDeletion = false;
|
|
|
|
this.onChangePublishedPorts();
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
removePublishedPort(index) {
|
2020-08-12 23:30:23 +00:00
|
|
|
if (this.state.isEdit && !this.formValues.PublishedPorts[index].IsNew) {
|
|
|
|
this.formValues.PublishedPorts[index].NeedsDeletion = true;
|
|
|
|
} else {
|
|
|
|
this.formValues.PublishedPorts.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.onChangePublishedPorts();
|
|
|
|
}
|
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region PUBLISHED PORTS ON CHANGE VALIDATION */
|
|
|
|
onChangePublishedPorts() {
|
|
|
|
this.onChangePortMappingContainerPort();
|
|
|
|
this.onChangePortMappingNodePort();
|
|
|
|
this.onChangePortMappingIngressRoute();
|
|
|
|
this.onChangePortMappingLoadBalancer();
|
2021-01-15 01:51:36 +00:00
|
|
|
this.onChangePortProtocol();
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingContainerPort() {
|
|
|
|
const state = this.state.duplicates.publishedPorts.containerPorts;
|
|
|
|
if (this.formValues.PublishingType !== KubernetesApplicationPublishingTypes.INGRESS) {
|
|
|
|
const source = _.map(this.formValues.PublishedPorts, (p) => (p.NeedsDeletion ? undefined : p.ContainerPort + p.Protocol));
|
|
|
|
const duplicates = KubernetesFormValidationHelper.getDuplicates(source);
|
|
|
|
state.refs = duplicates;
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = Object.keys(duplicates).length > 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
} else {
|
|
|
|
state.refs = {};
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = false;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingNodePort() {
|
|
|
|
const state = this.state.duplicates.publishedPorts.nodePorts;
|
2021-09-29 00:58:04 +00:00
|
|
|
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.NODE_PORT) {
|
2020-08-12 23:30:23 +00:00
|
|
|
const source = _.map(this.formValues.PublishedPorts, (p) => (p.NeedsDeletion ? undefined : p.NodePort));
|
|
|
|
const duplicates = KubernetesFormValidationHelper.getDuplicates(source);
|
|
|
|
state.refs = duplicates;
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = Object.keys(duplicates).length > 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
} else {
|
|
|
|
state.refs = {};
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = false;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingIngress(index) {
|
|
|
|
const publishedPort = this.formValues.PublishedPorts[index];
|
2021-08-31 21:43:11 +00:00
|
|
|
const ingress = _.find(this.ingresses, { Name: publishedPort.IngressName });
|
2021-07-05 06:17:20 +00:00
|
|
|
publishedPort.IngressHosts = ingress.Hosts;
|
2021-04-27 17:51:13 +00:00
|
|
|
this.ingressHostnames = ingress.Hosts;
|
|
|
|
publishedPort.IngressHost = this.ingressHostnames.length ? this.ingressHostnames[0] : [];
|
2020-08-20 00:51:14 +00:00
|
|
|
this.onChangePublishedPorts();
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingIngressRoute() {
|
|
|
|
const state = this.state.duplicates.publishedPorts.ingressRoutes;
|
2020-08-20 00:51:14 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
2021-02-26 15:50:33 +00:00
|
|
|
const newRoutes = _.map(this.formValues.PublishedPorts, (p) => (p.IsNew && p.IngressRoute ? `${p.IngressHost || p.IngressName}${p.IngressRoute}` : undefined));
|
|
|
|
const toDelRoutes = _.map(this.formValues.PublishedPorts, (p) => (p.NeedsDeletion && p.IngressRoute ? `${p.IngressHost || p.IngressName}${p.IngressRoute}` : undefined));
|
|
|
|
const allRoutes = _.flatMap(this.ingresses, (i) => _.map(i.Paths, (p) => `${p.Host || i.Name}${p.Path}`));
|
2020-08-12 23:30:23 +00:00
|
|
|
const duplicates = KubernetesFormValidationHelper.getDuplicates(newRoutes);
|
|
|
|
_.forEach(newRoutes, (route, idx) => {
|
|
|
|
if (_.includes(allRoutes, route) && !_.includes(toDelRoutes, route)) {
|
|
|
|
duplicates[idx] = route;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
state.refs = duplicates;
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = Object.keys(duplicates).length > 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
} else {
|
|
|
|
state.refs = {};
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = false;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingLoadBalancer() {
|
|
|
|
const state = this.state.duplicates.publishedPorts.loadBalancerPorts;
|
|
|
|
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER) {
|
|
|
|
const source = _.map(this.formValues.PublishedPorts, (p) => (p.NeedsDeletion ? undefined : p.LoadBalancerPort));
|
|
|
|
const duplicates = KubernetesFormValidationHelper.getDuplicates(source);
|
|
|
|
state.refs = duplicates;
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = Object.keys(duplicates).length > 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
} else {
|
|
|
|
state.refs = {};
|
2021-02-26 15:50:33 +00:00
|
|
|
state.hasRefs = false;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 01:51:36 +00:00
|
|
|
|
|
|
|
onChangePortProtocol(index) {
|
|
|
|
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER) {
|
|
|
|
const newPorts = _.filter(this.formValues.PublishedPorts, { IsNew: true });
|
|
|
|
_.forEach(newPorts, (port) => {
|
|
|
|
port.Protocol = index ? this.formValues.PublishedPorts[index].Protocol : newPorts[0].Protocol;
|
|
|
|
});
|
2021-02-02 09:37:37 +00:00
|
|
|
this.onChangePortMappingLoadBalancer();
|
2021-01-15 01:51:36 +00:00
|
|
|
}
|
2021-02-02 09:37:37 +00:00
|
|
|
this.onChangePortMappingContainerPort();
|
2021-01-15 01:51:36 +00:00
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region STATE VALIDATION FUNCTIONS */
|
|
|
|
isValid() {
|
|
|
|
return (
|
|
|
|
!this.state.alreadyExists &&
|
2021-02-26 15:50:33 +00:00
|
|
|
!this.state.duplicates.environmentVariables.hasRefs &&
|
|
|
|
!this.state.duplicates.persistedFolders.hasRefs &&
|
|
|
|
!this.state.duplicates.configurationPaths.hasRefs &&
|
|
|
|
!this.state.duplicates.existingVolumes.hasRefs &&
|
|
|
|
!this.state.duplicates.publishedPorts.containerPorts.hasRefs &&
|
|
|
|
!this.state.duplicates.publishedPorts.nodePorts.hasRefs &&
|
|
|
|
!this.state.duplicates.publishedPorts.ingressRoutes.hasRefs &&
|
|
|
|
!this.state.duplicates.publishedPorts.loadBalancerPorts.hasRefs
|
2020-08-12 23:30:23 +00:00
|
|
|
);
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
storageClassAvailable() {
|
|
|
|
return this.storageClasses && this.storageClasses.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasMultipleStorageClassesAvailable() {
|
|
|
|
return this.storageClasses && this.storageClasses.length > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetDeploymentType() {
|
|
|
|
this.formValues.DeploymentType = this.ApplicationDeploymentTypes.REPLICATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The data access policy panel is not shown when:
|
|
|
|
// * There is not persisted folder specified
|
|
|
|
showDataAccessPolicySection() {
|
|
|
|
return this.formValues.PersistedFolders.length !== 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A global deployment is not available when either:
|
|
|
|
// * For each persisted folder specified, if one of the storage object only supports the RWO access mode
|
|
|
|
// * The data access policy is set to ISOLATED
|
|
|
|
supportGlobalDeployment() {
|
|
|
|
const hasFolders = this.formValues.PersistedFolders.length !== 0;
|
2021-02-22 19:05:43 +00:00
|
|
|
const hasRWOOnly = KubernetesApplicationHelper.hasRWOOnly(this.formValues);
|
2020-07-05 23:21:03 +00:00
|
|
|
const isIsolated = this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED;
|
|
|
|
|
2021-06-15 03:53:31 +00:00
|
|
|
if (hasFolders && (hasRWOOnly || isIsolated)) {
|
2020-07-05 23:21:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-02-07 03:33:57 +00:00
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A StatefulSet is defined by DataAccessPolicy === ISOLATED
|
|
|
|
isEditAndStatefulSet() {
|
|
|
|
return this.state.isEdit && this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A scalable deployment is available when either:
|
|
|
|
// * No persisted folders are specified
|
|
|
|
// * The access policy is set to shared and for each persisted folders specified, all the associated
|
|
|
|
// storage objects support at least RWX access mode (no RWO only)
|
|
|
|
// * The access policy is set to isolated
|
|
|
|
supportScalableReplicaDeployment() {
|
|
|
|
const hasFolders = this.formValues.PersistedFolders.length !== 0;
|
2021-02-22 19:05:43 +00:00
|
|
|
const hasRWOOnly = KubernetesApplicationHelper.hasRWOOnly(this.formValues);
|
2020-07-05 23:21:03 +00:00
|
|
|
const isIsolated = this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED;
|
|
|
|
|
|
|
|
if (!hasFolders || isIsolated || (hasFolders && !hasRWOOnly)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each persisted folders, returns the non scalable deployments options (storage class that only supports RWO)
|
|
|
|
getNonScalableStorage() {
|
|
|
|
let storageOptions = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < this.formValues.PersistedFolders.length; i++) {
|
|
|
|
const folder = this.formValues.PersistedFolders[i];
|
|
|
|
|
2021-02-22 19:05:43 +00:00
|
|
|
if (folder.StorageClass && _.isEqual(folder.StorageClass.AccessModes, ['RWO'])) {
|
2020-07-05 23:21:03 +00:00
|
|
|
storageOptions.push(folder.StorageClass.Name);
|
2021-02-26 15:50:33 +00:00
|
|
|
} else {
|
|
|
|
storageOptions.push('<no storage option available>');
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _.uniq(storageOptions).join(', ');
|
|
|
|
}
|
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
enforceReplicaCountMinimum() {
|
|
|
|
if (this.formValues.ReplicaCount === null) {
|
|
|
|
this.formValues.ReplicaCount = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
resourceQuotaCapacityExceeded() {
|
|
|
|
return !this.state.sliders.memory.max || !this.state.sliders.cpu.max;
|
|
|
|
}
|
|
|
|
|
2021-08-31 21:08:01 +00:00
|
|
|
nodeLimitsOverflow() {
|
|
|
|
const cpu = this.formValues.CpuLimit;
|
|
|
|
const memory = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
|
|
|
|
|
|
|
|
const overflow = this.nodesLimits.overflowForReplica(cpu, memory, 1);
|
|
|
|
|
|
|
|
return overflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
effectiveInstances() {
|
|
|
|
return this.formValues.DeploymentType === this.ApplicationDeploymentTypes.GLOBAL ? this.nodeNumber : this.formValues.ReplicaCount;
|
|
|
|
}
|
|
|
|
|
2022-10-11 21:06:57 +00:00
|
|
|
hasPortErrors() {
|
|
|
|
const portError = this.formValues.Services.some((service) => service.nodePortError || service.servicePortError);
|
|
|
|
return portError;
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
resourceReservationsOverflow() {
|
2021-08-31 21:08:01 +00:00
|
|
|
const instances = this.effectiveInstances();
|
2020-07-05 23:21:03 +00:00
|
|
|
const cpu = this.formValues.CpuLimit;
|
2021-08-31 21:08:01 +00:00
|
|
|
const maxCpu = this.state.namespaceLimits.cpu;
|
|
|
|
const memory = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
|
|
|
|
const maxMemory = this.state.namespaceLimits.memory;
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2021-08-31 21:08:01 +00:00
|
|
|
// multiply 1000 can avoid 0.1 * 3 > 0.3
|
|
|
|
if (cpu * 1000 * instances > maxCpu * 1000) {
|
2020-07-05 23:21:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memory * instances > maxMemory) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-31 21:08:01 +00:00
|
|
|
if (this.formValues.DeploymentType === this.ApplicationDeploymentTypes.REPLICATED) {
|
|
|
|
return this.nodesLimits.overflowForReplica(cpu, memory, instances);
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeploymentType == GLOBAL
|
|
|
|
return this.nodesLimits.overflowForGlobal(cpu, memory);
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 22:08:11 +00:00
|
|
|
autoScalerOverflow() {
|
|
|
|
const instances = this.formValues.AutoScaler.MaxReplicas;
|
|
|
|
const cpu = this.formValues.CpuLimit;
|
2021-08-31 21:08:01 +00:00
|
|
|
const maxCpu = this.state.namespaceLimits.cpu;
|
|
|
|
const memory = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
|
|
|
|
const maxMemory = this.state.namespaceLimits.memory;
|
2020-08-04 22:08:11 +00:00
|
|
|
|
2021-08-31 21:08:01 +00:00
|
|
|
// multiply 1000 can avoid 0.1 * 3 > 0.3
|
|
|
|
if (cpu * 1000 * instances > maxCpu * 1000) {
|
2020-08-04 22:08:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memory * instances > maxMemory) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-31 21:08:01 +00:00
|
|
|
return this.nodesLimits.overflowForReplica(cpu, memory, instances);
|
2020-08-04 22:08:11 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
publishViaLoadBalancerEnabled() {
|
2022-01-16 19:37:46 +00:00
|
|
|
return this.state.useLoadBalancer && this.state.maxLoadBalancersQuota !== 0;
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
publishViaIngressEnabled() {
|
2021-08-31 21:43:11 +00:00
|
|
|
return this.ingresses.length;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
isEditAndNoChangesMade() {
|
|
|
|
if (!this.state.isEdit) return false;
|
|
|
|
const changes = JsonPatch.compare(this.savedFormValues, this.formValues);
|
|
|
|
this.editChanges = _.filter(changes, (change) => !_.includes(change.path, '$$hashKey') && change.path !== '/ApplicationType');
|
|
|
|
return !this.editChanges.length;
|
|
|
|
}
|
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
/* #region PERSISTED FOLDERS */
|
|
|
|
/* #region BUTTONS STATES */
|
|
|
|
isAddPersistentFolderButtonShowed() {
|
|
|
|
return !this.isEditAndStatefulSet() && this.formValues.Containers.length <= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
isNewVolumeButtonDisabled(index) {
|
|
|
|
return this.isEditAndExistingPersistedFolder(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
isExistingVolumeButtonDisabled() {
|
|
|
|
return !this.hasAvailableVolumes() || (this.isEdit && this.application.ApplicationType === this.ApplicationTypes.STATEFULSET);
|
|
|
|
}
|
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
hasAvailableVolumes() {
|
|
|
|
return this.availableVolumes.length > 0;
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
isEditAndExistingPersistedFolder(index) {
|
|
|
|
return this.state.isEdit && this.formValues.PersistedFolders[index].PersistentVolumeClaimName;
|
|
|
|
}
|
2021-02-26 15:50:33 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
isEditAndNotNewPublishedPort(index) {
|
|
|
|
return this.state.isEdit && !this.formValues.PublishedPorts[index].IsNew;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:58:04 +00:00
|
|
|
hasNoPublishedPorts() {
|
|
|
|
return this.formValues.PublishedPorts.filter((port) => !port.NeedsDeletion).length === 0;
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 23:56:53 +00:00
|
|
|
isEditAndNotNewPlacement(index) {
|
|
|
|
return this.state.isEdit && !this.formValues.Placements[index].IsNew;
|
|
|
|
}
|
|
|
|
|
2021-01-15 01:51:36 +00:00
|
|
|
isNewAndNotFirst(index) {
|
|
|
|
return !this.state.isEdit && index !== 0;
|
|
|
|
}
|
|
|
|
|
2020-08-13 23:56:53 +00:00
|
|
|
showPlacementPolicySection() {
|
|
|
|
const placements = _.filter(this.formValues.Placements, { NeedsDeletion: false });
|
|
|
|
return placements.length !== 0;
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
isNonScalable() {
|
|
|
|
const scalable = this.supportScalableReplicaDeployment();
|
|
|
|
const global = this.supportGlobalDeployment();
|
|
|
|
const replica = this.formValues.ReplicaCount > 1;
|
|
|
|
const replicated = this.formValues.DeploymentType === this.ApplicationDeploymentTypes.REPLICATED;
|
|
|
|
const res = (replicated && !scalable && replica) || (!replicated && !global);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
isDeployUpdateButtonDisabled() {
|
|
|
|
const overflow = this.resourceReservationsOverflow();
|
2020-08-04 22:08:11 +00:00
|
|
|
const autoScalerOverflow = this.autoScalerOverflow();
|
2020-07-05 23:21:03 +00:00
|
|
|
const inProgress = this.state.actionInProgress;
|
|
|
|
const invalid = !this.isValid();
|
|
|
|
const hasNoChanges = this.isEditAndNoChangesMade();
|
|
|
|
const nonScalable = this.isNonScalable();
|
2021-09-29 00:58:04 +00:00
|
|
|
const isPublishingWithoutPorts = this.formValues.IsPublishingService && this.hasNoPublishedPorts();
|
|
|
|
return overflow || autoScalerOverflow || inProgress || invalid || hasNoChanges || nonScalable || isPublishingWithoutPorts;
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 19:37:46 +00:00
|
|
|
isExternalApplication() {
|
|
|
|
if (this.application) {
|
|
|
|
return KubernetesApplicationHelper.isExternalApplication(this.application);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
disableLoadBalancerEdit() {
|
|
|
|
return (
|
|
|
|
this.state.isEdit &&
|
|
|
|
this.application.ServiceType === this.ServiceTypes.LOAD_BALANCER &&
|
|
|
|
!this.application.LoadBalancerIPAddress &&
|
|
|
|
this.formValues.PublishingType === this.ApplicationPublishingTypes.LOAD_BALANCER
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
isPublishingTypeEditDisabled() {
|
|
|
|
const ports = _.filter(this.formValues.PublishedPorts, { IsNew: false, NeedsDeletion: false });
|
|
|
|
return this.state.isEdit && this.formValues.PublishedPorts.length > 0 && ports.length > 0;
|
|
|
|
}
|
|
|
|
|
2021-01-15 01:51:36 +00:00
|
|
|
isEditLBWithPorts() {
|
2021-09-21 04:20:22 +00:00
|
|
|
return this.formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER && _.filter(this.formValues.PublishedPorts, { IsNew: false }).length === 0;
|
2021-01-15 01:51:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
isProtocolOptionDisabled(index, protocol) {
|
2021-01-15 01:51:36 +00:00
|
|
|
return (
|
|
|
|
this.disableLoadBalancerEdit() ||
|
|
|
|
(this.isEditAndNotNewPublishedPort(index) && this.formValues.PublishedPorts[index].Protocol !== protocol) ||
|
2021-09-21 04:20:22 +00:00
|
|
|
(this.isEditLBWithPorts() && this.formValues.PublishedPorts[index].Protocol !== protocol && this.isNewAndNotFirst(index))
|
2021-01-15 01:51:36 +00:00
|
|
|
);
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region DATA AUTO REFRESH */
|
2023-02-10 05:28:53 +00:00
|
|
|
updateSliders(namespaceWithQuota) {
|
|
|
|
const quota = namespaceWithQuota.Quota;
|
2021-08-31 21:08:01 +00:00
|
|
|
let minCpu = 0,
|
|
|
|
minMemory = 0,
|
|
|
|
maxCpu = this.state.namespaceLimits.cpu,
|
|
|
|
maxMemory = this.state.namespaceLimits.memory;
|
|
|
|
|
|
|
|
if (quota) {
|
|
|
|
if (quota.CpuLimit) {
|
|
|
|
minCpu = KubernetesApplicationQuotaDefaults.CpuLimit;
|
|
|
|
}
|
|
|
|
if (quota.MemoryLimit) {
|
|
|
|
minMemory = KubernetesResourceReservationHelper.bytesValue(KubernetesApplicationQuotaDefaults.MemoryLimit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maxCpu = Math.min(maxCpu, this.nodesLimits.MaxCPU);
|
|
|
|
maxMemory = Math.min(maxMemory, this.nodesLimits.MaxMemory);
|
|
|
|
|
|
|
|
if (maxMemory < minMemory) {
|
|
|
|
minMemory = 0;
|
2021-02-26 15:50:33 +00:00
|
|
|
maxMemory = 0;
|
2021-08-31 21:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.state.sliders.memory.min = KubernetesResourceReservationHelper.megaBytesValue(minMemory);
|
|
|
|
this.state.sliders.memory.max = KubernetesResourceReservationHelper.megaBytesValue(maxMemory);
|
|
|
|
this.state.sliders.cpu.min = minCpu;
|
|
|
|
this.state.sliders.cpu.max = _.floor(maxCpu, 2);
|
|
|
|
if (!this.state.isEdit) {
|
|
|
|
this.formValues.CpuLimit = minCpu;
|
|
|
|
this.formValues.MemoryLimit = KubernetesResourceReservationHelper.megaBytesValue(minMemory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
updateNamespaceLimits(namespaceWithQuota) {
|
|
|
|
return this.$async(async () => {
|
|
|
|
let maxCpu = this.state.nodes.cpu;
|
|
|
|
let maxMemory = this.state.nodes.memory;
|
2021-08-31 21:08:01 +00:00
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
const quota = namespaceWithQuota.Quota;
|
2021-08-31 21:08:01 +00:00
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
this.state.resourcePoolHasQuota = false;
|
|
|
|
|
|
|
|
if (quota) {
|
|
|
|
if (quota.CpuLimit) {
|
|
|
|
this.state.resourcePoolHasQuota = true;
|
|
|
|
maxCpu = quota.CpuLimit - quota.CpuLimitUsed;
|
|
|
|
if (this.state.isEdit && this.savedFormValues.CpuLimit) {
|
|
|
|
maxCpu += this.savedFormValues.CpuLimit * this.effectiveInstances();
|
|
|
|
}
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
2021-08-31 21:08:01 +00:00
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
if (quota.MemoryLimit) {
|
|
|
|
this.state.resourcePoolHasQuota = true;
|
|
|
|
maxMemory = quota.MemoryLimit - quota.MemoryLimitUsed;
|
|
|
|
if (this.state.isEdit && this.savedFormValues.MemoryLimit) {
|
|
|
|
maxMemory += KubernetesResourceReservationHelper.bytesValue(this.savedFormValues.MemoryLimit) * this.effectiveInstances();
|
|
|
|
}
|
2021-02-26 15:50:33 +00:00
|
|
|
}
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
2021-08-31 21:08:01 +00:00
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
this.state.namespaceLimits.cpu = maxCpu;
|
|
|
|
this.state.namespaceLimits.memory = maxMemory;
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshStacks(namespace) {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
this.stacks = await this.KubernetesStackService.get(namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve stacks');
|
|
|
|
}
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshConfigurations(namespace) {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
this.configurations = await this.KubernetesConfigurationService.get(namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve configurations');
|
|
|
|
}
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshApplications(namespace) {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
this.applications = await this.KubernetesApplicationService.get(namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve applications');
|
|
|
|
}
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
refreshVolumes(namespace) {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
2022-03-08 12:14:23 +00:00
|
|
|
const storageClasses = this.endpoint.Kubernetes.Configuration.StorageClasses;
|
|
|
|
const volumes = await this.KubernetesVolumeService.get(namespace, storageClasses);
|
2021-02-26 15:50:33 +00:00
|
|
|
_.forEach(volumes, (volume) => {
|
|
|
|
volume.Applications = KubernetesVolumeHelper.getUsingApplications(volume, this.applications);
|
|
|
|
});
|
|
|
|
this.volumes = volumes;
|
|
|
|
const filteredVolumes = _.filter(this.volumes, (volume) => {
|
|
|
|
const isUnused = !KubernetesVolumeHelper.isUsed(volume);
|
|
|
|
const isRWX = volume.PersistentVolumeClaim.StorageClass && _.includes(volume.PersistentVolumeClaim.StorageClass.AccessModes, 'RWX');
|
|
|
|
return isUnused || isRWX;
|
|
|
|
});
|
|
|
|
this.availableVolumes = filteredVolumes;
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve volumes');
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshIngresses(namespace) {
|
2021-08-31 21:43:11 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
this.ingresses = await this.KubernetesIngressService.get(namespace);
|
|
|
|
this.ingressHostnames = this.ingresses.length ? this.ingresses[0].Hosts : [];
|
|
|
|
if (!this.publishViaIngressEnabled()) {
|
|
|
|
if (this.savedFormValues) {
|
|
|
|
this.formValues.PublishingType = this.savedFormValues.PublishingType;
|
|
|
|
} else {
|
2021-09-29 00:58:04 +00:00
|
|
|
this.formValues.PublishingType = this.ApplicationPublishingTypes.CLUSTER_IP;
|
2021-08-31 21:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.formValues.OriginalIngresses = this.ingresses;
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve ingresses');
|
2021-02-26 15:50:33 +00:00
|
|
|
}
|
2021-08-31 21:43:11 +00:00
|
|
|
});
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshNamespaceData(namespace) {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
await Promise.all([
|
|
|
|
this.refreshStacks(namespace),
|
|
|
|
this.refreshConfigurations(namespace),
|
|
|
|
this.refreshApplications(namespace),
|
|
|
|
this.refreshIngresses(namespace),
|
|
|
|
this.refreshVolumes(namespace),
|
|
|
|
]);
|
|
|
|
this.onChangeName();
|
|
|
|
});
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resetFormValues() {
|
|
|
|
this.clearConfigurations();
|
|
|
|
this.resetPersistedFolders();
|
|
|
|
this.resetPublishedPorts();
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onResourcePoolSelectionChange() {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
2023-02-10 05:28:53 +00:00
|
|
|
const namespaceWithQuota = await this.KubernetesResourcePoolService.get(this.formValues.ResourcePool.Namespace.Name);
|
2021-02-26 15:50:33 +00:00
|
|
|
const namespace = this.formValues.ResourcePool.Namespace.Name;
|
2023-02-10 05:28:53 +00:00
|
|
|
this.updateNamespaceLimits(namespaceWithQuota);
|
|
|
|
this.updateSliders(namespaceWithQuota);
|
2021-02-26 15:50:33 +00:00
|
|
|
await this.refreshNamespaceData(namespace);
|
|
|
|
this.resetFormValues();
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region ACTIONS */
|
2020-07-05 23:21:03 +00:00
|
|
|
async deployApplicationAsync() {
|
|
|
|
this.state.actionInProgress = true;
|
|
|
|
try {
|
|
|
|
this.formValues.ApplicationOwner = this.Authentication.getUserDetails().username;
|
|
|
|
_.remove(this.formValues.Configurations, (item) => item.SelectedConfiguration === undefined);
|
|
|
|
await this.KubernetesApplicationService.create(this.formValues);
|
|
|
|
this.Notifications.success('Application successfully deployed', this.formValues.Name);
|
|
|
|
this.$state.go('kubernetes.applications');
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to create application');
|
|
|
|
} finally {
|
|
|
|
this.state.actionInProgress = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 03:55:11 +00:00
|
|
|
async updateApplicationAsync(ingressesToUpdate, rulePlural) {
|
|
|
|
if (ingressesToUpdate.length) {
|
|
|
|
try {
|
|
|
|
await Promise.all(ingressesToUpdate.map((ing) => updateIngress(this.endpoint.Id, ing)));
|
|
|
|
this.Notifications.success('Success', `Ingress ${rulePlural} successfully updated`);
|
|
|
|
} catch (error) {
|
|
|
|
this.Notifications.error('Failure', error, 'Unable to update ingress');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
try {
|
|
|
|
this.state.actionInProgress = true;
|
|
|
|
await this.KubernetesApplicationService.patch(this.savedFormValues, this.formValues);
|
2022-08-10 05:07:35 +00:00
|
|
|
this.Notifications.success('Success', 'Application successfully updated');
|
2020-07-05 23:21:03 +00:00
|
|
|
this.$state.go('kubernetes.applications.application', { name: this.application.Name, namespace: this.application.ResourcePool });
|
|
|
|
} catch (err) {
|
2020-08-12 23:30:23 +00:00
|
|
|
this.Notifications.error('Failure', err, 'Unable to update application');
|
2020-07-05 23:21:03 +00:00
|
|
|
} finally {
|
|
|
|
this.state.actionInProgress = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 03:55:11 +00:00
|
|
|
async confirmUpdateApplicationAsync() {
|
|
|
|
const [ingressesToUpdate, servicePortsToUpdate] = await this.checkIngressesToUpdate();
|
|
|
|
// if there is an ingressesToUpdate, then show a warning modal with asking if they want to update the ingresses
|
|
|
|
if (ingressesToUpdate.length) {
|
|
|
|
const rulePlural = ingressesToUpdate.length > 1 ? 'rules' : 'rule';
|
|
|
|
const noMatchSentence =
|
|
|
|
servicePortsToUpdate.length > 1
|
|
|
|
? `Service ports in this application no longer match the ingress ${rulePlural}.`
|
|
|
|
: `A service port in this application no longer matches the ingress ${rulePlural} which may break ingress rule paths.`;
|
|
|
|
const message = `
|
|
|
|
<ul class="ml-3">
|
|
|
|
<li>Updating the application may cause a service interruption.</li>
|
|
|
|
<li>${noMatchSentence}</li>
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
const inputLabel = `Update ingress ${rulePlural} to match the service port changes`;
|
|
|
|
confirmUpdateAppIngress(`Are you sure?`, message, inputLabel, (value) => {
|
|
|
|
if (value === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (value.length === 0) {
|
|
|
|
return this.$async(this.updateApplicationAsync, [], '');
|
|
|
|
}
|
|
|
|
if (value[0] === '1') {
|
|
|
|
return this.$async(this.updateApplicationAsync, ingressesToUpdate, rulePlural);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2020-07-05 23:21:03 +00:00
|
|
|
this.ModalService.confirmUpdate('Updating the application may cause a service interruption. Do you wish to continue?', (confirmed) => {
|
|
|
|
if (confirmed) {
|
2022-10-07 03:55:11 +00:00
|
|
|
return this.$async(this.updateApplicationAsync, [], '');
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
});
|
2022-10-07 03:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if service ports with ingresses have changed and allow the user to update the ingress to the new port values with a modal
|
|
|
|
async checkIngressesToUpdate() {
|
|
|
|
let ingressesToUpdate = [];
|
|
|
|
let servicePortsToUpdate = [];
|
|
|
|
const fullIngresses = await getIngresses(this.endpoint.Id, this.formValues.ResourcePool.Namespace.Name);
|
|
|
|
this.formValues.Services.forEach((updatedService) => {
|
|
|
|
const oldServiceIndex = this.oldFormValues.Services.findIndex((oldService) => oldService.Name === updatedService.Name);
|
|
|
|
const numberOfPortsInOldService = this.oldFormValues.Services[oldServiceIndex] && this.oldFormValues.Services[oldServiceIndex].Ports.length;
|
|
|
|
// if the service has an ingress and there is the same number of ports or more in the updated service
|
|
|
|
if (updatedService.Ingress && numberOfPortsInOldService && numberOfPortsInOldService <= updatedService.Ports.length) {
|
|
|
|
const updatedOldPorts = updatedService.Ports.slice(0, numberOfPortsInOldService);
|
|
|
|
const ingressesForService = fullIngresses.filter((ing) => {
|
|
|
|
const ingServiceNames = ing.Paths.map((path) => path.ServiceName);
|
|
|
|
if (ingServiceNames.includes(updatedService.Name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ingressesForService.forEach((ingressForService) => {
|
|
|
|
updatedOldPorts.forEach((servicePort, pIndex) => {
|
|
|
|
if (servicePort.ingress) {
|
|
|
|
// if there isn't a ingress path that has a matching service name and port
|
|
|
|
const doesIngressPathMatchServicePort = ingressForService.Paths.find((ingPath) => ingPath.ServiceName === updatedService.Name && ingPath.Port === servicePort.port);
|
|
|
|
if (!doesIngressPathMatchServicePort) {
|
|
|
|
// then find the ingress path index to update by looking for the matching port in the old form values
|
|
|
|
const oldServicePort = this.oldFormValues.Services[oldServiceIndex].Ports[pIndex].port;
|
|
|
|
const newServicePort = servicePort.port;
|
|
|
|
|
|
|
|
const ingressPathIndex = ingressForService.Paths.findIndex((ingPath) => {
|
|
|
|
return ingPath.ServiceName === updatedService.Name && ingPath.Port === oldServicePort;
|
|
|
|
});
|
|
|
|
if (ingressPathIndex !== -1) {
|
|
|
|
// if the ingress to update isn't in the ingressesToUpdate list
|
|
|
|
const ingressUpdateIndex = ingressesToUpdate.findIndex((ing) => ing.Name === ingressForService.Name);
|
|
|
|
if (ingressUpdateIndex === -1) {
|
|
|
|
// then add it to the list with the new port
|
|
|
|
const ingressToUpdate = angular.copy(ingressForService);
|
|
|
|
ingressToUpdate.Paths[ingressPathIndex].Port = newServicePort;
|
|
|
|
ingressesToUpdate.push(ingressToUpdate);
|
|
|
|
} else {
|
|
|
|
// if the ingress is already in the list, then update the path with the new port
|
|
|
|
ingressesToUpdate[ingressUpdateIndex].Paths[ingressPathIndex].Port = newServicePort;
|
|
|
|
}
|
|
|
|
if (!servicePortsToUpdate.includes(newServicePort)) {
|
|
|
|
servicePortsToUpdate.push(newServicePort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return [ingressesToUpdate, servicePortsToUpdate];
|
|
|
|
}
|
|
|
|
|
|
|
|
deployApplication() {
|
|
|
|
if (this.state.isEdit) {
|
|
|
|
return this.$async(this.confirmUpdateApplicationAsync);
|
2020-07-05 23:21:03 +00:00
|
|
|
} else {
|
|
|
|
return this.$async(this.deployApplicationAsync);
|
|
|
|
}
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region APPLICATION - used on edit context only */
|
2020-07-05 23:21:03 +00:00
|
|
|
getApplication() {
|
2021-02-26 15:50:33 +00:00
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
2021-07-14 09:15:21 +00:00
|
|
|
const namespace = this.$state.params.namespace;
|
2022-03-08 12:14:23 +00:00
|
|
|
const storageClasses = this.endpoint.Kubernetes.Configuration.StorageClasses;
|
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
[this.application, this.persistentVolumeClaims] = await Promise.all([
|
2021-07-14 09:15:21 +00:00
|
|
|
this.KubernetesApplicationService.get(namespace, this.$state.params.name),
|
2022-03-08 12:14:23 +00:00
|
|
|
this.KubernetesPersistentVolumeClaimService.get(namespace, storageClasses),
|
2021-02-26 15:50:33 +00:00
|
|
|
]);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve application details');
|
|
|
|
}
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
2021-07-14 09:15:21 +00:00
|
|
|
|
|
|
|
async parseImageConfiguration(imageModel) {
|
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
return await this.RegistryService.retrievePorRegistryModelFromRepository(imageModel.Image, this.endpoint.Id, imageModel.Registry.Id, this.$state.params.namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve registry');
|
|
|
|
return imageModel;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region ON INIT */
|
2021-02-26 15:50:33 +00:00
|
|
|
$onInit() {
|
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
2021-07-14 09:15:21 +00:00
|
|
|
this.storageClasses = this.endpoint.Kubernetes.Configuration.StorageClasses;
|
|
|
|
this.state.useLoadBalancer = this.endpoint.Kubernetes.Configuration.UseLoadBalancer;
|
|
|
|
this.state.useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics;
|
2021-02-26 15:50:33 +00:00
|
|
|
|
2021-08-31 21:43:11 +00:00
|
|
|
const [resourcePools, nodes, nodesLimits] = await Promise.all([
|
2021-02-26 15:50:33 +00:00
|
|
|
this.KubernetesResourcePoolService.get(),
|
|
|
|
this.KubernetesNodeService.get(),
|
2021-08-31 21:08:01 +00:00
|
|
|
this.KubernetesNodesLimitsService.get(),
|
2021-02-26 15:50:33 +00:00
|
|
|
]);
|
2021-08-31 21:08:01 +00:00
|
|
|
this.nodesLimits = nodesLimits;
|
2021-02-26 15:50:33 +00:00
|
|
|
|
2021-10-06 22:06:53 +00:00
|
|
|
const nonSystemNamespaces = _.filter(resourcePools, (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name));
|
|
|
|
|
2022-10-11 21:06:57 +00:00
|
|
|
this.allNamespaces = resourcePools.map(({ Namespace }) => Namespace.Name);
|
2021-10-06 22:06:53 +00:00
|
|
|
this.resourcePools = _.sortBy(nonSystemNamespaces, ({ Namespace }) => (Namespace.Name === 'default' ? 0 : 1));
|
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
const namespaceWithQuota = await this.KubernetesResourcePoolService.get(this.resourcePools[0].Namespace.Name);
|
2021-02-26 15:50:33 +00:00
|
|
|
this.formValues.ResourcePool = this.resourcePools[0];
|
2023-02-10 05:28:53 +00:00
|
|
|
this.formValues.ResourcePool.Quota = namespaceWithQuota.Quota;
|
2021-02-26 15:50:33 +00:00
|
|
|
if (!this.formValues.ResourcePool) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
|
2021-02-26 15:50:33 +00:00
|
|
|
_.forEach(nodes, (item) => {
|
|
|
|
this.state.nodes.memory += filesizeParser(item.Memory);
|
|
|
|
this.state.nodes.cpu += item.CPU;
|
2020-08-12 23:30:23 +00:00
|
|
|
});
|
2021-02-26 15:50:33 +00:00
|
|
|
this.nodesLabels = KubernetesNodeHelper.generateNodeLabelsFromNodes(nodes);
|
2021-08-31 21:08:01 +00:00
|
|
|
this.nodeNumber = nodes.length;
|
2021-02-26 15:50:33 +00:00
|
|
|
|
2021-07-14 09:15:21 +00:00
|
|
|
const namespace = this.state.isEdit ? this.$state.params.namespace : this.formValues.ResourcePool.Namespace.Name;
|
2021-02-26 15:50:33 +00:00
|
|
|
await this.refreshNamespaceData(namespace);
|
|
|
|
|
|
|
|
if (this.state.isEdit) {
|
|
|
|
await this.getApplication();
|
|
|
|
this.formValues = KubernetesApplicationConverter.applicationToFormValues(
|
|
|
|
this.application,
|
|
|
|
this.resourcePools,
|
|
|
|
this.configurations,
|
|
|
|
this.persistentVolumeClaims,
|
2021-07-05 06:17:20 +00:00
|
|
|
this.nodesLabels,
|
2021-08-31 21:43:11 +00:00
|
|
|
this.ingresses
|
2021-02-26 15:50:33 +00:00
|
|
|
);
|
2021-09-07 00:37:26 +00:00
|
|
|
|
|
|
|
if (this.application.ApplicationKind) {
|
2021-09-22 04:59:28 +00:00
|
|
|
this.state.appType = KubernetesDeploymentTypes[this.application.ApplicationKind.toUpperCase()];
|
|
|
|
if (this.application.ApplicationKind === KubernetesDeploymentTypes.URL) {
|
|
|
|
this.state.appType = KubernetesDeploymentTypes.CONTENT;
|
|
|
|
}
|
|
|
|
|
2021-09-07 00:37:26 +00:00
|
|
|
if (this.application.StackId) {
|
|
|
|
this.stack = await this.StackService.stack(this.application.StackId);
|
2021-09-22 04:59:28 +00:00
|
|
|
if (this.state.appType === KubernetesDeploymentTypes.CONTENT) {
|
2021-09-07 00:37:26 +00:00
|
|
|
this.stackFileContent = await this.StackService.getStackFile(this.application.StackId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-31 21:43:11 +00:00
|
|
|
this.formValues.OriginalIngresses = this.ingresses;
|
2021-07-14 09:15:21 +00:00
|
|
|
this.formValues.ImageModel = await this.parseImageConfiguration(this.formValues.ImageModel);
|
2021-02-26 15:50:33 +00:00
|
|
|
this.savedFormValues = angular.copy(this.formValues);
|
|
|
|
delete this.formValues.ApplicationType;
|
|
|
|
|
|
|
|
if (this.application.ApplicationType !== KubernetesApplicationTypes.STATEFULSET) {
|
|
|
|
_.forEach(this.formValues.PersistedFolders, (persistedFolder) => {
|
|
|
|
const volume = _.find(this.availableVolumes, ['PersistentVolumeClaim.Name', persistedFolder.PersistentVolumeClaimName]);
|
|
|
|
if (volume) {
|
|
|
|
persistedFolder.UseNewVolume = false;
|
|
|
|
persistedFolder.ExistingVolume = volume;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await this.refreshNamespaceData(namespace);
|
|
|
|
} else {
|
|
|
|
this.formValues.AutoScaler = KubernetesApplicationHelper.generateAutoScalerFormValueFromHorizontalPodAutoScaler(null, this.formValues.ReplicaCount);
|
2020-08-07 04:40:24 +00:00
|
|
|
}
|
2021-08-31 21:08:01 +00:00
|
|
|
|
|
|
|
if (this.state.isEdit) {
|
|
|
|
this.nodesLimits.excludesPods(this.application.Pods, this.formValues.CpuLimit, KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit));
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:58:04 +00:00
|
|
|
this.formValues.IsPublishingService = this.formValues.PublishedPorts.length > 0;
|
|
|
|
|
2022-10-07 03:55:11 +00:00
|
|
|
this.oldFormValues = angular.copy(this.formValues);
|
|
|
|
|
2023-02-10 05:28:53 +00:00
|
|
|
this.updateNamespaceLimits(namespaceWithQuota);
|
|
|
|
this.updateSliders(namespaceWithQuota);
|
2021-02-26 15:50:33 +00:00
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to load view data');
|
|
|
|
} finally {
|
|
|
|
this.state.viewReady = true;
|
|
|
|
}
|
|
|
|
});
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default KubernetesCreateApplicationController;
|
|
|
|
angular.module('portainer.kubernetes').controller('KubernetesCreateApplicationController', KubernetesCreateApplicationController);
|