feat(k8s) EE-1543 Allow Services to be managed for external kube apps

This commit is contained in:
Simon Meng
2021-09-28 09:23:39 +13:00
parent 34f6e11f1d
commit 788fe853dd
6 changed files with 1050 additions and 1036 deletions

View File

@@ -16,7 +16,8 @@ function _publishedPortToServicePort(formValues, publishedPort, type) {
const name = formValues.Name;
const res = new KubernetesServicePort();
res.name = _.toLower(name + '-' + publishedPort.ContainerPort + '-' + publishedPort.Protocol);
res.port = type === KubernetesServiceTypes.LOAD_BALANCER ? publishedPort.LoadBalancerPort : publishedPort.ContainerPort;
// if generatePublishedPortsFormValuesFromPublishedPorts backups the ServicePort then use it instead of ContainerPort
res.port = type === KubernetesServiceTypes.LOAD_BALANCER ? publishedPort.LoadBalancerPort : publishedPort.ServicePort || publishedPort.ContainerPort;
res.targetPort = publishedPort.ContainerPort;
res.protocol = publishedPort.Protocol;
if (type === KubernetesServiceTypes.NODE_PORT && publishedPort.NodePort) {
@@ -48,7 +49,7 @@ class KubernetesServiceConverter {
res.Type = KubernetesServiceTypes.LOAD_BALANCER;
}
const ports = _.map(formValues.PublishedPorts, (item) => _publishedPortToServicePort(formValues, item, res.Type));
res.Ports = _.uniqBy(_.without(ports, undefined), (p) => p.targetPort + p.protocol);
res.Ports = _.uniqBy(_.without(ports, undefined), (p) => p.targetPort + p.protocol + p.port);
return res;
}

View File

@@ -289,6 +289,12 @@ class KubernetesApplicationHelper {
}
res.Protocol = port.Protocol;
res.ContainerPort = port.TargetPort;
// when editing an external app ports, backup the ServicePort to the form values so that the service can be correctly patched
if (port.Port !== port.TargetPort) {
res.ServicePort = port.Port;
}
if (serviceType === KubernetesServiceTypes.LOAD_BALANCER) {
res.LoadBalancerPort = port.Port;
res.LoadBalancerNodePort = port.NodePort;

View File

@@ -113,6 +113,7 @@ export function KubernetesApplicationPublishedPortFormValue() {
IsNew: true,
ContainerPort: '',
NodePort: '',
ServicePort: '',
LoadBalancerPort: '',
LoadBalancerNodePort: undefined, // only filled to save existing loadbalancer nodePort and drop it when moving app exposure from LB to Internal/NodePort
Protocol: 'TCP',

File diff suppressed because it is too large Load Diff

View File

@@ -1057,6 +1057,10 @@ class KubernetesCreateApplicationController {
}
});
}
isEditingExternalApp() {
return this.state.isEdit && KubernetesApplicationHelper.isExternalApplication(this.application);
}
/* #endregion */
/* #region ON INIT */

View File

@@ -198,14 +198,7 @@
<rd-widget>
<rd-widget-body>
<div ng-if="!ctrl.isSystemNamespace()" style="margin-bottom: 15px;">
<button
ng-if="!ctrl.isExternalApplication()"
type="button"
class="btn btn-sm btn-primary"
ui-sref="kubernetes.applications.application.edit"
style="margin-left: 0;"
data-cy="k8sAppDetail-editAppButton"
>
<button type="button" class="btn btn-sm btn-primary" ui-sref="kubernetes.applications.application.edit" style="margin-left: 0;" data-cy="k8sAppDetail-editAppButton">
<i class="fa fa-file-code space-right" aria-hidden="true"></i>Edit this application
</button>
<button