func BuildExternalService()

in pkg/common/utils/resource/service.go [97:139]


func BuildExternalService(dcr *v1.DorisCluster, componentType v1.ComponentType, config map[string]interface{}) corev1.Service {
	labels := v1.GenerateExternalServiceLabels(dcr, componentType)
	selector := v1.GenerateServiceSelector(dcr, componentType)
	//the k8s service type.
	var ports []corev1.ServicePort
	var exportService *v1.ExportService

	switch componentType {
	case v1.Component_FE:
		exportService = dcr.Spec.FeSpec.Service
		ports = getFeServicePorts(config)
	case v1.Component_BE:
		//cn is be, but for user we should make them clear for ability recognition
		exportService = dcr.Spec.BeSpec.Service
		ports = getBeServicePorts(config)
	case v1.Component_CN:
		exportService = dcr.Spec.CnSpec.Service
		ports = getBeServicePorts(config)
	default:
		klog.Infof("BuildExternalService componentType %s not supported.", componentType)
	}

	svc := corev1.Service{
		ObjectMeta: metav1.ObjectMeta{
			Name:      v1.GenerateExternalServiceName(dcr, componentType),
			Namespace: dcr.Namespace,
			Labels:    labels,
		},
	}

	constructServiceSpec(exportService, &svc, selector, ports)
	if exportService != nil {
		svc.Annotations = exportService.Annotations
	}

	svc.OwnerReferences = []metav1.OwnerReference{GetOwnerReference(dcr)}
	// the code is invalid, duplicate with ServiceDeepEqual
	//hso := serviceHashObject(&svc)
	//anno := map[string]string{}
	//anno[v1.ComponentResourceHash] = hash.HashObject(hso)
	//svc.Annotations = anno
	return svc
}