hotfix: swap envoy rule header nil to last position (#662)

This commit is contained in:
naison
2025-07-04 19:53:16 +08:00
committed by GitHub
parent 61a33ff5bd
commit e490f72a78
3 changed files with 16 additions and 4 deletions

View File

@@ -53,9 +53,9 @@ func (c *ConnectOptions) Cleanup(logCtx context.Context) {
if c.dhcp != nil {
err := c.dhcp.ReleaseIP(ctx, ipv4, ipv6)
if err != nil {
plog.G(logCtx).Errorf("Failed to release IP to DHCP server: %v", err)
plog.G(logCtx).Errorf("Failed to IPv4 %v IPv6 %v: %v", ipv4, ipv6, err)
} else {
plog.G(logCtx).Infof("Releaseed IPv4 %v IPv6 %v to DHCP server", ipv4, ipv6)
plog.G(logCtx).Infof("Released IPv4 %v IPv6 %v", ipv4, ipv6)
}
}
if c.clientset != nil {

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"sort"
"strings"
"time"
@@ -260,6 +261,17 @@ func addVirtualRule(v []*controlplane.Virtual, ns, nodeID string, port []control
if v[index].Ports == nil {
v[index].Ports = port
}
// envoy rule have order, eg:
// 1. null header to a
// 2. foo=bar to b
// then will never hit to b
// so needs to let null header to last rule
for x := range v {
sort.SliceStable(v[x].Rules, func(i, j int) bool {
return len(v[x].Rules[i].Headers) != 0
})
}
return v
}

View File

@@ -193,9 +193,9 @@ func (h *admissionReviewHandler) handleDelete(ar v1.AdmissionReview) *v1.Admissi
defer h.Unlock()
err := h.dhcp.ReleaseIP(context.Background(), ipv4, ipv6)
if err != nil {
plog.G(context.Background()).Errorf("Failed to release IPv4 %v IPv6 %s to DHCP server: %v", ipv4, ipv6, err)
plog.G(context.Background()).Errorf("Failed to release IPv4 %v IPv6 %s: %v", ipv4, ipv6, err)
} else {
plog.G(context.Background()).Debugf("Release IPv4 %v IPv6 %v to DHCP server", ipv4, ipv6)
plog.G(context.Background()).Debugf("Release IPv4 %v IPv6 %v", ipv4, ipv6)
}
}
return &v1.AdmissionResponse{Allowed: true}