Patching Istio's RouteRules doesn't take effect using kubectl

5/25/2018

I'm trying to patch an Istio's RouteRule on the fly by changing the proportion of traffic each version of the service receives. Right now when I run

kubectl describe routerule my-rule

I get the description:

Name:         my-rule
Namespace:    default
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"config.istio.io/v1alpha2","kind":"RouteRule","metadata":{"annotations":{},"name":"my-rule","namespace":"default"},"spec":...
API Version:  config.istio.io/v1alpha2
Kind:         RouteRule
Metadata:
  Cluster Name:        
  Creation Timestamp:  2018-05-25T16:21:59Z
  Generation:          0
  Resource Version:    154906
  Self Link:           /apis/config.istio.io/v1alpha2/namespaces/default/routerules/my-rule
  UID:                 bfd78178-6037-11e8-8d5c-06f2e5b7e6b2
Spec:
  Destination:
    Name:  MyApp
  Match:
    Request:
      Headers:
        Uri:
          Prefix:  /MyApp/
  Rewrite:
    Uri:  /
  Route:
    Labels:
      Version:  v1
    Weight:     10
    Labels:
      Version:  v2
    Weight:     90

Now I want to change the rule such that 90% of traffic is sent to v1 and 10% to v2:

kubectl patch routerule my-rule --type='json' -p='[{"op":"replace", "path":"/spec/route", "value":[{"labels":{"version":"v1"}, "weight": "90"}, {"labels":{"version":"v2"}, "weight": "10"}]}]'

When I run this, the command succeeds with routerule.config.istio.io "my-rule" patched; and if I run kubectl describe on my rule again I can verify it has the updated values:

...
Route:
Labels:
  Version:  v1
Weight:     90
Labels:
  Version:  v2
Weight:     10

However, this doesn't actually take effect. When I hit the endpoint, I still see the original rules are applied (most of the traffic is sent to v2). Any ideas as to what could be causing this? Do I need to somehow inform Istio that the rule has changed?

-- PoweredByOrange
istio
kubectl
kubernetes

1 Answer

5/30/2018

Stupid mistake - figured out what I was doing wrong:

"weight": "90" should have been "weight": 90 (integer value instead of string). What's odd however is Istio happily took the string value from the patch and applied it, even though it should have reported an error. I'll wait to see if they fix it in their stable release of the pilot, otherwise will raise a PR.

-- PoweredByOrange
Source: StackOverflow