2020-07-05 23:21:03 +00:00
|
|
|
import angular from 'angular';
|
2020-08-12 23:30:23 +00:00
|
|
|
import * as _ from 'lodash-es';
|
2020-07-05 23:21:03 +00:00
|
|
|
import filesizeParser from 'filesize-parser';
|
|
|
|
import * as JsonPatch from 'fast-json-patch';
|
|
|
|
|
|
|
|
import {
|
|
|
|
KubernetesApplicationDataAccessPolicies,
|
|
|
|
KubernetesApplicationDeploymentTypes,
|
|
|
|
KubernetesApplicationPublishingTypes,
|
|
|
|
KubernetesApplicationQuotaDefaults,
|
2020-08-07 04:40:24 +00:00
|
|
|
KubernetesApplicationTypes,
|
2020-08-13 23:56:53 +00:00
|
|
|
KubernetesApplicationPlacementTypes,
|
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,
|
2020-08-20 00:51:14 +00:00
|
|
|
KubernetesFormValueDuplicate,
|
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';
|
2020-08-13 23:56:53 +00:00
|
|
|
import { KubernetesNodeHelper } from 'Kubernetes/node/helper';
|
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(
|
|
|
|
$async,
|
|
|
|
$state,
|
|
|
|
Notifications,
|
|
|
|
EndpointProvider,
|
|
|
|
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,
|
2020-08-07 04:40:24 +00:00
|
|
|
KubernetesNamespaceHelper,
|
|
|
|
KubernetesVolumeService
|
2020-07-05 23:21:03 +00:00
|
|
|
) {
|
|
|
|
this.$async = $async;
|
|
|
|
this.$state = $state;
|
|
|
|
this.Notifications = Notifications;
|
|
|
|
this.EndpointProvider = EndpointProvider;
|
|
|
|
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;
|
2020-07-14 05:39:13 +00:00
|
|
|
this.KubernetesNamespaceHelper = KubernetesNamespaceHelper;
|
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;
|
|
|
|
|
|
|
|
this.onInit = this.onInit.bind(this);
|
|
|
|
this.updateApplicationAsync = this.updateApplicationAsync.bind(this);
|
|
|
|
this.deployApplicationAsync = this.deployApplicationAsync.bind(this);
|
|
|
|
this.updateSlidersAsync = this.updateSlidersAsync.bind(this);
|
|
|
|
this.refreshStacksAsync = this.refreshStacksAsync.bind(this);
|
|
|
|
this.refreshConfigurationsAsync = this.refreshConfigurationsAsync.bind(this);
|
|
|
|
this.refreshApplicationsAsync = this.refreshApplicationsAsync.bind(this);
|
2020-08-12 23:30:23 +00:00
|
|
|
this.refreshNamespaceDataAsync = this.refreshNamespaceDataAsync.bind(this);
|
2020-07-05 23:21:03 +00:00
|
|
|
this.getApplicationAsync = this.getApplicationAsync.bind(this);
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
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);
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region AUTO SCLAER 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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
this.state.duplicates.configurationPaths.hasDuplicates = 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
restoreEnvironmentVariable(index) {
|
|
|
|
this.formValues.EnvironmentVariables[index].NeedsDeletion = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
removeEnvironmentVariable(index) {
|
|
|
|
if (this.state.isEdit && !this.formValues.EnvironmentVariables[index].IsNew) {
|
|
|
|
this.formValues.EnvironmentVariables[index].NeedsDeletion = true;
|
|
|
|
} else {
|
|
|
|
this.formValues.EnvironmentVariables.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.onChangeEnvironmentName();
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
onChangeEnvironmentName() {
|
|
|
|
this.state.duplicates.environmentVariables.refs = KubernetesFormValidationHelper.getDuplicates(_.map(this.formValues.EnvironmentVariables, 'Name'));
|
|
|
|
this.state.duplicates.environmentVariables.hasDuplicates = Object.keys(this.state.duplicates.environmentVariables.refs).length > 0;
|
|
|
|
}
|
|
|
|
/* #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];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.formValues.PersistedFolders.push(new KubernetesApplicationPersistedFolderFormValue(storageClass));
|
|
|
|
this.resetDeploymentType();
|
|
|
|
}
|
|
|
|
|
|
|
|
restorePersistedFolder(index) {
|
|
|
|
this.formValues.PersistedFolders[index].NeedsDeletion = false;
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
resetPersistedFolders() {
|
|
|
|
this.formValues.PersistedFolders = _.forEach(this.formValues.PersistedFolders, (persistedFolder) => {
|
|
|
|
persistedFolder.ExistingVolume = null;
|
|
|
|
persistedFolder.UseNewVolume = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.state.duplicates.persistedFolders.hasDuplicates = Object.keys(this.state.duplicates.persistedFolders.refs).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeExistingVolumeSelection() {
|
|
|
|
this.state.duplicates.existingVolumes.refs = KubernetesFormValidationHelper.getDuplicates(
|
|
|
|
_.map(this.formValues.PersistedFolders, (persistedFolder) => {
|
|
|
|
return persistedFolder.ExistingVolume ? persistedFolder.ExistingVolume.PersistentVolumeClaim.Name : '';
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.state.duplicates.existingVolumes.hasDuplicates = Object.keys(this.state.duplicates.existingVolumes.refs).length > 0;
|
2020-08-07 04:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
state.hasDuplicates = Object.keys(duplicates).length > 0;
|
2020-08-13 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* #endregion */
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #region PUBLISHED PORTS UI MANAGEMENT */
|
|
|
|
addPublishedPort() {
|
|
|
|
const p = new KubernetesApplicationPublishedPortFormValue();
|
|
|
|
const ingresses = this.filteredIngresses;
|
|
|
|
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
|
|
|
|
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Host : 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() {
|
|
|
|
const ingresses = this.filteredIngresses;
|
|
|
|
_.forEach(this.formValues.PublishedPorts, (p) => {
|
|
|
|
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
|
|
|
|
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Host : 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;
|
|
|
|
state.hasDuplicates = Object.keys(duplicates).length > 0;
|
|
|
|
} else {
|
|
|
|
state.refs = {};
|
|
|
|
state.hasDuplicates = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingNodePort() {
|
|
|
|
const state = this.state.duplicates.publishedPorts.nodePorts;
|
|
|
|
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.CLUSTER) {
|
|
|
|
const source = _.map(this.formValues.PublishedPorts, (p) => (p.NeedsDeletion ? undefined : p.NodePort));
|
|
|
|
const duplicates = KubernetesFormValidationHelper.getDuplicates(source);
|
|
|
|
state.refs = duplicates;
|
|
|
|
state.hasDuplicates = Object.keys(duplicates).length > 0;
|
|
|
|
} else {
|
|
|
|
state.refs = {};
|
|
|
|
state.hasDuplicates = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePortMappingIngress(index) {
|
|
|
|
const publishedPort = this.formValues.PublishedPorts[index];
|
|
|
|
const ingress = _.find(this.filteredIngresses, { Name: publishedPort.IngressName });
|
|
|
|
publishedPort.IngressHost = ingress.Host;
|
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) {
|
2020-08-20 00:51:14 +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;
|
|
|
|
state.hasDuplicates = Object.keys(duplicates).length > 0;
|
|
|
|
} else {
|
|
|
|
state.refs = {};
|
|
|
|
state.hasDuplicates = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
state.hasDuplicates = Object.keys(duplicates).length > 0;
|
|
|
|
} else {
|
|
|
|
state.refs = {};
|
|
|
|
state.hasDuplicates = false;
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 01:51:36 +00:00
|
|
|
|
|
|
|
onChangePortProtocol(index) {
|
|
|
|
this.onChangePortMappingContainerPort();
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-08-12 23:30:23 +00:00
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region STATE VALIDATION FUNCTIONS */
|
|
|
|
isValid() {
|
|
|
|
return (
|
|
|
|
!this.state.alreadyExists &&
|
|
|
|
!this.state.duplicates.environmentVariables.hasDuplicates &&
|
|
|
|
!this.state.duplicates.persistedFolders.hasDuplicates &&
|
|
|
|
!this.state.duplicates.configurationPaths.hasDuplicates &&
|
|
|
|
!this.state.duplicates.existingVolumes.hasDuplicates &&
|
|
|
|
!this.state.duplicates.publishedPorts.containerPorts.hasDuplicates &&
|
|
|
|
!this.state.duplicates.publishedPorts.nodePorts.hasDuplicates &&
|
|
|
|
!this.state.duplicates.publishedPorts.ingressRoutes.hasDuplicates &&
|
|
|
|
!this.state.duplicates.publishedPorts.loadBalancerPorts.hasDuplicates
|
|
|
|
);
|
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;
|
|
|
|
const hasRWOOnly = _.find(this.formValues.PersistedFolders, (item) => _.isEqual(item.StorageClass.AccessModes, ['RWO']));
|
|
|
|
const isIsolated = this.formValues.DataAccessPolicy === this.ApplicationDataAccessPolicies.ISOLATED;
|
|
|
|
|
|
|
|
if ((hasFolders && hasRWOOnly) || isIsolated) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
const hasRWOOnly = _.find(this.formValues.PersistedFolders, (item) => _.isEqual(item.StorageClass.AccessModes, ['RWO']));
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (_.isEqual(folder.StorageClass.AccessModes, ['RWO'])) {
|
|
|
|
storageOptions.push(folder.StorageClass.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _.uniq(storageOptions).join(', ');
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceQuotaCapacityExceeded() {
|
|
|
|
return !this.state.sliders.memory.max || !this.state.sliders.cpu.max;
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceReservationsOverflow() {
|
|
|
|
const instances = this.formValues.ReplicaCount;
|
|
|
|
const cpu = this.formValues.CpuLimit;
|
|
|
|
const maxCpu = this.state.sliders.cpu.max;
|
|
|
|
const memory = this.formValues.MemoryLimit;
|
|
|
|
const maxMemory = this.state.sliders.memory.max;
|
|
|
|
|
|
|
|
if (cpu * instances > maxCpu) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memory * instances > maxMemory) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-04 22:08:11 +00:00
|
|
|
autoScalerOverflow() {
|
|
|
|
const instances = this.formValues.AutoScaler.MaxReplicas;
|
|
|
|
const cpu = this.formValues.CpuLimit;
|
|
|
|
const maxCpu = this.state.sliders.cpu.max;
|
|
|
|
const memory = this.formValues.MemoryLimit;
|
|
|
|
const maxMemory = this.state.sliders.memory.max;
|
|
|
|
|
|
|
|
if (cpu * instances > maxCpu) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memory * instances > maxMemory) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
publishViaLoadBalancerEnabled() {
|
|
|
|
return this.state.useLoadBalancer;
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
publishViaIngressEnabled() {
|
|
|
|
return this.filteredIngresses.length;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
isEditAndExistingPersistedFolder(index) {
|
|
|
|
return this.state.isEdit && this.formValues.PersistedFolders[index].PersistentVolumeClaimName;
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
isEditAndNotNewPublishedPort(index) {
|
|
|
|
return this.state.isEdit && !this.formValues.PublishedPorts[index].IsNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
isNotInternalAndHasNoPublishedPorts() {
|
|
|
|
const toDelPorts = _.filter(this.formValues.PublishedPorts, { NeedsDeletion: true });
|
|
|
|
const toKeepPorts = _.without(this.formValues.PublishedPorts, ...toDelPorts);
|
|
|
|
return this.formValues.PublishingType !== KubernetesApplicationPublishingTypes.INTERNAL && toKeepPorts.length === 0;
|
|
|
|
}
|
|
|
|
|
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();
|
2020-08-12 23:30:23 +00:00
|
|
|
const notInternalNoPorts = this.isNotInternalAndHasNoPublishedPorts();
|
|
|
|
return overflow || autoScalerOverflow || inProgress || invalid || hasNoChanges || nonScalable || notInternalNoPorts;
|
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() {
|
|
|
|
return this.formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER && _.filter(this.formValues.PublishedPorts, { IsNew: false }).length;
|
|
|
|
}
|
|
|
|
|
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) ||
|
|
|
|
(this.isEditLBWithPorts() && this.formValues.PublishedPorts[index].Protocol !== protocol) ||
|
|
|
|
(this.isNewAndNotFirst(index) && this.formValues.PublishedPorts[index].Protocol !== protocol)
|
|
|
|
);
|
2020-08-12 23:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* #endregion */
|
|
|
|
|
|
|
|
/* #region DATA AUTO REFRESH */
|
2020-07-05 23:21:03 +00:00
|
|
|
async updateSlidersAsync() {
|
|
|
|
try {
|
|
|
|
const quota = this.formValues.ResourcePool.Quota;
|
|
|
|
let minCpu,
|
|
|
|
maxCpu,
|
|
|
|
minMemory,
|
|
|
|
maxMemory = 0;
|
|
|
|
if (quota) {
|
|
|
|
this.state.resourcePoolHasQuota = true;
|
|
|
|
if (quota.CpuLimit) {
|
|
|
|
minCpu = KubernetesApplicationQuotaDefaults.CpuLimit;
|
|
|
|
maxCpu = quota.CpuLimit - quota.CpuLimitUsed;
|
|
|
|
if (this.state.isEdit && this.savedFormValues.CpuLimit) {
|
|
|
|
maxCpu += this.savedFormValues.CpuLimit * this.savedFormValues.ReplicaCount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
minCpu = 0;
|
|
|
|
maxCpu = this.state.nodes.cpu;
|
|
|
|
}
|
|
|
|
if (quota.MemoryLimit) {
|
|
|
|
minMemory = KubernetesApplicationQuotaDefaults.MemoryLimit;
|
|
|
|
maxMemory = quota.MemoryLimit - quota.MemoryLimitUsed;
|
|
|
|
if (this.state.isEdit && this.savedFormValues.MemoryLimit) {
|
|
|
|
maxMemory += KubernetesResourceReservationHelper.bytesValue(this.savedFormValues.MemoryLimit) * this.savedFormValues.ReplicaCount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
minMemory = 0;
|
|
|
|
maxMemory = this.state.nodes.memory;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.state.resourcePoolHasQuota = false;
|
|
|
|
minCpu = 0;
|
|
|
|
maxCpu = this.state.nodes.cpu;
|
|
|
|
minMemory = 0;
|
|
|
|
maxMemory = this.state.nodes.memory;
|
|
|
|
}
|
|
|
|
this.state.sliders.memory.min = minMemory;
|
|
|
|
this.state.sliders.memory.max = KubernetesResourceReservationHelper.megaBytesValue(maxMemory);
|
|
|
|
this.state.sliders.cpu.min = minCpu;
|
|
|
|
this.state.sliders.cpu.max = _.round(maxCpu, 2);
|
|
|
|
if (!this.state.isEdit) {
|
|
|
|
this.formValues.CpuLimit = minCpu;
|
|
|
|
this.formValues.MemoryLimit = minMemory;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to update resources selector');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSliders() {
|
|
|
|
return this.$async(this.updateSlidersAsync);
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshStacksAsync(namespace) {
|
|
|
|
try {
|
|
|
|
this.stacks = await this.KubernetesStackService.get(namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve stacks');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshStacks(namespace) {
|
|
|
|
return this.$async(this.refreshStacksAsync, namespace);
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshConfigurationsAsync(namespace) {
|
|
|
|
try {
|
|
|
|
this.configurations = await this.KubernetesConfigurationService.get(namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve configurations');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshConfigurations(namespace) {
|
|
|
|
return this.$async(this.refreshConfigurationsAsync, namespace);
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshApplicationsAsync(namespace) {
|
|
|
|
try {
|
|
|
|
this.applications = await this.KubernetesApplicationService.get(namespace);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve applications');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshApplications(namespace) {
|
|
|
|
return this.$async(this.refreshApplicationsAsync, namespace);
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
refreshVolumes(namespace) {
|
|
|
|
const filteredVolumes = _.filter(this.volumes, (volume) => {
|
|
|
|
const isSameNamespace = volume.ResourcePool.Namespace.Name === namespace;
|
|
|
|
const isUnused = !KubernetesVolumeHelper.isUsed(volume);
|
|
|
|
const isRWX = volume.PersistentVolumeClaim.StorageClass && _.find(volume.PersistentVolumeClaim.StorageClass.AccessModes, (am) => am === 'RWX');
|
|
|
|
return isSameNamespace && (isUnused || isRWX);
|
|
|
|
});
|
|
|
|
this.availableVolumes = filteredVolumes;
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshIngresses(namespace) {
|
|
|
|
this.filteredIngresses = _.filter(this.ingresses, { Namespace: namespace });
|
|
|
|
if (!this.publishViaIngressEnabled()) {
|
|
|
|
this.formValues.PublishingType = KubernetesApplicationPublishingTypes.INTERNAL;
|
|
|
|
}
|
|
|
|
this.formValues.OriginalIngresses = this.filteredIngresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshNamespaceDataAsync(namespace) {
|
|
|
|
await Promise.all([
|
|
|
|
this.refreshStacks(namespace),
|
|
|
|
this.refreshConfigurations(namespace),
|
|
|
|
this.refreshApplications(namespace),
|
|
|
|
this.refreshIngresses(namespace),
|
|
|
|
this.refreshVolumes(namespace),
|
|
|
|
]);
|
2020-07-05 23:21:03 +00:00
|
|
|
this.onChangeName();
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
refreshNamespaceData(namespace) {
|
|
|
|
return this.$async(this.refreshNamespaceDataAsync, namespace);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFormValues() {
|
|
|
|
this.clearConfigurations();
|
|
|
|
this.resetPersistedFolders();
|
|
|
|
this.resetPublishedPorts();
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onResourcePoolSelectionChange() {
|
|
|
|
const namespace = this.formValues.ResourcePool.Namespace.Name;
|
|
|
|
this.updateSliders();
|
2020-08-12 23:30:23 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateApplicationAsync() {
|
|
|
|
try {
|
|
|
|
this.state.actionInProgress = true;
|
|
|
|
await this.KubernetesApplicationService.patch(this.savedFormValues, this.formValues);
|
|
|
|
this.Notifications.success('Application successfully updated');
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deployApplication() {
|
|
|
|
if (this.state.isEdit) {
|
|
|
|
this.ModalService.confirmUpdate('Updating the application may cause a service interruption. Do you wish to continue?', (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
return this.$async(this.updateApplicationAsync);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} 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
|
|
|
async getApplicationAsync() {
|
|
|
|
try {
|
|
|
|
const namespace = this.state.params.namespace;
|
|
|
|
[this.application, this.persistentVolumeClaims] = await Promise.all([
|
|
|
|
this.KubernetesApplicationService.get(namespace, this.state.params.name),
|
|
|
|
this.KubernetesPersistentVolumeClaimService.get(namespace),
|
|
|
|
]);
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve application details');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getApplication() {
|
|
|
|
return this.$async(this.getApplicationAsync);
|
|
|
|
}
|
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 */
|
2020-07-05 23:21:03 +00:00
|
|
|
async onInit() {
|
|
|
|
try {
|
|
|
|
this.state = {
|
|
|
|
actionInProgress: false,
|
|
|
|
useLoadBalancer: false,
|
2020-08-04 22:08:11 +00:00
|
|
|
useServerMetrics: false,
|
2020-07-05 23:21:03 +00:00
|
|
|
sliders: {
|
|
|
|
cpu: {
|
|
|
|
min: 0,
|
|
|
|
max: 0,
|
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
min: 0,
|
|
|
|
max: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodes: {
|
|
|
|
memory: 0,
|
|
|
|
cpu: 0,
|
|
|
|
},
|
|
|
|
resourcePoolHasQuota: false,
|
|
|
|
viewReady: false,
|
|
|
|
availableSizeUnits: ['MB', 'GB', 'TB'],
|
|
|
|
alreadyExists: false,
|
2020-08-12 23:30:23 +00:00
|
|
|
duplicates: {
|
2020-08-20 00:51:14 +00:00
|
|
|
environmentVariables: new KubernetesFormValueDuplicate(),
|
|
|
|
persistedFolders: new KubernetesFormValueDuplicate(),
|
|
|
|
configurationPaths: new KubernetesFormValueDuplicate(),
|
|
|
|
existingVolumes: new KubernetesFormValueDuplicate(),
|
2020-08-12 23:30:23 +00:00
|
|
|
publishedPorts: {
|
2020-08-20 00:51:14 +00:00
|
|
|
containerPorts: new KubernetesFormValueDuplicate(),
|
|
|
|
nodePorts: new KubernetesFormValueDuplicate(),
|
|
|
|
ingressRoutes: new KubernetesFormValueDuplicate(),
|
|
|
|
loadBalancerPorts: new KubernetesFormValueDuplicate(),
|
2020-08-12 23:30:23 +00:00
|
|
|
},
|
2020-08-20 00:51:14 +00:00
|
|
|
placements: new KubernetesFormValueDuplicate(),
|
2020-08-12 23:30:23 +00:00
|
|
|
},
|
2020-07-05 23:21:03 +00:00
|
|
|
isEdit: false,
|
|
|
|
params: {
|
|
|
|
namespace: this.$transition$.params().namespace,
|
|
|
|
name: this.$transition$.params().name,
|
|
|
|
},
|
2020-08-07 04:40:24 +00:00
|
|
|
PersistedFoldersUseExistingVolumes: false,
|
2020-07-05 23:21:03 +00:00
|
|
|
};
|
|
|
|
|
2020-08-04 22:08:11 +00:00
|
|
|
this.isAdmin = this.Authentication.isAdmin();
|
|
|
|
|
2020-07-05 23:21:03 +00:00
|
|
|
this.editChanges = [];
|
|
|
|
|
|
|
|
if (this.$transition$.params().namespace && this.$transition$.params().name) {
|
|
|
|
this.state.isEdit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const endpoint = this.EndpointProvider.currentEndpoint();
|
2020-08-04 22:08:11 +00:00
|
|
|
this.endpoint = endpoint;
|
2020-07-05 23:21:03 +00:00
|
|
|
this.storageClasses = endpoint.Kubernetes.Configuration.StorageClasses;
|
|
|
|
this.state.useLoadBalancer = endpoint.Kubernetes.Configuration.UseLoadBalancer;
|
2020-08-04 22:08:11 +00:00
|
|
|
this.state.useServerMetrics = endpoint.Kubernetes.Configuration.UseServerMetrics;
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
this.formValues = new KubernetesApplicationFormValues();
|
|
|
|
|
2020-08-12 23:30:23 +00:00
|
|
|
const [resourcePools, nodes, ingresses] = await Promise.all([
|
2020-08-07 04:40:24 +00:00
|
|
|
this.KubernetesResourcePoolService.get(),
|
|
|
|
this.KubernetesNodeService.get(),
|
2020-08-12 23:30:23 +00:00
|
|
|
this.KubernetesIngressService.get(),
|
2020-08-07 04:40:24 +00:00
|
|
|
]);
|
2020-08-12 23:30:23 +00:00
|
|
|
this.ingresses = ingresses;
|
2020-07-05 23:21:03 +00:00
|
|
|
|
2020-07-14 05:39:13 +00:00
|
|
|
this.resourcePools = _.filter(resourcePools, (resourcePool) => !this.KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name));
|
2020-07-05 23:21:03 +00:00
|
|
|
this.formValues.ResourcePool = this.resourcePools[0];
|
2020-08-12 23:30:23 +00:00
|
|
|
|
|
|
|
// TODO: refactor @Max
|
|
|
|
// Don't pull all volumes and applications across all namespaces
|
|
|
|
// Use refreshNamespaceData flow (triggered on Init + on Namespace change)
|
|
|
|
// and query only accross the selected namespace
|
|
|
|
if (this.storageClassAvailable()) {
|
|
|
|
const [applications, volumes] = await Promise.all([this.KubernetesApplicationService.get(), this.KubernetesVolumeService.get()]);
|
|
|
|
this.volumes = volumes;
|
|
|
|
_.forEach(this.volumes, (volume) => {
|
|
|
|
volume.Applications = KubernetesVolumeHelper.getUsingApplications(volume, applications);
|
|
|
|
});
|
|
|
|
}
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
_.forEach(nodes, (item) => {
|
|
|
|
this.state.nodes.memory += filesizeParser(item.Memory);
|
|
|
|
this.state.nodes.cpu += item.CPU;
|
|
|
|
});
|
2020-08-13 23:56:53 +00:00
|
|
|
this.nodesLabels = KubernetesNodeHelper.generateNodeLabelsFromNodes(nodes);
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
const namespace = this.state.isEdit ? this.state.params.namespace : this.formValues.ResourcePool.Namespace.Name;
|
2020-08-12 23:30:23 +00:00
|
|
|
await this.refreshNamespaceData(namespace);
|
2020-07-05 23:21:03 +00:00
|
|
|
|
|
|
|
if (this.state.isEdit) {
|
|
|
|
await this.getApplication();
|
2020-08-13 23:56:53 +00:00
|
|
|
this.formValues = KubernetesApplicationConverter.applicationToFormValues(
|
|
|
|
this.application,
|
|
|
|
this.resourcePools,
|
|
|
|
this.configurations,
|
|
|
|
this.persistentVolumeClaims,
|
|
|
|
this.nodesLabels
|
|
|
|
);
|
2020-08-12 23:30:23 +00:00
|
|
|
this.formValues.OriginalIngresses = this.filteredIngresses;
|
2020-07-05 23:21:03 +00:00
|
|
|
this.savedFormValues = angular.copy(this.formValues);
|
|
|
|
delete this.formValues.ApplicationType;
|
2020-08-07 04:40:24 +00:00
|
|
|
|
|
|
|
if (this.application.ApplicationType !== KubernetesApplicationTypes.STATEFULSET) {
|
|
|
|
_.forEach(this.formValues.PersistedFolders, (persistedFolder) => {
|
|
|
|
const volume = _.find(this.availableVolumes, (vol) => vol.PersistentVolumeClaim.Name === persistedFolder.PersistentVolumeClaimName);
|
|
|
|
if (volume) {
|
|
|
|
persistedFolder.UseNewVolume = false;
|
|
|
|
persistedFolder.ExistingVolume = volume;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-08-04 22:08:11 +00:00
|
|
|
} else {
|
2020-08-10 22:57:20 +00:00
|
|
|
this.formValues.AutoScaler = KubernetesApplicationHelper.generateAutoScalerFormValueFromHorizontalPodAutoScaler(null, this.formValues.ReplicaCount);
|
2020-08-12 23:30:23 +00:00
|
|
|
this.formValues.OriginalIngressClasses = angular.copy(this.ingresses);
|
2020-07-05 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await this.updateSliders();
|
|
|
|
} catch (err) {
|
|
|
|
this.Notifications.error('Failure', err, 'Unable to load view data');
|
|
|
|
} finally {
|
|
|
|
this.state.viewReady = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
return this.$async(this.onInit);
|
|
|
|
}
|
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);
|