mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
Merge branch 'develop' into feat/EE-809/EE-466/kube-advanced-apps
This commit is contained in:
commit
0128d1bf96
54 changed files with 1634 additions and 1389 deletions
|
@ -39,6 +39,7 @@ export default class KubectlShellController {
|
|||
}
|
||||
|
||||
configureSocketAndTerminal(socket, term) {
|
||||
var vm = this;
|
||||
socket.onopen = function () {
|
||||
const terminal_container = document.getElementById('terminal-container');
|
||||
term.open(terminal_container);
|
||||
|
@ -55,7 +56,7 @@ export default class KubectlShellController {
|
|||
});
|
||||
|
||||
this.$window.onresize = function () {
|
||||
term.fit();
|
||||
vm.TerminalWindow.terminalresize();
|
||||
};
|
||||
|
||||
socket.onmessage = function (msg) {
|
||||
|
|
|
@ -60,7 +60,7 @@ ul.sidebar li .shell-item-center a:hover {
|
|||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 480px;
|
||||
height: 495px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.dashboard({endpointId: $ctrl.endpointId})" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.resourcePools({endpointId: $ctrl.endpointId})" ui-sref-active="active">Namespaces <span class="menu-icon fa fa-layer-group fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.applications({endpointId: $ctrl.endpointId})" ui-sref-active="active">Applications <span class="menu-icon fa fa-laptop-code fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.configurations({endpointId: $ctrl.endpointId})" ui-sref-active="active">Configurations <span class="menu-icon fa fa-file-code fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.volumes({endpointId: $ctrl.endpointId})" ui-sref-active="active">Volumes <span class="menu-icon fa fa-database fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.cluster({endpointId: $ctrl.endpointId})" ui-sref-active="active">Cluster <span class="menu-icon fa fa-server fa-fw"></span></a>
|
||||
<div
|
||||
ng-if="
|
||||
$ctrl.adminAccess &&
|
||||
['kubernetes.cluster', 'portainer.endpoints.endpoint.kubernetesConfig', 'kubernetes.registries', 'kubernetes.registries.access'].includes($ctrl.currentState)
|
||||
"
|
||||
>
|
||||
<div class="sidebar-sublist">
|
||||
<a ui-sref="portainer.endpoints.endpoint.kubernetesConfig({id: $ctrl.endpointId})" ui-sref-active="active">Setup</a>
|
||||
</div>
|
||||
<div class="sidebar-sublist">
|
||||
<a ui-sref="kubernetes.registries({endpointId: $ctrl.endpointId})" ui-sref-active="active">Registries</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
|
@ -1,8 +0,0 @@
|
|||
angular.module('portainer.kubernetes').component('kubernetesSidebarContent', {
|
||||
templateUrl: './kubernetesSidebarContent.html',
|
||||
bindings: {
|
||||
adminAccess: '<',
|
||||
endpointId: '<',
|
||||
currentState: '<',
|
||||
},
|
||||
});
|
9
app/kubernetes/components/kubernetes-sidebar/index.js
Normal file
9
app/kubernetes/components/kubernetes-sidebar/index.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import angular from 'angular';
|
||||
|
||||
angular.module('portainer.kubernetes').component('kubernetesSidebar', {
|
||||
templateUrl: './kubernetes-sidebar.html',
|
||||
bindings: {
|
||||
endpointId: '<',
|
||||
isSidebarOpen: '<',
|
||||
},
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
<sidebar-menu-item path="kubernetes.dashboard" path-params="{ endpointId: $ctrl.endpointId }" icon-class="fa-tachometer-alt fa-fw" class-name="sidebar-list">
|
||||
Dashboard
|
||||
</sidebar-menu-item>
|
||||
|
||||
<sidebar-menu-item path="kubernetes.resourcePools" path-params="{ endpointId: $ctrl.endpointId }" icon-class="fa-layer-group fa-fw" class-name="sidebar-list">
|
||||
Namespaces
|
||||
</sidebar-menu-item>
|
||||
|
||||
<sidebar-menu-item path="kubernetes.applications" path-params="{ endpointId: $ctrl.endpointId }" icon-class="fa-laptop-code fa-fw" class-name="sidebar-list">
|
||||
Applications
|
||||
</sidebar-menu-item>
|
||||
|
||||
<sidebar-menu-item path="kubernetes.configurations" path-params="{ endpointId: $ctrl.endpointId }" icon-class="fa-file-code fa-fw" class-name="sidebar-list">
|
||||
Configurations
|
||||
</sidebar-menu-item>
|
||||
|
||||
<sidebar-menu-item path="kubernetes.volumes" path-params="{ endpointId: $ctrl.endpointId }" icon-class="fa-database fa-fw" class-name="sidebar-list">
|
||||
Volumes
|
||||
</sidebar-menu-item>
|
||||
|
||||
<sidebar-menu
|
||||
icon-class="fa-server fa-fw"
|
||||
label="Cluster"
|
||||
path="kubernetes.cluster"
|
||||
path-params="{ endpointId: $ctrl.endpointId }"
|
||||
is-sidebar-open="$ctrl.isSidebarOpen"
|
||||
children-paths="['kubernetes.cluster', 'portainer.endpoints.endpoint.kubernetesConfig', 'kubernetes.registries', 'kubernetes.registries.access']"
|
||||
>
|
||||
<div ng-if="$ctrl.adminAccess">
|
||||
<sidebar-menu-item authorization="K8sClusterSetupRW" path="portainer.endpoints.endpoint.kubernetesConfig" path-params="{ id: $ctrl.endpointId }" class-name="sidebar-sublist">
|
||||
Setup
|
||||
</sidebar-menu-item>
|
||||
|
||||
<sidebar-menu-item authorization="PortainerRegistryList" path="kubernetes.registries" path-params="{ endpointId: $ctrl.endpointId }" class-name="sidebar-sublist">
|
||||
Registries
|
||||
</sidebar-menu-item>
|
||||
</div>
|
||||
</sidebar-menu>
|
|
@ -89,122 +89,110 @@ class KubernetesApplicationService {
|
|||
|
||||
/* #region GET */
|
||||
async getAsync(namespace, name) {
|
||||
try {
|
||||
const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
|
||||
this.KubernetesDeploymentService.get(namespace, name),
|
||||
this.KubernetesDaemonSetService.get(namespace, name),
|
||||
this.KubernetesStatefulSetService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(namespace),
|
||||
this.KubernetesIngressService.get(namespace),
|
||||
]);
|
||||
const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
|
||||
this.KubernetesDeploymentService.get(namespace, name),
|
||||
this.KubernetesDaemonSetService.get(namespace, name),
|
||||
this.KubernetesStatefulSetService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(namespace),
|
||||
this.KubernetesIngressService.get(namespace),
|
||||
]);
|
||||
|
||||
// const pod = _.find(pods.value, ['metadata.namespace', namespace, 'metadata.name', name]);
|
||||
|
||||
let rootItem;
|
||||
let converterFunc;
|
||||
if (deployment.status === 'fulfilled') {
|
||||
rootItem = deployment;
|
||||
converterFunc = KubernetesApplicationConverter.apiDeploymentToApplication;
|
||||
} else if (daemonSet.status === 'fulfilled') {
|
||||
rootItem = daemonSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiDaemonSetToApplication;
|
||||
} else if (statefulSet.status === 'fulfilled') {
|
||||
rootItem = statefulSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiStatefulSetToapplication;
|
||||
} else if (pod.status === 'fulfilled') {
|
||||
rootItem = pod;
|
||||
converterFunc = KubernetesApplicationConverter.apiPodToApplication;
|
||||
} else {
|
||||
throw new PortainerError('Unable to determine which association to use to convert application');
|
||||
}
|
||||
|
||||
const services = await this.KubernetesServiceService.get(namespace);
|
||||
const boundService = KubernetesServiceHelper.findApplicationBoundService(services, rootItem.value.Raw);
|
||||
const service = boundService ? await this.KubernetesServiceService.get(namespace, boundService.metadata.name) : {};
|
||||
|
||||
const application = converterFunc(rootItem.value.Raw, pods.value, service.Raw, ingresses.value);
|
||||
application.Yaml = rootItem.value.Yaml;
|
||||
application.Raw = rootItem.value.Raw;
|
||||
application.Pods = _.map(application.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers.value, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(namespace, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
|
||||
await this.KubernetesHistoryService.get(application);
|
||||
|
||||
if (service.Yaml) {
|
||||
application.Yaml += '---\n' + service.Yaml;
|
||||
}
|
||||
if (scaler && scaler.Yaml) {
|
||||
application.Yaml += '---\n' + scaler.Yaml;
|
||||
}
|
||||
// TODO: refactor @LP
|
||||
// append ingress yaml ?
|
||||
return application;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
let rootItem;
|
||||
let converterFunc;
|
||||
if (deployment.status === 'fulfilled') {
|
||||
rootItem = deployment;
|
||||
converterFunc = KubernetesApplicationConverter.apiDeploymentToApplication;
|
||||
} else if (daemonSet.status === 'fulfilled') {
|
||||
rootItem = daemonSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiDaemonSetToApplication;
|
||||
} else if (statefulSet.status === 'fulfilled') {
|
||||
rootItem = statefulSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiStatefulSetToapplication;
|
||||
} else if (pod.status === 'fulfilled') {
|
||||
rootItem = pod;
|
||||
converterFunc = KubernetesApplicationConverter.apiPodToApplication;
|
||||
} else {
|
||||
throw new PortainerError('Unable to determine which association to use to convert application');
|
||||
}
|
||||
|
||||
const services = await this.KubernetesServiceService.get(namespace);
|
||||
const boundService = KubernetesServiceHelper.findApplicationBoundService(services, rootItem.value.Raw);
|
||||
const service = boundService ? await this.KubernetesServiceService.get(namespace, boundService.metadata.name) : {};
|
||||
|
||||
const application = converterFunc(rootItem.value.Raw, pods.value, service.Raw, ingresses.value);
|
||||
application.Yaml = rootItem.value.Yaml;
|
||||
application.Raw = rootItem.value.Raw;
|
||||
application.Pods = _.map(application.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers.value, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(namespace, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
|
||||
await this.KubernetesHistoryService.get(application);
|
||||
|
||||
if (service.Yaml) {
|
||||
application.Yaml += '---\n' + service.Yaml;
|
||||
}
|
||||
if (scaler && scaler.Yaml) {
|
||||
application.Yaml += '---\n' + scaler.Yaml;
|
||||
}
|
||||
// TODO: refactor @LP
|
||||
// append ingress yaml ?
|
||||
return application;
|
||||
}
|
||||
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
|
||||
const convertToApplication = (item, converterFunc, services, pods, ingresses) => {
|
||||
const service = KubernetesServiceHelper.findApplicationBoundService(services, item);
|
||||
const application = converterFunc(item, pods, service, ingresses);
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
return application;
|
||||
};
|
||||
const convertToApplication = (item, converterFunc, services, pods, ingresses) => {
|
||||
const service = KubernetesServiceHelper.findApplicationBoundService(services, item);
|
||||
const application = converterFunc(item, pods, service, ingresses);
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
return application;
|
||||
};
|
||||
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([
|
||||
this.KubernetesDeploymentService.get(ns),
|
||||
this.KubernetesDaemonSetService.get(ns),
|
||||
this.KubernetesStatefulSetService.get(ns),
|
||||
this.KubernetesServiceService.get(ns),
|
||||
this.KubernetesPodService.get(ns),
|
||||
this.KubernetesIngressService.get(ns),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(ns),
|
||||
]);
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([
|
||||
this.KubernetesDeploymentService.get(ns),
|
||||
this.KubernetesDaemonSetService.get(ns),
|
||||
this.KubernetesStatefulSetService.get(ns),
|
||||
this.KubernetesServiceService.get(ns),
|
||||
this.KubernetesPodService.get(ns),
|
||||
this.KubernetesIngressService.get(ns),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(ns),
|
||||
]);
|
||||
|
||||
const deploymentApplications = _.map(deployments, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiDeploymentToApplication, services, pods, ingresses)
|
||||
);
|
||||
const daemonSetApplications = _.map(daemonSets, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiDaemonSetToApplication, services, pods, ingresses)
|
||||
);
|
||||
const statefulSetApplications = _.map(statefulSets, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiStatefulSetToapplication, services, pods, ingresses)
|
||||
);
|
||||
const deploymentApplications = _.map(deployments, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiDeploymentToApplication, services, pods, ingresses)
|
||||
);
|
||||
const daemonSetApplications = _.map(daemonSets, (item) => convertToApplication(item, KubernetesApplicationConverter.apiDaemonSetToApplication, services, pods, ingresses));
|
||||
const statefulSetApplications = _.map(statefulSets, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiStatefulSetToapplication, services, pods, ingresses)
|
||||
);
|
||||
|
||||
const boundPods = _.concat(_.flatMap(deploymentApplications, 'Pods'), _.flatMap(daemonSetApplications, 'Pods'), _.flatMap(statefulSetApplications, 'Pods'));
|
||||
const unboundPods = _.without(pods, ...boundPods);
|
||||
const nakedPodsApplications = _.map(unboundPods, (item) => convertToApplication(item, KubernetesApplicationConverter.apiPodToApplication, services, pods, ingresses));
|
||||
const boundPods = _.concat(_.flatMap(deploymentApplications, 'Pods'), _.flatMap(daemonSetApplications, 'Pods'), _.flatMap(statefulSetApplications, 'Pods'));
|
||||
const unboundPods = _.without(pods, ...boundPods);
|
||||
const nakedPodsApplications = _.map(unboundPods, (item) => convertToApplication(item, KubernetesApplicationConverter.apiPodToApplication, services, pods, ingresses));
|
||||
|
||||
const applications = _.concat(deploymentApplications, daemonSetApplications, statefulSetApplications, nakedPodsApplications);
|
||||
_.forEach(applications, (app) => {
|
||||
app.Pods = _.map(app.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
});
|
||||
await Promise.all(
|
||||
_.forEach(applications, async (application) => {
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(ns, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
})
|
||||
);
|
||||
return applications;
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const applications = _.concat(deploymentApplications, daemonSetApplications, statefulSetApplications, nakedPodsApplications);
|
||||
_.forEach(applications, (app) => {
|
||||
app.Pods = _.map(app.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
});
|
||||
await Promise.all(
|
||||
_.forEach(applications, async (application) => {
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(ns, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
})
|
||||
);
|
||||
return applications;
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
}
|
||||
|
||||
get(namespace, name) {
|
||||
|
@ -226,42 +214,38 @@ class KubernetesApplicationService {
|
|||
* also be displayed in the summary output (getCreatedApplicationResources)
|
||||
*/
|
||||
async createAsync(formValues) {
|
||||
try {
|
||||
let [app, headlessService, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
|
||||
let [app, headlessService, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
|
||||
|
||||
if (service) {
|
||||
await this.KubernetesServiceService.create(service);
|
||||
if (formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, service.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
if (service) {
|
||||
await this.KubernetesServiceService.create(service);
|
||||
if (formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, service.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
|
||||
const apiService = this._getApplicationApiService(app);
|
||||
|
||||
if (app instanceof KubernetesStatefulSet) {
|
||||
app.VolumeClaims = claims;
|
||||
headlessService = await this.KubernetesServiceService.create(headlessService);
|
||||
app.ServiceName = headlessService.metadata.name;
|
||||
} else {
|
||||
const claimPromises = _.map(claims, (item) => {
|
||||
if (!item.PreviousName && !item.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(item);
|
||||
}
|
||||
});
|
||||
await Promise.all(_.without(claimPromises, undefined));
|
||||
}
|
||||
|
||||
if (formValues.AutoScaler.IsUsed && formValues.DeploymentType !== KubernetesApplicationDeploymentTypes.GLOBAL) {
|
||||
const kind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(app);
|
||||
const autoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(formValues, kind);
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(autoScaler);
|
||||
}
|
||||
|
||||
await apiService.create(app);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const apiService = this._getApplicationApiService(app);
|
||||
|
||||
if (app instanceof KubernetesStatefulSet) {
|
||||
app.VolumeClaims = claims;
|
||||
headlessService = await this.KubernetesServiceService.create(headlessService);
|
||||
app.ServiceName = headlessService.metadata.name;
|
||||
} else {
|
||||
const claimPromises = _.map(claims, (item) => {
|
||||
if (!item.PreviousName && !item.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(item);
|
||||
}
|
||||
});
|
||||
await Promise.all(_.without(claimPromises, undefined));
|
||||
}
|
||||
|
||||
if (formValues.AutoScaler.IsUsed && formValues.DeploymentType !== KubernetesApplicationDeploymentTypes.GLOBAL) {
|
||||
const kind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(app);
|
||||
const autoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(formValues, kind);
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(autoScaler);
|
||||
}
|
||||
|
||||
await apiService.create(app);
|
||||
}
|
||||
|
||||
create(formValues) {
|
||||
|
@ -277,97 +261,89 @@ class KubernetesApplicationService {
|
|||
* in this method should also be displayed in the summary output (getUpdatedApplicationResources)
|
||||
*/
|
||||
async patchAsync(oldFormValues, newFormValues) {
|
||||
try {
|
||||
const [oldApp, oldHeadlessService, oldService, oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
|
||||
const [newApp, newHeadlessService, newService, newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
|
||||
const oldApiService = this._getApplicationApiService(oldApp);
|
||||
const newApiService = this._getApplicationApiService(newApp);
|
||||
const [oldApp, oldHeadlessService, oldService, oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
|
||||
const [newApp, newHeadlessService, newService, newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
|
||||
const oldApiService = this._getApplicationApiService(oldApp);
|
||||
const newApiService = this._getApplicationApiService(newApp);
|
||||
|
||||
if (oldApiService !== newApiService) {
|
||||
await this.delete(oldApp);
|
||||
if (oldService) {
|
||||
await this.KubernetesServiceService.delete(oldService);
|
||||
}
|
||||
return await this.create(newFormValues);
|
||||
}
|
||||
|
||||
if (newApp instanceof KubernetesStatefulSet) {
|
||||
await this.KubernetesServiceService.patch(oldHeadlessService, newHeadlessService);
|
||||
} else {
|
||||
const claimPromises = _.map(newClaims, (newClaim) => {
|
||||
if (!newClaim.PreviousName && !newClaim.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(newClaim);
|
||||
} else if (!newClaim.Id) {
|
||||
const oldClaim = _.find(oldClaims, { Name: newClaim.PreviousName });
|
||||
return this.KubernetesPersistentVolumeClaimService.patch(oldClaim, newClaim);
|
||||
}
|
||||
});
|
||||
await Promise.all(claimPromises);
|
||||
}
|
||||
|
||||
await newApiService.patch(oldApp, newApp);
|
||||
|
||||
if (oldService && newService) {
|
||||
await this.KubernetesServiceService.patch(oldService, newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS || oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const oldIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(oldFormValues, oldService.Name);
|
||||
const newIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldIngresses, newIngresses));
|
||||
}
|
||||
} else if (!oldService && newService) {
|
||||
await this.KubernetesServiceService.create(newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(newFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
} else if (oldService && !newService) {
|
||||
if (oldApiService !== newApiService) {
|
||||
await this.delete(oldApp);
|
||||
if (oldService) {
|
||||
await this.KubernetesServiceService.delete(oldService);
|
||||
if (oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, oldService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
}
|
||||
return await this.create(newFormValues);
|
||||
}
|
||||
|
||||
const newKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(newApp);
|
||||
const newAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(newFormValues, newKind);
|
||||
if (!oldFormValues.AutoScaler.IsUsed) {
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(newAutoScaler);
|
||||
}
|
||||
} else {
|
||||
const oldKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(oldApp);
|
||||
const oldAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(oldFormValues, oldKind);
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.patch(oldAutoScaler, newAutoScaler);
|
||||
} else {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(oldAutoScaler);
|
||||
if (newApp instanceof KubernetesStatefulSet) {
|
||||
await this.KubernetesServiceService.patch(oldHeadlessService, newHeadlessService);
|
||||
} else {
|
||||
const claimPromises = _.map(newClaims, (newClaim) => {
|
||||
if (!newClaim.PreviousName && !newClaim.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(newClaim);
|
||||
} else if (!newClaim.Id) {
|
||||
const oldClaim = _.find(oldClaims, { Name: newClaim.PreviousName });
|
||||
return this.KubernetesPersistentVolumeClaimService.patch(oldClaim, newClaim);
|
||||
}
|
||||
});
|
||||
await Promise.all(claimPromises);
|
||||
}
|
||||
|
||||
await newApiService.patch(oldApp, newApp);
|
||||
|
||||
if (oldService && newService) {
|
||||
await this.KubernetesServiceService.patch(oldService, newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS || oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const oldIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(oldFormValues, oldService.Name);
|
||||
const newIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldIngresses, newIngresses));
|
||||
}
|
||||
} else if (!oldService && newService) {
|
||||
await this.KubernetesServiceService.create(newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(newFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
} else if (oldService && !newService) {
|
||||
await this.KubernetesServiceService.delete(oldService);
|
||||
if (oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, oldService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
}
|
||||
|
||||
const newKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(newApp);
|
||||
const newAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(newFormValues, newKind);
|
||||
if (!oldFormValues.AutoScaler.IsUsed) {
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(newAutoScaler);
|
||||
}
|
||||
} else {
|
||||
const oldKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(oldApp);
|
||||
const oldAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(oldFormValues, oldKind);
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.patch(oldAutoScaler, newAutoScaler);
|
||||
} else {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(oldAutoScaler);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// this function accepts KubernetesApplication as parameters
|
||||
async patchPartialAsync(oldApp, newApp) {
|
||||
try {
|
||||
const oldAppPayload = {
|
||||
Name: oldApp.Name,
|
||||
Namespace: oldApp.ResourcePool,
|
||||
StackName: oldApp.StackName,
|
||||
Note: oldApp.Note,
|
||||
};
|
||||
const newAppPayload = {
|
||||
Name: newApp.Name,
|
||||
Namespace: newApp.ResourcePool,
|
||||
StackName: newApp.StackName,
|
||||
Note: newApp.Note,
|
||||
};
|
||||
const apiService = this._getApplicationApiService(oldApp);
|
||||
await apiService.patch(oldAppPayload, newAppPayload);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const oldAppPayload = {
|
||||
Name: oldApp.Name,
|
||||
Namespace: oldApp.ResourcePool,
|
||||
StackName: oldApp.StackName,
|
||||
Note: oldApp.Note,
|
||||
};
|
||||
const newAppPayload = {
|
||||
Name: newApp.Name,
|
||||
Namespace: newApp.ResourcePool,
|
||||
StackName: newApp.StackName,
|
||||
Note: newApp.Note,
|
||||
};
|
||||
const apiService = this._getApplicationApiService(oldApp);
|
||||
await apiService.patch(oldAppPayload, newAppPayload);
|
||||
}
|
||||
|
||||
// accept either formValues or applications as parameters
|
||||
|
@ -384,42 +360,38 @@ class KubernetesApplicationService {
|
|||
|
||||
/* #region DELETE */
|
||||
async deleteAsync(application) {
|
||||
try {
|
||||
const payload = {
|
||||
Namespace: application.ResourcePool || application.Namespace,
|
||||
Name: application.Name,
|
||||
};
|
||||
const servicePayload = angular.copy(payload);
|
||||
servicePayload.Name = application.Name;
|
||||
const payload = {
|
||||
Namespace: application.ResourcePool || application.Namespace,
|
||||
Name: application.Name,
|
||||
};
|
||||
const servicePayload = angular.copy(payload);
|
||||
servicePayload.Name = application.Name;
|
||||
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.delete(payload);
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.delete(payload);
|
||||
|
||||
if (apiService === this.KubernetesStatefulSetService) {
|
||||
const headlessServicePayload = angular.copy(payload);
|
||||
headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName;
|
||||
await this.KubernetesServiceService.delete(headlessServicePayload);
|
||||
}
|
||||
if (apiService === this.KubernetesStatefulSetService) {
|
||||
const headlessServicePayload = angular.copy(payload);
|
||||
headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName;
|
||||
await this.KubernetesServiceService.delete(headlessServicePayload);
|
||||
}
|
||||
|
||||
if (application.ServiceType) {
|
||||
await this.KubernetesServiceService.delete(servicePayload);
|
||||
const isIngress = _.filter(application.PublishedPorts, (p) => p.IngressRules.length).length;
|
||||
if (isIngress) {
|
||||
const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
|
||||
const formValues = {
|
||||
OriginalIngresses: originalIngresses,
|
||||
PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
|
||||
};
|
||||
_.forEach(formValues.PublishedPorts, (p) => (p.NeedsDeletion = true));
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, servicePayload.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
if (application.ServiceType) {
|
||||
await this.KubernetesServiceService.delete(servicePayload);
|
||||
const isIngress = _.filter(application.PublishedPorts, (p) => p.IngressRules.length).length;
|
||||
if (isIngress) {
|
||||
const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
|
||||
const formValues = {
|
||||
OriginalIngresses: originalIngresses,
|
||||
PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
|
||||
};
|
||||
_.forEach(formValues.PublishedPorts, (p) => (p.NeedsDeletion = true));
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, servicePayload.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
if (!_.isEmpty(application.AutoScaler)) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
if (!_.isEmpty(application.AutoScaler)) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,13 +402,9 @@ class KubernetesApplicationService {
|
|||
|
||||
/* #region ROLLBACK */
|
||||
async rollbackAsync(application, targetRevision) {
|
||||
try {
|
||||
const payload = KubernetesApplicationRollbackHelper.getPatchPayload(application, targetRevision);
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.rollback(application.ResourcePool, application.Name, payload);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const payload = KubernetesApplicationRollbackHelper.getPatchPayload(application, targetRevision);
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.rollback(application.ResourcePool, application.Name, payload);
|
||||
}
|
||||
|
||||
rollback(application, targetRevision) {
|
||||
|
|
|
@ -26,35 +26,27 @@ class KubernetesConfigurationService {
|
|||
* GET
|
||||
*/
|
||||
async getAsync(namespace, name) {
|
||||
try {
|
||||
const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]);
|
||||
let configuration;
|
||||
if (secret.status === 'fulfilled') {
|
||||
configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
|
||||
return configuration;
|
||||
}
|
||||
configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
|
||||
const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]);
|
||||
let configuration;
|
||||
if (secret.status === 'fulfilled') {
|
||||
configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
|
||||
return configuration;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [configMaps, secrets] = await Promise.all([this.KubernetesConfigMapService.get(ns), this.KubernetesSecretService.get(ns)]);
|
||||
const secretsConfigurations = _.map(secrets, (secret) => KubernetesConfigurationConverter.secretToConfiguration(secret));
|
||||
const configMapsConfigurations = _.map(configMaps, (configMap) => KubernetesConfigurationConverter.configMapToConfiguration(configMap));
|
||||
return _.concat(configMapsConfigurations, secretsConfigurations);
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [configMaps, secrets] = await Promise.all([this.KubernetesConfigMapService.get(ns), this.KubernetesSecretService.get(ns)]);
|
||||
const secretsConfigurations = _.map(secrets, (secret) => KubernetesConfigurationConverter.secretToConfiguration(secret));
|
||||
const configMapsConfigurations = _.map(configMaps, (configMap) => KubernetesConfigurationConverter.configMapToConfiguration(configMap));
|
||||
return _.concat(configMapsConfigurations, secretsConfigurations);
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
}
|
||||
|
||||
get(namespace, name) {
|
||||
|
@ -70,16 +62,12 @@ class KubernetesConfigurationService {
|
|||
async createAsync(formValues) {
|
||||
formValues.ConfigurationOwner = KubernetesCommonHelper.ownerToLabel(formValues.ConfigurationOwner);
|
||||
|
||||
try {
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
await this.KubernetesConfigMapService.create(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
await this.KubernetesSecretService.create(secret);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
await this.KubernetesConfigMapService.create(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
await this.KubernetesSecretService.create(secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,18 +79,14 @@ class KubernetesConfigurationService {
|
|||
* UPDATE
|
||||
*/
|
||||
async updateAsync(formValues, configuration) {
|
||||
try {
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesConfigMapService.update(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
secret.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesSecretService.update(secret);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesConfigMapService.update(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
secret.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesSecretService.update(secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,14 +98,10 @@ class KubernetesConfigurationService {
|
|||
* DELETE
|
||||
*/
|
||||
async deleteAsync(config) {
|
||||
try {
|
||||
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
await this.KubernetesConfigMapService.delete(config);
|
||||
} else {
|
||||
await this.KubernetesSecretService.delete(config);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
await this.KubernetesConfigMapService.delete(config);
|
||||
} else {
|
||||
await this.KubernetesSecretService.delete(config);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,11 @@ class KubernetesConfigService {
|
|||
|
||||
async downloadConfig() {
|
||||
const response = await this.KubernetesConfig.get();
|
||||
return this.FileSaver.saveAs(response.data, 'config');
|
||||
|
||||
const headers = response.headers();
|
||||
const contentDispositionHeader = headers['content-disposition'];
|
||||
const filename = contentDispositionHeader.replace('attachment;', '').trim();
|
||||
return this.FileSaver.saveAs(response.data, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,39 +14,31 @@ export function KubernetesResourcePoolService($async, EndpointService, Kubernete
|
|||
};
|
||||
|
||||
async function getOne(name) {
|
||||
try {
|
||||
const namespace = await KubernetesNamespaceService.get(name);
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
const namespace = await KubernetesNamespaceService.get(name);
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
async function getAll() {
|
||||
try {
|
||||
const namespaces = await KubernetesNamespaceService.get();
|
||||
const pools = await Promise.all(
|
||||
_.map(namespaces, async (namespace) => {
|
||||
const name = namespace.Name;
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
})
|
||||
);
|
||||
return pools;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const namespaces = await KubernetesNamespaceService.get();
|
||||
const pools = await Promise.all(
|
||||
_.map(namespaces, async (namespace) => {
|
||||
const name = namespace.Name;
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
})
|
||||
);
|
||||
return pools;
|
||||
}
|
||||
|
||||
function get(name) {
|
||||
|
@ -58,80 +50,68 @@ export function KubernetesResourcePoolService($async, EndpointService, Kubernete
|
|||
|
||||
function create(formValues) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
const [namespace, quota, ingresses, registries] = KubernetesResourcePoolConverter.formValuesToResourcePool(formValues);
|
||||
await KubernetesNamespaceService.create(namespace);
|
||||
const [namespace, quota, ingresses, registries] = KubernetesResourcePoolConverter.formValuesToResourcePool(formValues);
|
||||
await KubernetesNamespaceService.create(namespace);
|
||||
|
||||
if (quota) {
|
||||
await KubernetesResourceQuotaService.create(quota);
|
||||
}
|
||||
const ingressPromises = _.map(ingresses, (i) => KubernetesIngressService.create(i));
|
||||
await Promise.all(ingressPromises);
|
||||
|
||||
const endpointId = formValues.EndpointId;
|
||||
const registriesPromises = _.map(registries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
await Promise.all(registriesPromises);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (quota) {
|
||||
await KubernetesResourceQuotaService.create(quota);
|
||||
}
|
||||
const ingressPromises = _.map(ingresses, (i) => KubernetesIngressService.create(i));
|
||||
await Promise.all(ingressPromises);
|
||||
|
||||
const endpointId = formValues.EndpointId;
|
||||
const registriesPromises = _.map(registries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
await Promise.all(registriesPromises);
|
||||
});
|
||||
}
|
||||
|
||||
function patch(oldFormValues, newFormValues) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
const [oldNamespace, oldQuota, oldIngresses, oldRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(oldFormValues);
|
||||
const [newNamespace, newQuota, newIngresses, newRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(newFormValues);
|
||||
void oldNamespace, newNamespace;
|
||||
const [oldNamespace, oldQuota, oldIngresses, oldRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(oldFormValues);
|
||||
const [newNamespace, newQuota, newIngresses, newRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(newFormValues);
|
||||
void oldNamespace, newNamespace;
|
||||
|
||||
if (oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.patch(oldQuota, newQuota);
|
||||
} else if (!oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.create(newQuota);
|
||||
} else if (oldQuota && !newQuota) {
|
||||
await KubernetesResourceQuotaService.delete(oldQuota);
|
||||
}
|
||||
|
||||
const create = _.filter(newIngresses, (ing) => !_.find(oldIngresses, { Name: ing.Name }));
|
||||
const del = _.filter(oldIngresses, (ing) => !_.find(newIngresses, { Name: ing.Name }));
|
||||
const patch = _.without(newIngresses, ...create);
|
||||
|
||||
const createPromises = _.map(create, (i) => KubernetesIngressService.create(i));
|
||||
const delPromises = _.map(del, (i) => KubernetesIngressService.delete(i.Namespace, i.Name));
|
||||
const patchPromises = _.map(patch, (ing) => {
|
||||
const old = _.find(oldIngresses, { Name: ing.Name });
|
||||
ing.Paths = angular.copy(old.Paths);
|
||||
ing.PreviousHost = old.Host;
|
||||
return KubernetesIngressService.patch(old, ing);
|
||||
});
|
||||
|
||||
const promises = _.flatten([createPromises, delPromises, patchPromises]);
|
||||
await Promise.all(promises);
|
||||
|
||||
const endpointId = newFormValues.EndpointId;
|
||||
const keptRegistries = _.intersectionBy(oldRegistries, newRegistries, 'Id');
|
||||
const removedRegistries = _.without(oldRegistries, ...keptRegistries);
|
||||
|
||||
const newRegistriesPromises = _.map(newRegistries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
const removedRegistriesPromises = _.map(removedRegistries, (r) => {
|
||||
_.pull(r.RegistryAccesses[endpointId].Namespaces, newFormValues.Name);
|
||||
return EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]);
|
||||
});
|
||||
|
||||
await Promise.all(_.concat(newRegistriesPromises, removedRegistriesPromises));
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.patch(oldQuota, newQuota);
|
||||
} else if (!oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.create(newQuota);
|
||||
} else if (oldQuota && !newQuota) {
|
||||
await KubernetesResourceQuotaService.delete(oldQuota);
|
||||
}
|
||||
|
||||
const create = _.filter(newIngresses, (ing) => !_.find(oldIngresses, { Name: ing.Name }));
|
||||
const del = _.filter(oldIngresses, (ing) => !_.find(newIngresses, { Name: ing.Name }));
|
||||
const patch = _.without(newIngresses, ...create);
|
||||
|
||||
const createPromises = _.map(create, (i) => KubernetesIngressService.create(i));
|
||||
const delPromises = _.map(del, (i) => KubernetesIngressService.delete(i.Namespace, i.Name));
|
||||
const patchPromises = _.map(patch, (ing) => {
|
||||
const old = _.find(oldIngresses, { Name: ing.Name });
|
||||
ing.Paths = angular.copy(old.Paths);
|
||||
ing.PreviousHost = old.Host;
|
||||
return KubernetesIngressService.patch(old, ing);
|
||||
});
|
||||
|
||||
const promises = _.flatten([createPromises, delPromises, patchPromises]);
|
||||
await Promise.all(promises);
|
||||
|
||||
const endpointId = newFormValues.EndpointId;
|
||||
const keptRegistries = _.intersectionBy(oldRegistries, newRegistries, 'Id');
|
||||
const removedRegistries = _.without(oldRegistries, ...keptRegistries);
|
||||
|
||||
const newRegistriesPromises = _.map(newRegistries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
const removedRegistriesPromises = _.map(removedRegistries, (r) => {
|
||||
_.pull(r.RegistryAccesses[endpointId].Namespaces, newFormValues.Name);
|
||||
return EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]);
|
||||
});
|
||||
|
||||
await Promise.all(_.concat(newRegistriesPromises, removedRegistriesPromises));
|
||||
});
|
||||
}
|
||||
|
||||
function _delete(pool) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
await KubernetesNamespaceService.delete(pool.Namespace);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
await KubernetesNamespaceService.delete(pool.Namespace);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,9 @@ class KubernetesStackService {
|
|||
* GET
|
||||
*/
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const applications = await this.KubernetesApplicationService.get(namespace);
|
||||
const stacks = _.map(applications, (item) => item.StackName);
|
||||
return _.uniq(_.without(stacks, '-'));
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const applications = await this.KubernetesApplicationService.get(namespace);
|
||||
const stacks = _.map(applications, (item) => item.StackName);
|
||||
return _.uniq(_.without(stacks, '-'));
|
||||
}
|
||||
|
||||
get(namespace) {
|
||||
|
|
|
@ -20,28 +20,20 @@ class KubernetesVolumeService {
|
|||
* GET
|
||||
*/
|
||||
async getAsync(namespace, name) {
|
||||
try {
|
||||
const [pvc, pool] = await Promise.all([this.KubernetesPersistentVolumeClaimService.get(namespace, name), this.KubernetesResourcePoolService.get(namespace)]);
|
||||
return KubernetesVolumeConverter.pvcToVolume(pvc, pool);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const [pvc, pool] = await Promise.all([this.KubernetesPersistentVolumeClaimService.get(namespace, name), this.KubernetesResourcePoolService.get(namespace)]);
|
||||
return KubernetesVolumeConverter.pvcToVolume(pvc, pool);
|
||||
}
|
||||
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const data = await this.KubernetesResourcePoolService.get(namespace);
|
||||
const pools = data instanceof Array ? data : [data];
|
||||
const res = await Promise.all(
|
||||
_.map(pools, async (pool) => {
|
||||
const pvcs = await this.KubernetesPersistentVolumeClaimService.get(pool.Namespace.Name);
|
||||
return _.map(pvcs, (pvc) => KubernetesVolumeConverter.pvcToVolume(pvc, pool));
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const data = await this.KubernetesResourcePoolService.get(namespace);
|
||||
const pools = data instanceof Array ? data : [data];
|
||||
const res = await Promise.all(
|
||||
_.map(pools, async (pool) => {
|
||||
const pvcs = await this.KubernetesPersistentVolumeClaimService.get(pool.Namespace.Name);
|
||||
return _.map(pvcs, (pvc) => KubernetesVolumeConverter.pvcToVolume(pvc, pool));
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
}
|
||||
|
||||
get(namespace, name) {
|
||||
|
@ -55,11 +47,7 @@ class KubernetesVolumeService {
|
|||
* DELETE
|
||||
*/
|
||||
async deleteAsync(volume) {
|
||||
try {
|
||||
await this.KubernetesPersistentVolumeClaimService.delete(volume.PersistentVolumeClaim);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
await this.KubernetesPersistentVolumeClaimService.delete(volume.PersistentVolumeClaim);
|
||||
}
|
||||
|
||||
delete(volume) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue