func constructServiceSpec()

in pkg/common/utils/resource/service.go [141:167]


func constructServiceSpec(exportService *v1.ExportService, svc *corev1.Service, selector map[string]string, ports []corev1.ServicePort) {
	var exportPorts []v1.DorisServicePort
	if exportService != nil {
		exportPorts = exportService.ServicePorts
	}

	for _, ep := range exportPorts {
		for i, _ := range ports {
			if int(ep.TargetPort) == ports[i].TargetPort.IntValue() {
				ports[i].NodePort = ep.NodePort
			}
		}
	}

	svc.Spec = corev1.ServiceSpec{
		Selector:        selector,
		Ports:           ports,
		SessionAffinity: corev1.ServiceAffinityClientIP,
	}

	// The external load balancer provided by the cloud provider may cause the client IP received by the service to change.
	if exportService != nil && exportService.Type == corev1.ServiceTypeLoadBalancer {
		svc.Spec.SessionAffinity = corev1.ServiceAffinityNone
	}

	setServiceType(exportService, svc)
}