<p>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 <code>if</code> statement in the snippet?</p>
<pre><code>---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: blue-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/configuration-snippet: |
      if (canary) { &lt;--- WHAT CAN I CHECK HERE?
        ...
      } else {
        ...
      }
spec:
  ...
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: green-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/canary: &quot;true&quot;
    nginx.ingress.kubernetes.io/canary-by-cookie: &quot;green&quot;
spec:
  ...
</code></pre>

<p>I don't think there is a specific <em>canary property</em> you can check against.<br />
You could, however, look for specific <em>cookie</em>, that your canary service could provide</p>
<pre><code>if ($http_cookie ~* &quot;id=([^;]+)(?:;|$)&quot;) {
    ...
}
</code></pre>
<p>Note that, while nginx does have <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if" rel="nofollow noreferrer"><code>if</code> directive</a>, there is no <code>else</code>. <em>The equivalent for else would be all that isn't modified with an <code>if</code></em>.</p>
