From fcb76f570e028a7d4cf6e38502b49edc3f8d4376 Mon Sep 17 00:00:00 2001
From: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com>
Date: Fri, 23 Sep 2022 16:11:35 +1200
Subject: [PATCH] feat(ingress): remove ingresses from add and edit application
EE-4206 (#7677)
---
.../applicationsDatatableController.js | 4 +-
.../kube-services/kube-services.controller.js | 15 +----
.../kube-services/kube-services.html | 47 +++++++--------
app/kubernetes/ingress/converter.js | 1 +
app/kubernetes/services/applicationService.js | 60 +------------------
.../ingress-table/ingress-table.controller.js | 1 +
.../ingress-table/ingress-table.html | 6 +-
7 files changed, 31 insertions(+), 103 deletions(-)
diff --git a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
index e3049e073..e876f5550 100644
--- a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
+++ b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
@@ -93,8 +93,8 @@ angular.module('portainer.docker').controller('KubernetesApplicationsDatatableCo
// Map all ingress rules in published ports to their respective URLs
const ingressUrls = item.PublishedPorts.flatMap((pp) => pp.IngressRules)
.filter(({ Host, IP }) => Host || IP)
- .map(({ Host, IP, Port, Path }) => {
- let scheme = Port === 443 ? 'https' : 'http';
+ .map(({ Host, IP, Path, TLS }) => {
+ let scheme = TLS && TLS.filter((tls) => tls.hosts && tls.hosts.includes(Host)).length > 0 ? 'https' : 'http';
return `${scheme}://${Host || IP}${Path}`;
});
diff --git a/app/kubernetes/components/kube-services/kube-services.controller.js b/app/kubernetes/components/kube-services/kube-services.controller.js
index 32d6b8515..69f96241b 100644
--- a/app/kubernetes/components/kube-services/kube-services.controller.js
+++ b/app/kubernetes/components/kube-services/kube-services.controller.js
@@ -11,12 +11,7 @@ export default class KubeServicesViewController {
addEntry(service) {
const p = new KubernetesService();
- if (service === KubernetesApplicationPublishingTypes.INGRESS) {
- p.Type = KubernetesApplicationPublishingTypes.CLUSTER_IP;
- p.Ingress = true;
- } else {
- p.Type = service;
- }
+ p.Type = service;
p.Selector = this.formValues.Selector;
@@ -62,8 +57,6 @@ export default class KubeServicesViewController {
return KubernetesServiceTypes.NODE_PORT;
case KubernetesApplicationPublishingTypes.LOAD_BALANCER:
return KubernetesServiceTypes.LOAD_BALANCER;
- case KubernetesApplicationPublishingTypes.INGRESS:
- return KubernetesServiceTypes.INGRESS;
}
}
@@ -79,8 +72,6 @@ export default class KubeServicesViewController {
return 'fa fa-list';
case KubernetesApplicationPublishingTypes.LOAD_BALANCER:
return 'fa fa-project-diagram';
- case KubernetesApplicationPublishingTypes.INGRESS:
- return 'fa fa-route';
}
}
$onInit() {
@@ -98,10 +89,6 @@ export default class KubeServicesViewController {
typeName: KubernetesServiceTypes.LOAD_BALANCER,
typeValue: KubernetesApplicationPublishingTypes.LOAD_BALANCER,
},
- {
- typeName: KubernetesServiceTypes.INGRESS,
- typeValue: KubernetesApplicationPublishingTypes.INGRESS,
- },
],
selected: KubernetesApplicationPublishingTypes.CLUSTER_IP,
endpointId: this.EndpointProvider.endpointID(),
diff --git a/app/kubernetes/components/kube-services/kube-services.html b/app/kubernetes/components/kube-services/kube-services.html
index f21b21b1e..d579db1ea 100644
--- a/app/kubernetes/components/kube-services/kube-services.html
+++ b/app/kubernetes/components/kube-services/kube-services.html
@@ -1,5 +1,12 @@
Publishing the application
-
+
+
+
+
+ Publish your application by creating a ClusterIP service for it, which you may then expose via an ingress.
+
+
+
-
-
-
-
- Ingress
-
-
-
-
diff --git a/app/kubernetes/ingress/converter.js b/app/kubernetes/ingress/converter.js
index 774d2690a..67fdc5bed 100644
--- a/app/kubernetes/ingress/converter.js
+++ b/app/kubernetes/ingress/converter.js
@@ -25,6 +25,7 @@ export class KubernetesIngressConverter {
ingRule.IP = data.status.loadBalancer.ingress ? data.status.loadBalancer.ingress[0].ip : undefined;
ingRule.Port = path.backend.service.port.number;
ingRule.Path = path.path;
+ ingRule.TLS = data.spec.tls;
return ingRule;
});
});
diff --git a/app/kubernetes/services/applicationService.js b/app/kubernetes/services/applicationService.js
index 5eaa865bd..ea90dc985 100644
--- a/app/kubernetes/services/applicationService.js
+++ b/app/kubernetes/services/applicationService.js
@@ -2,12 +2,7 @@ import _ from 'lodash-es';
import angular from 'angular';
import PortainerError from 'Portainer/error';
-import {
- KubernetesApplication,
- KubernetesApplicationDeploymentTypes,
- KubernetesApplicationPublishingTypes,
- KubernetesApplicationTypes,
-} from 'Kubernetes/models/application/models';
+import { KubernetesApplication, KubernetesApplicationDeploymentTypes, KubernetesApplicationTypes } from 'Kubernetes/models/application/models';
import KubernetesApplicationHelper from 'Kubernetes/helpers/application';
import KubernetesApplicationRollbackHelper from 'Kubernetes/helpers/application/rollback';
import KubernetesApplicationConverter from 'Kubernetes/converters/application';
@@ -17,7 +12,6 @@ import { KubernetesDaemonSet } from 'Kubernetes/models/daemon-set/models';
import KubernetesServiceHelper from 'Kubernetes/helpers/serviceHelper';
import { KubernetesHorizontalPodAutoScalerHelper } from 'Kubernetes/horizontal-pod-auto-scaler/helper';
import { KubernetesHorizontalPodAutoScalerConverter } from 'Kubernetes/horizontal-pod-auto-scaler/converter';
-import { KubernetesIngressConverter } from 'Kubernetes/ingress/converter';
import KubernetesPodConverter from 'Kubernetes/pod/converter';
class KubernetesApplicationService {
@@ -79,12 +73,6 @@ class KubernetesApplicationService {
return apiService;
}
- _generateIngressPatchPromises(oldIngresses, newIngresses) {
- return _.map(newIngresses, (newIng) => {
- const oldIng = _.find(oldIngresses, { Name: newIng.Name });
- return this.KubernetesIngressService.patch(oldIng, newIng);
- });
- }
/* #endregion */
/* #region GET */
@@ -221,26 +209,12 @@ class KubernetesApplicationService {
*/
async createAsync(formValues) {
// formValues -> Application
- let [app, headlessService, services, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
+ let [app, headlessService, services, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
if (services) {
services.forEach(async (service) => {
await this.KubernetesServiceService.create(service);
});
-
- //Generate all ingresses from current form by passing services object
- const ingresses = KubernetesIngressConverter.generateNewIngresses(formValues.OriginalIngresses, services);
- if (ingresses) {
- //Update original ingress with current ingress
- await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
- }
- }
-
- if (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);
@@ -322,20 +296,10 @@ class KubernetesApplicationService {
newServices.forEach(async (service) => {
await this.KubernetesServiceService.create(service);
});
-
- // Create multiple ingress
- const ingresses = KubernetesIngressConverter.generateNewIngresses(oldFormValues.OriginalIngresses, newServices);
- if (ingresses) {
- await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, ingresses));
- }
}
// Delete services ( only called when all services been deleted )
if (oldServices.length !== 0 && newServices.length === 0) {
- const ingresses = KubernetesIngressConverter.removeIngressesPaths(oldFormValues.OriginalIngresses, oldServices);
- if (ingresses) {
- await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, ingresses));
- }
await this.KubernetesServiceService.deleteAll(oldServices);
}
@@ -356,15 +320,6 @@ class KubernetesApplicationService {
await this.KubernetesServiceService.create(newService);
}
});
-
- // Clear all ingress which is related to services in this application
- const clearIngress = KubernetesIngressConverter.removeIngressesPaths(oldFormValues.OriginalIngresses, oldServices);
-
- // Generate all ingress from services in this application
- const newIngress = KubernetesIngressConverter.generateNewIngresses(clearIngress, newServices);
-
- // Compare new ingress with old ingress to get api patch
- await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, newIngress));
}
const newKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(newApp);
@@ -438,17 +393,6 @@ class KubernetesApplicationService {
if (application.ServiceType) {
// delete headless service && non-headless service
await this.KubernetesServiceService.delete(application.Services);
-
- if (application.Ingresses.length) {
- const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
- const formValues = {
- OriginalIngresses: originalIngresses,
- PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
- };
- const ingresses = KubernetesIngressConverter.applicationFormValuesToDeleteIngresses(formValues, application);
-
- await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
- }
}
if (!_.isEmpty(application.AutoScaler)) {
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
diff --git a/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.controller.js b/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.controller.js
index d09d9f6c8..878f96310 100644
--- a/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.controller.js
+++ b/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.controller.js
@@ -18,6 +18,7 @@ export default class KubernetesApplicationIngressController {
_.forEach(ingresses, (ingress) => {
_.forEach(ingress.Paths, (path) => {
if (path.ServiceName === service.metadata.name) {
+ path.Secure = ingress.TLS && ingress.TLS.filter((tls) => tls.hosts && tls.hosts.includes(path.Host)).length > 0;
this.applicationIngress.push(path);
this.hasIngress = true;
}
diff --git a/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.html b/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.html
index 76b0e8216..58967e9cb 100644
--- a/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.html
+++ b/app/kubernetes/views/applications/edit/components/ingress-table/ingress-table.html
@@ -10,13 +10,15 @@
HTTP Route |
- {{ ingress.IngressName }} |
+ {{ ingress.IngressName }} |
{{ ingress.ServiceName }} |
{{ ingress.Host }} |
{{ ingress.Port }} |
{{ ingress.Path }} |
{{ ingress.Host }}{{ ingress.Path }} | {{ ingress.Host }}{{ ingress.Path }}