fix issue on editing app with persisted folder (#6646)

Co-authored-by: Richard Wei <dgui.wei@gmail.com>
pull/6728/head
Richard Wei 2022-04-06 05:42:01 +12:00 committed by GitHub
parent 2059a9e064
commit 7e28b3ca3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 69 deletions

View File

@ -281,47 +281,50 @@ class KubernetesApplicationHelper {
let services = []; let services = [];
if (app.Services) { if (app.Services) {
app.Services.forEach(function (service) { app.Services.forEach(function (service) {
const svc = new KubernetesService(); //skip generate formValues if service = headless service ( clusterIp === "None" )
svc.Namespace = service.metadata.namespace; if (service.spec.clusterIP !== 'None') {
svc.Name = service.metadata.name; const svc = new KubernetesService();
svc.StackName = service.StackName; svc.Namespace = service.metadata.namespace;
svc.ApplicationOwner = app.ApplicationOwner; svc.Name = service.metadata.name;
svc.ApplicationName = app.ApplicationName; svc.StackName = service.StackName;
svc.Type = service.spec.type; svc.ApplicationOwner = app.ApplicationOwner;
if (service.spec.type === KubernetesServiceTypes.CLUSTER_IP) { svc.ApplicationName = app.ApplicationName;
svc.Type = 1; svc.Type = service.spec.type;
} else if (service.spec.type === KubernetesServiceTypes.NODE_PORT) { if (service.spec.type === KubernetesServiceTypes.CLUSTER_IP) {
svc.Type = 2; svc.Type = 1;
} else if (service.spec.type === KubernetesServiceTypes.LOAD_BALANCER) { } else if (service.spec.type === KubernetesServiceTypes.NODE_PORT) {
svc.Type = 3; svc.Type = 2;
} } else if (service.spec.type === KubernetesServiceTypes.LOAD_BALANCER) {
svc.Type = 3;
}
let ports = []; let ports = [];
service.spec.ports.forEach(function (port) { service.spec.ports.forEach(function (port) {
const svcport = new KubernetesServicePort(); const svcport = new KubernetesServicePort();
svcport.name = port.name; svcport.name = port.name;
svcport.port = port.port; svcport.port = port.port;
svcport.nodePort = port.nodePort; svcport.nodePort = port.nodePort;
svcport.protocol = port.protocol; svcport.protocol = port.protocol;
svcport.targetPort = port.targetPort; svcport.targetPort = port.targetPort;
app.Ingresses.value.forEach((ingress) => { app.Ingresses.value.forEach((ingress) => {
const ingressMatched = _.find(ingress.Paths, { ServiceName: service.metadata.name }); const ingressMatched = _.find(ingress.Paths, { ServiceName: service.metadata.name });
if (ingressMatched) { if (ingressMatched) {
svcport.ingress = { svcport.ingress = {
IngressName: ingressMatched.IngressName, IngressName: ingressMatched.IngressName,
Host: ingressMatched.Host, Host: ingressMatched.Host,
Path: ingressMatched.Path, Path: ingressMatched.Path,
}; };
svc.Ingress = true; svc.Ingress = true;
} }
});
ports.push(svcport);
}); });
svc.Ports = ports;
ports.push(svcport); svc.Selector = app.Raw.spec.selector.matchLabels;
}); services.push(svc);
svc.Ports = ports; }
svc.Selector = app.Raw.spec.selector.matchLabels;
services.push(svc);
}); });
return services; return services;

View File

@ -429,10 +429,10 @@ class KubernetesApplicationService {
if (apiService === this.KubernetesStatefulSetService) { if (apiService === this.KubernetesStatefulSetService) {
const headlessServicePayload = angular.copy(payload); const headlessServicePayload = angular.copy(payload);
headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName; headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName;
await this.KubernetesServiceService.delete(headlessServicePayload);
} }
if (application.ServiceType) { if (application.ServiceType) {
// delete headless service && non-headless service
await this.KubernetesServiceService.delete(application.Services); await this.KubernetesServiceService.delete(application.Services);
if (application.Ingresses.length) { if (application.Ingresses.length) {

View File

@ -257,7 +257,7 @@
This application is not exposing any port. This application is not exposing any port.
</div> </div>
<div ng-if="ctrl.application.PublishedPorts.length > 0"> <div ng-if="ctrl.application.Services.length !== 0">
<!-- Services notice --> <!-- Services notice -->
<div> <div>
<div class="small text-muted"> <div class="small text-muted">

View File

@ -237,37 +237,39 @@ function getVolumeClaimUpdateResourceSummary(oldPVC, newPVC) {
// getServiceUpdateResourceSummary replicates KubernetesServiceService.patch // getServiceUpdateResourceSummary replicates KubernetesServiceService.patch
function getServiceUpdateResourceSummary(oldServices, newServices) { function getServiceUpdateResourceSummary(oldServices, newServices) {
let summary = []; let summary = [];
newServices.forEach((newService) => { // skip update summary when service is headless service
const oldServiceMatched = _.find(oldServices, { Name: newService.Name }); if (!oldServices.Headless) {
if (oldServiceMatched) { newServices.forEach((newService) => {
const payload = KubernetesServiceConverter.patchPayload(oldServiceMatched, newService); const oldServiceMatched = _.find(oldServices, { Name: newService.Name });
if (payload.length) { if (oldServiceMatched) {
const serviceUpdate = { const payload = KubernetesServiceConverter.patchPayload(oldServiceMatched, newService);
action: UPDATE, if (payload.length) {
kind: KubernetesResourceTypes.SERVICE, const serviceUpdate = {
name: oldServiceMatched.Name, action: UPDATE,
type: oldServiceMatched.Type || KubernetesServiceTypes.CLUSTER_IP, kind: KubernetesResourceTypes.SERVICE,
}; name: oldServiceMatched.Name,
summary.push(serviceUpdate); type: oldServiceMatched.Type || KubernetesServiceTypes.CLUSTER_IP,
};
summary.push(serviceUpdate);
}
} else {
const emptyService = new KubernetesService();
const payload = KubernetesServiceConverter.patchPayload(emptyService, newService);
if (payload.length) {
const serviceCreate = { action: CREATE, kind: KubernetesResourceTypes.SERVICE, name: newService.Name, type: newService.Type || KubernetesServiceTypes.CLUSTER_IP };
summary.push(serviceCreate);
}
} }
} else { });
const emptyService = new KubernetesService();
const payload = KubernetesServiceConverter.patchPayload(emptyService, newService); oldServices.forEach((oldService) => {
if (payload.length) { const newServiceMatched = _.find(newServices, { Name: oldService.Name });
const serviceCreate = { action: CREATE, kind: KubernetesResourceTypes.SERVICE, name: newService.Name, type: newService.Type || KubernetesServiceTypes.CLUSTER_IP }; if (!newServiceMatched) {
summary.push(serviceCreate); const serviceDelete = { action: DELETE, kind: KubernetesResourceTypes.SERVICE, name: oldService.Name, type: oldService.Type || KubernetesServiceTypes.CLUSTER_IP };
summary.push(serviceDelete);
} }
} });
}); }
oldServices.forEach((oldService) => {
const newServiceMatched = _.find(newServices, { Name: oldService.Name });
if (!newServiceMatched) {
const serviceDelete = { action: DELETE, kind: KubernetesResourceTypes.SERVICE, name: oldService.Name, type: oldService.Type || KubernetesServiceTypes.CLUSTER_IP };
summary.push(serviceDelete);
}
});
if (summary.length !== 0) { if (summary.length !== 0) {
return summary; return summary;
} }