hotfix: envoy control-plane detect enable ipv6 or not to add route (#389)

This commit is contained in:
naison
2024-12-09 18:50:44 +08:00
committed by GitHub
parent d9d4091905
commit 9ebc95352a
3 changed files with 27 additions and 3 deletions

View File

@@ -42,7 +42,7 @@ type Rule struct {
PortMap map[int32]int32
}
func (a *Virtual) To() (
func (a *Virtual) To(enableIPv6 bool) (
listeners []types.Resource,
clusters []types.Resource,
routes []types.Resource,
@@ -56,7 +56,13 @@ func (a *Virtual) To() (
var rr []*route.Route
for _, rule := range a.Rules {
for _, ip := range []string{rule.LocalTunIPv4, rule.LocalTunIPv6} {
var ips []string
if enableIPv6 {
ips = []string{rule.LocalTunIPv4, rule.LocalTunIPv6}
} else {
ips = []string{rule.LocalTunIPv4}
}
for _, ip := range ips {
clusterName := fmt.Sprintf("%s_%v", ip, rule.PortMap[port.ContainerPort])
clusters = append(clusters, ToCluster(clusterName))
endpoints = append(endpoints, ToEndPoint(clusterName, ip, rule.PortMap[port.ContainerPort]))

View File

@@ -17,6 +17,8 @@ import (
log "github.com/sirupsen/logrus"
utilcache "k8s.io/apimachinery/pkg/util/cache"
"sigs.k8s.io/yaml"
"github.com/wencaiwulue/kubevpn/v2/pkg/util"
)
type Processor struct {
@@ -50,6 +52,7 @@ func (p *Processor) ProcessFile(file NotifyMessage) error {
p.logger.Errorf("error parsing yaml file: %+v", err)
return err
}
enableIPv6, _ := util.DetectSupportIPv6()
for _, config := range configList {
if len(config.Uid) == 0 {
continue
@@ -62,7 +65,7 @@ func (p *Processor) ProcessFile(file NotifyMessage) error {
}
p.logger.Debugf("update config, version %d, config %v", p.version, config)
listeners, clusters, routes, endpoints := config.To()
listeners, clusters, routes, endpoints := config.To(enableIPv6)
resources := map[resource.Type][]types.Resource{
resource.ListenerType: listeners, // listeners
resource.RouteType: routes, // routes