From ddfd17aab0753d0552ed0d4907b9bc31c0485626 Mon Sep 17 00:00:00 2001 From: "xiayu.lyt" Date: Wed, 24 Apr 2024 20:43:21 +0800 Subject: [PATCH] fix backend ip version check for clb Signed-off-by: xiayu.lyt --- .../service/reconcile/backend/backend.go | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/controller/service/reconcile/backend/backend.go b/pkg/controller/service/reconcile/backend/backend.go index 3dd0fb631..1774c664f 100644 --- a/pkg/controller/service/reconcile/backend/backend.go +++ b/pkg/controller/service/reconcile/backend/backend.go @@ -87,17 +87,26 @@ func (e *EndpointWithENI) setTrafficPolicy(reqCtx *svcCtx.RequestContext) { } func (e *EndpointWithENI) setAddressIpVersion(reqCtx *svcCtx.RequestContext) { + e.AddressIPVersion = model.IPv4 + if reqCtx.Anno.Get(annotation.BackendIPVersion) != string(model.IPv6) { + return + } // Only EndpointSlice support dual stack. // Enable IPv6DualStack and EndpointSlice feature gates if you want to use ipv6 backends - if utilfeature.DefaultMutableFeatureGate.Enabled(ctrlCfg.IPv6DualStack) && - utilfeature.DefaultMutableFeatureGate.Enabled(ctrlCfg.EndpointSlice) && - strings.EqualFold(reqCtx.Anno.Get(annotation.IPVersion), string(model.DualStack)) && - reqCtx.Anno.Get(annotation.BackendIPVersion) == string(model.IPv6) { - e.AddressIPVersion = model.IPv6 - reqCtx.Log.Info("backend address ip version is ipv6") + if !utilfeature.DefaultMutableFeatureGate.Enabled(ctrlCfg.IPv6DualStack) || + !utilfeature.DefaultMutableFeatureGate.Enabled(ctrlCfg.EndpointSlice) { return } - e.AddressIPVersion = model.IPv4 + + c := model.IPv6 + if helper.NeedNLB(reqCtx.Service) { + c = model.DualStack + } + if strings.EqualFold(reqCtx.Anno.Get(annotation.IPVersion), string(c)) { + reqCtx.Log.Info("backend address ip version is ipv6") + e.AddressIPVersion = model.IPv6 + } + return } func GetNodes(reqCtx *svcCtx.RequestContext, kubeClient client.Client) ([]v1.Node, error) {