Repository: emissary-ingress/emissary

Issue:
imagePullPolicy is set to Always
We should have a more sensible setup for our default YAML


Discussion:

Resolving patch:
diff --git a/ambassador/ambassador/mapping.py b/ambassador/ambassador/mapping.py
--- a/ambassador/ambassador/mapping.py
+++ b/ambassador/ambassador/mapping.py
@@ -31,14 +31,14 @@ def route_weight(klass, route):
         return tuple(weight)
 
     TransparentRouteKeys = {
-        "host_redirect": True,
-        "path_redirect": True,
-        "host_rewrite": True,
         "auto_host_rewrite": True,
         "case_sensitive": True,
-        "use_websocket": True,
-        "timeout_ms": True,
+        "host_redirect": True,
+        "host_rewrite": True,
+        "path_redirect": True,
         "priority": True,
+        "timeout_ms": True,
+        "use_websocket": True,
     }
 
     def __init__(self, _source="--internal--", _from=None, **kwargs):
@@ -108,6 +108,12 @@ def new_route(self, cluster_name):
         if self.headers:
             route['headers'] = self.headers
 
+        add_request_headers = self.get('add_request_headers')
+        if add_request_headers:
+            route['request_headers_to_add'] = []
+            for key, value in add_request_headers.items():
+              route['request_headers_to_add'].append({"key": key, "value": value})
+
         # Even though we don't use it for generating the Envoy config, go ahead
         # and make sure that any ':method' header match gets saved under the
         # route's '_method' key -- diag uses it to make life easier.
diff --git a/end-to-end/demotest.py b/end-to-end/demotest.py
--- a/end-to-end/demotest.py
+++ b/end-to-end/demotest.py
@@ -8,6 +8,8 @@
 import time
 import yaml
 
+DEFAULT_ITERATIONS=500
+
 # Yes, it's a terrible idea to use skip cert verification for TLS.
 # We really don't care for this test though.
 import urllib3
@@ -40,17 +42,22 @@ def call(url, headers=None, iterations=1):
     
     return got
 
+def to_percentage(count, iterations):
+    bias = iterations // 2
+    return ((count * 100) + bias) // iterations
+
 def test_demo(base, v2_wanted):
     url = "%s/demo/" % base
 
     attempts = 3
+    iterations = DEFAULT_ITERATIONS
 
     while attempts > 0:
         print("2.0.0: attempts left %d" % attempts)
-        got = call(url, iterations=1000)
+        got = call(url, iterations=iterations)
 
         print(got)
-        v2_seen = ((got.get('2.0.0', 0) + 5) // 10)
+        v2_seen = to_percentage(got.get('2.0.0', 0), iterations)
         delta = abs(v2_seen - v2_wanted)
         rc = (delta <= 2)
 
@@ -81,7 +88,7 @@ def test_from_yaml(base, yaml_path):
         headers = test.get('headers', None)
         host = test.get('host', None)
         versions = test.get('versions', None)
-        iterations = test.get('iterations', 100)
+        iterations = test.get('iterations', DEFAULT_ITERATIONS)
 
         if not versions:
             print("missing versions in %s?" % name)
@@ -107,7 +114,8 @@ def test_from_yaml(base, yaml_path):
             test_ok = True
 
             for version, wanted_count in versions.items():
-                got_count = got.get(version, 0)
+                # Convert iterations to percent.
+                got_count = to_percentage(got.get(version, 0), iterations)
                 delta = abs(got_count - wanted_count)
 
                 print("%s %s: wanted %d, got %d (delta %d)" % 


Test patch:
diff --git a/ambassador/tests/006-headers-and-host/config/mapping-qotm.yaml b/ambassador/tests/006-headers-and-host/config/mapping-qotm.yaml
--- a/ambassador/tests/006-headers-and-host/config/mapping-qotm.yaml
+++ b/ambassador/tests/006-headers-and-host/config/mapping-qotm.yaml
@@ -27,3 +27,7 @@ headers:
   x-demo-mode: host
 host: httpbin.org
 host_rewrite: httpbin.org
+add_request_headers:
+  x-test-proto: "%PROTOCOL%"
+  x-test-ip: "%CLIENT_IP%"
+  x-test-static: testing
diff --git a/ambassador/tests/006-headers-and-host/gold.intermediate.json b/ambassador/tests/006-headers-and-host/gold.intermediate.json
--- a/ambassador/tests/006-headers-and-host/gold.intermediate.json
+++ b/ambassador/tests/006-headers-and-host/gold.intermediate.json
@@ -182,7 +182,21 @@
                 ],
                 "host_rewrite": "httpbin.org",
                 "prefix": "/qotm/",
-                "prefix_rewrite": "/"
+                "prefix_rewrite": "/",
+                "request_headers_to_add": [
+                    {
+                        "key": "x-test-proto",
+                        "value": "%PROTOCOL%"
+                    },
+                    {
+                        "key": "x-test-ip",
+                        "value": "%CLIENT_IP%"
+                    },
+                    {
+                        "key": "x-test-static",
+                        "value": "testing"
+                    }
+                ]
             },
             {
                 "_group_id": "dc5d22df356f9df8439ed418ef194c061e57c68f",
@@ -298,7 +312,7 @@
             "kind": "Mapping",
             "name": "qotm_host_mapping",
             "version": "ambassador/v0",
-            "yaml": "apiVersion: ambassador/v0\nheaders:\n  x-demo-mode: host\nhost: httpbin.org\nhost_rewrite: httpbin.org\nkind: Mapping\nname: qotm_host_mapping\nprefix: /qotm/\nrewrite: /\nservice: httpbin.org:80\n"
+            "yaml": "add_request_headers:\n  x-test-ip: '%CLIENT_IP%'\n  x-test-proto: '%PROTOCOL%'\n  x-test-static: testing\napiVersion: ambassador/v0\nheaders:\n  x-demo-mode: host\nhost: httpbin.org\nhost_rewrite: httpbin.org\nkind: Mapping\nname: qotm_host_mapping\nprefix: /qotm/\nrewrite: /\nservice: httpbin.org:80\n"
         }
     }
-}
\ No newline at end of file
+}
diff --git a/ambassador/tests/006-headers-and-host/gold.json b/ambassador/tests/006-headers-and-host/gold.json
--- a/ambassador/tests/006-headers-and-host/gold.json
+++ b/ambassador/tests/006-headers-and-host/gold.json
@@ -89,6 +89,7 @@
                     
                     {
                       "timeout_ms": 10000,"prefix": "/qotm/","prefix_rewrite": "/","host_rewrite": "httpbin.org","headers": [{"name": "x-demo-mode", "regex": false, "value": "host"}, {"name": ":authority", "regex": false, "value": "httpbin.org"}],
+                      "request_headers_to_add": [{"key": "x-test-proto", "value": "%PROTOCOL%"}, {"key": "x-test-ip", "value": "%CLIENT_IP%"}, {"key": "x-test-static", "value": "testing"}],
                       "weighted_clusters": {
                           "clusters": [
                               
@@ -212,4 +213,4 @@
   },
   "statsd_udp_ip_address": "127.0.0.1:8125",
   "stats_flush_interval_ms": 1000
-}
\ No newline at end of file
+}