Is there a canary property to check in nginx-ingress snippet

352 Views Asked by At

I have these two ingresses for a blue (production) and green (canary) deployment and I want in my nginx snippet to set certain stuff based on whether the request is served from production service or from canary. What should be the if statement in the snippet?

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: blue-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      if (canary) { <--- WHAT CAN I CHECK HERE?
        ...
      } else {
        ...
      }
spec:
  ...
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: green-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-by-cookie: "green"
spec:
  ...
1

There are 1 best solutions below

5
AudioBubble On

I don't think there is a specific canary property you can check against.
You could, however, look for specific cookie, that your canary service could provide

if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
    ...
}

Note that, while nginx does have if directive, there is no else. The equivalent for else would be all that isn't modified with an if.