From 0524c613f25548b6bb2c75e5a267112372585bbf Mon Sep 17 00:00:00 2001 From: zhoujunhao <18853925545@163.com> Date: Mon, 15 Oct 2018 15:20:13 +0800 Subject: [PATCH] [FIX] Fixed a bug that caused the label length to exceed the limit when opening multiple tcp ports. --- entrance/source/handle.go | 30 ++++++++++++++++++++++-------- worker/appm/pod.go | 11 ++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/entrance/source/handle.go b/entrance/source/handle.go index 8a662ee6e..07ce65858 100644 --- a/entrance/source/handle.go +++ b/entrance/source/handle.go @@ -116,18 +116,32 @@ func (m *Manager) podSource(pods *v1.Pod, method core.EventMethod) { continue } } - ppInfo := pods.Labels["protocols"] - if ppInfo == "" { - ppInfo = "1234_._ptth" - } mapPP := make(map[string]string) - infoList := strings.Split(ppInfo, "-.-") - if len(infoList) > 0 { - for _, pps := range infoList { - portInfo := strings.Split(pps, "_._") + ppInfo, ok := pods.Labels["protocols"] + if ok { + if ppInfo == "" { + ppInfo = "1234_._ptth" + } + infoList := strings.Split(ppInfo, "-.-") + if len(infoList) > 0 { + for _, pps := range infoList { + portInfo := strings.Split(pps, "_._") + mapPP[portInfo[0]] = portInfo[1] + } + } + } else { + protocolsNumber := pods.Labels["protocols_number"] + number, err := strconv.Atoi(protocolsNumber); + if err != nil { + logrus.Errorf("ports number converted to int failed:", err.Error()) + } + for i := 0; i < number; i++ { + protocol := pods.Labels[fmt.Sprintf("%s_%d", "protocol", i)] + portInfo := strings.Split(protocol,"_._") mapPP[portInfo[0]] = portInfo[1] } } + //protocols: 5000_._http-.-8080_._stream s := &config.SourceBranch{ Tenant: pods.Labels["tenant_name"], diff --git a/worker/appm/pod.go b/worker/appm/pod.go index 1df17e5a7..84995d2a7 100644 --- a/worker/appm/pod.go +++ b/worker/appm/pod.go @@ -206,14 +206,11 @@ func (p *PodTemplateSpecBuild) Build(creatorID string) (*v1.PodTemplateSpec, err outPorts, err = p.CreateUpstreamPluginMappingPort(outPorts, pluginPorts) } labels["service_type"] = "outer" - var pStr string - for _, p := range outPorts { - if pStr != "" { - pStr += "-.-" - } - pStr += fmt.Sprintf("%d_._%s", p.ContainerPort, p.Protocol) + labels["protocols_number"] = string(len(outPorts)) + for i, p := range outPorts { + key := fmt.Sprintf("%s_%d", "protocol", i) + labels[key] = fmt.Sprintf("%d_._%s", p.ContainerPort, p.Protocol) } - labels["protocols"] = pStr } //step7: set hostname if p.hostName != "" {