Skip to content

Commit 7e1d1eb

Browse files
Prioritize reroute-virtual-interfaces over kubevirtInterfaces (#57690)
If a pod has both the istio.io/reroute-virtual-interfaces annotation and the older, deprecated traffic.sidecar.istio.io/kubevirtInterfaces annotation, the newer one should take precedence. But the CNI plugin and the injection template code were each handling them separately, which caused unexpected behavior. This fix makes sure the newer annotation always takes priority, while still supporting pods that only use the deprecated annotation. Fixes: istio/istio#57662 Signed-off-by: Sridhar Gaddam <sgaddam@redhat.com> Co-authored-by: Sridhar Gaddam <sgaddam@redhat.com>
1 parent 513b527 commit 7e1d1eb

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

cni/pkg/plugin/sidecar_redirect.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,20 @@ func NewRedirect(pi *PodInfo) (*Redirect, error) {
275275
return nil, fmt.Errorf("annotation value error for value %s; annotationFound = %t: %v",
276276
"excludeInterfaces", isFound, valErr)
277277
}
278-
// kubeVirtInterfaces is deprecated, so check it first, but prefer`reroute-virtual-interfaces`
279-
// if both are defined.
280-
isFound, redir.rerouteVirtualInterfaces, valErr = getAnnotationOrDefault("kubevirtInterfaces", pi.Annotations)
281-
if valErr != nil {
282-
return nil, fmt.Errorf("annotation value error for value %s; annotationFound = %t: %v",
283-
"kubevirtInterfaces", isFound, valErr)
284-
}
278+
// kubeVirtInterfaces is deprecated, so prefer`reroute-virtual-interfaces` if both are defined.
285279
isFound, redir.rerouteVirtualInterfaces, valErr = getAnnotationOrDefault("reroute-virtual-interfaces", pi.Annotations)
286280
if valErr != nil {
287281
return nil, fmt.Errorf("annotation value error for value %s; annotationFound = %t: %v",
288282
"reroute-virtual-interfaces", isFound, valErr)
289283
}
284+
// Only check deprecated kubevirtInterfaces if reroute-virtual-interfaces was not found
285+
if !isFound {
286+
isFound, redir.rerouteVirtualInterfaces, valErr = getAnnotationOrDefault("kubevirtInterfaces", pi.Annotations)
287+
if valErr != nil {
288+
return nil, fmt.Errorf("annotation value error for value %s; annotationFound = %t: %v",
289+
"kubevirtInterfaces", isFound, valErr)
290+
}
291+
}
290292
if v, found := pi.ProxyEnvironments["ISTIO_META_DNS_CAPTURE"]; found {
291293
// parse and set the bool value of dnsRedirect
292294
redir.dnsRedirect, valErr = strconv.ParseBool(v)

manifests/charts/istio-control/istio-discovery/files/injection-template.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,12 @@ spec:
119119
- "-o"
120120
- "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/excludeOutboundPorts` .Values.global.proxy.excludeOutboundPorts }}"
121121
{{ end -}}
122-
{{ if (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces`) -}}
123-
- "-k"
124-
- "{{ index .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces` }}"
125-
{{ end -}}
126122
{{ if (isset .ObjectMeta.Annotations `istio.io/reroute-virtual-interfaces`) -}}
127123
- "-k"
128124
- "{{ index .ObjectMeta.Annotations `istio.io/reroute-virtual-interfaces` }}"
125+
{{ else if (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces`) -}}
126+
- "-k"
127+
- "{{ index .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces` }}"
129128
{{ end -}}
130129
{{ if (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeInterfaces`) -}}
131130
- "-c"

pkg/kube/inject/testdata/inject/reroute-virtual-interfaces.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ spec:
1313
metadata:
1414
annotations:
1515
istio.io/reroute-virtual-interfaces: "net0ps2"
16+
traffic.sidecar.istio.io/kubevirtInterfaces: "net1"
1617
labels:
1718
app: hello
1819
tier: backend

pkg/kube/inject/testdata/inject/reroute-virtual-interfaces.yaml.injected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
prometheus.io/port: "15020"
2323
prometheus.io/scrape: "true"
2424
sidecar.istio.io/status: '{"initContainers":["istio-init","istio-proxy"],"containers":null,"volumes":["workload-socket","credential-socket","workload-certs","istio-envoy","istio-data","istio-podinfo","istio-token","istiod-ca-cert","istio-ca-crl"],"imagePullSecrets":null,"revision":"default"}'
25+
traffic.sidecar.istio.io/kubevirtInterfaces: net1
2526
creationTimestamp: null
2627
labels:
2728
app: hello

releasenotes/notes/57662.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: release-notes/v2
2+
kind: bug-fix
3+
area: traffic-management
4+
issue:
5+
- 57662
6+
releaseNotes:
7+
- |
8+
**Fixed** an annotation issue where both istio.io/reroute-virtual-interfaces and the deprecated traffic.sidecar.istio.io/kubevirtInterfaces were processed. The newer reroute-virtual-interfaces annotation now correctly takes precedence.

0 commit comments

Comments
 (0)