Skip to content

Commit 2a0d7fa

Browse files
committed
fix: scope BackendTrafficPolicy conflict detection by sectionName
The conflict key only included the target Service (namespace/name/kind), so two BackendTrafficPolicies targeting the same Service were always treated as conflicting even when scoped to different ports via sectionName. Include sectionName in the key so a port-scoped policy and a whole-Service policy (or two different-section policies) can both be accepted.
1 parent ddf0242 commit 2a0d7fa

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/controller/policies.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ import (
4747
type PolicyTargetKey struct {
4848
NsName types.NamespacedName
4949
GroupKind schema.GroupKind
50+
// SectionName scopes the target to a specific section (for a Service, the
51+
// port name). Policies that target different sections of the same resource
52+
// do not conflict; an empty SectionName targets the whole resource.
53+
SectionName string
5054
}
5155

5256
func (p PolicyTargetKey) String() string {
53-
return p.NsName.String() + "/" + p.GroupKind.String()
57+
return p.NsName.String() + "/" + p.GroupKind.String() + "/" + p.SectionName
5458
}
5559

5660
func BackendTrafficPolicyPredicateFunc(channel chan event.GenericEvent) predicate.Predicate {
@@ -143,6 +147,9 @@ func ProcessBackendTrafficPolicy(
143147
NsName: types.NamespacedName{Namespace: p.GetNamespace(), Name: string(targetRef.Name)},
144148
GroupKind: schema.GroupKind{Group: "", Kind: internaltypes.KindService},
145149
}
150+
if sectionName != nil {
151+
key.SectionName = string(*sectionName)
152+
}
146153
condition := NewPolicyCondition(policy.Generation, true, "Policy has been accepted")
147154
if sectionName != nil && !servicePortNameMap[fmt.Sprintf("%s/%s/%s", policy.Namespace, string(targetRef.Name), *sectionName)] {
148155
condition = NewPolicyCondition(policy.Generation, false, fmt.Sprintf("No section name %s found in Service %s/%s", *sectionName, policy.Namespace, targetRef.Name))

0 commit comments

Comments
 (0)