[FIX] Fixed a bug that caused the label length to exceed the limit when opening multiple tcp ports.

This commit is contained in:
zhoujunhao 2018-10-15 15:20:13 +08:00
parent d59eb73709
commit 0524c613f2
2 changed files with 26 additions and 15 deletions

View File

@ -116,11 +116,12 @@ func (m *Manager) podSource(pods *v1.Pod, method core.EventMethod) {
continue
}
}
ppInfo := pods.Labels["protocols"]
mapPP := make(map[string]string)
ppInfo, ok := pods.Labels["protocols"]
if ok {
if ppInfo == "" {
ppInfo = "1234_._ptth"
}
mapPP := make(map[string]string)
infoList := strings.Split(ppInfo, "-.-")
if len(infoList) > 0 {
for _, pps := range infoList {
@ -128,6 +129,19 @@ func (m *Manager) podSource(pods *v1.Pod, method core.EventMethod) {
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"],

View File

@ -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 += "-.-"
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)
}
pStr += fmt.Sprintf("%d_._%s", p.ContainerPort, p.Protocol)
}
labels["protocols"] = pStr
}
//step7: set hostname
if p.hostName != "" {