1

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:
  ...
Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27

1 Answers1

1

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.