[ADD] add udp stream

This commit is contained in:
GLYASAI 2018-12-01 20:08:05 +08:00
parent 7b600fb995
commit cc28eca3f7
3 changed files with 35 additions and 11 deletions

View File

@ -428,7 +428,12 @@ func (s *rbdStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
if host == "" {
host = s.conf.IP
}
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.Backend.ServiceName)
protocol := s.GetServiceProtocol(svcKey, ing.Spec.Backend.ServicePort.IntVal)
listening := fmt.Sprintf("%s:%v", host, anns.L4.L4Port)
if string(protocol) == string(v1.ProtocolUDP) {
listening = fmt.Sprintf("%s %s", listening, "udp")
}
backendName := util.BackendName(listening, ing.Namespace, anns.Weight.Weight)
vs := l4vsMap[listening]
@ -478,7 +483,6 @@ func (s *rbdStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
vs = &v1.VirtualService{
Listening: []string{"80"},
ServerName: virSrvName,
Protocol: v1.HTTP,
Locations: []*v1.Location{},
ForceSSLRedirect: anns.Rewrite.ForceSSLRedirect,
}
@ -496,11 +500,7 @@ func (s *rbdStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
}
for _, path := range rule.IngressRuleValue.HTTP.Paths {
p := path.Path
if p == "/" {
p = "root"
}
locKey := fmt.Sprintf("%s_%s", virSrvName, p)
locKey := fmt.Sprintf("%s_%s", virSrvName, path.Path)
location := srvLocMap[locKey]
l7PoolMap[path.Backend.ServiceName] = struct{}{}
// if location do not exists, then creates a new one
@ -528,6 +528,7 @@ func (s *rbdStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
nameCondition.Value = map[string]string{"1": "1"}
backendName = fmt.Sprintf("%s_%s", locKey, v1.DefaultType)
}
// TODO: put backendName, weight in struct
backendName = util.BackendName(backendName, ing.Namespace, anns.Weight.Weight)
location.NameCondition[backendName] = nameCondition
l7PoolBackendMap[path.Backend.ServiceName] = append(l7PoolBackendMap[path.Backend.ServiceName], backendName)
@ -595,6 +596,21 @@ func (s *rbdStore) ListIngresses() []*extensions.Ingress {
return ingresses
}
// GetServiceProtocol returns the Service matching key and port.
func (s *rbdStore) GetServiceProtocol(key string, port int32) corev1.Protocol {
svcs, err := s.listers.Service.ByKey(key)
if err != nil {
return corev1.ProtocolTCP
}
for _, p := range svcs.Spec.Ports {
if p.Port == port {
return p.Protocol
}
}
return corev1.ProtocolTCP
}
// GetIngressAnnotations returns the parsed annotations of an Ingress matching key.
func (s rbdStore) GetIngressAnnotations(key string) (*annotations.Ingress, error) {
ia, err := s.listers.IngressAnnotation.ByKey(key)

View File

@ -29,6 +29,7 @@ func BackendName(name string, ns string, weight int) string {
name = strings.Replace(name, ".", "_", -1)
name = strings.Replace(name, "-", "_", -1)
name = strings.Replace(name, ":", "_", -1)
name = strings.Replace(name, "/", "slash", -1)
name = fmt.Sprintf("%s%s%d", "N", name, weight)
return name
}

View File

@ -18,18 +18,25 @@
package v1
type ProtocolType string
import corev1 "k8s.io/api/core/v1"
// Protocol defines network protocols supported for things like container ports.
type Protocol string
const (
STREAM ProtocolType = "stream"
HTTP ProtocolType = "http"
// ProtocolTCP is the TCP protocol.
ProtocolTCP Protocol = "TCP"
// ProtocolUDP is the UDP protocol.
ProtocolUDP Protocol = "UDP"
// ProtocolSCTP is the SCTP protocol.
ProtocolSCTP Protocol = "SCTP"
)
//VirtualService VirtualService
type VirtualService struct {
Meta
Enabled bool `json:"enable"`
Protocol ProtocolType `json:"protocol"` //default stream
Enabled bool `json:"enable"`
Protocol corev1.Protocol `json:"protocol"`
// BackendProtocol indicates which protocol should be used to communicate with the service
BackendProtocol string `json:"backend-protocol"`
Port int32 `json:"port"`