Repository: emissary-ingress/emissary

Issue:
issue updating to 0.20.0
I tried updating argonath to 0.20.0 and hit the following:

[rhs@venture argonath]$ kubectl logs -n argonath ambassador-stable-3487196781-0k920 ambassador
2017-12-21 02:49:17 AMBASSADOR: starting initial sync
/usr/local/lib/python3.4/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Merging config inputs from /etc/ambassador-config
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key hello-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Scheduling restart
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key oauth-auth0-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key api-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key api-master.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key api-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key api-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key ghas-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key goals-master.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key hellospring-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key hellospring-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key issues-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key issues-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key issues-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key java-api-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key java-api-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key message-canary.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key message-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key message-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key message-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key meter-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key meter-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key meter-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key ui-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key ui-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key ui-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key hello-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key hellospring-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key api-dev-multiclaim.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key kubernaut-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: update: including key scout-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Changes detected, regenerating envoy config.
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote issues-stable.yaml to /etc/ambassador-config-1/issues-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote kubernaut-stable.yaml to /etc/ambassador-config-1/kubernaut-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote meter-dev-foo.yaml to /etc/ambassador-config-1/meter-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote issues-rhs-tabs.yaml to /etc/ambassador-config-1/issues-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote ghas-stable.yaml to /etc/ambassador-config-1/ghas-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote message-dev-foo.yaml to /etc/ambassador-config-1/message-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote message-canary.yaml to /etc/ambassador-config-1/message-canary.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote oauth-auth0-stable.yaml to /etc/ambassador-config-1/oauth-auth0-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote ui-rhs-tabs.yaml to /etc/ambassador-config-1/ui-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote api-master.yaml to /etc/ambassador-config-1/api-master.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote api-stable.yaml to /etc/ambassador-config-1/api-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote issues-dev-foo.yaml to /etc/ambassador-config-1/issues-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote message-stable.yaml to /etc/ambassador-config-1/message-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote hellospring-rhs-tabs.yaml to /etc/ambassador-config-1/hellospring-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote api-rhs-tabs.yaml to /etc/ambassador-config-1/api-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote message-rhs-tabs.yaml to /etc/ambassador-config-1/message-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote api-dev-multiclaim.yaml to /etc/ambassador-config-1/api-dev-multiclaim.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote api-dev-foo.yaml to /etc/ambassador-config-1/api-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote ui-stable.yaml to /etc/ambassador-config-1/ui-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote meter-rhs-tabs.yaml to /etc/ambassador-config-1/meter-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote meter-stable.yaml to /etc/ambassador-config-1/meter-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote ui-dev-foo.yaml to /etc/ambassador-config-1/ui-dev-foo.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote goals-master.yaml to /etc/ambassador-config-1/goals-master.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote hellospring-stable.yaml to /etc/ambassador-config-1/hellospring-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote scout-stable.yaml to /etc/ambassador-config-1/scout-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote java-api-stable.yaml to /etc/ambassador-config-1/java-api-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote hello-stable.yaml to /etc/ambassador-config-1/hello-stable.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: Wrote java-api-rhs-tabs.yaml to /etc/ambassador-config-1/java-api-rhs-tabs.yaml
2017-12-21 02:49:17 kubewatch 0.20.0 INFO: generating config with gencount 1
Traceback (most recent call last):
  File "/application/kubewatch.py", line 466, in <module>
    main()
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/application/kubewatch.py", line 449, in main
    sync(restarter)
  File "/application/kubewatch.py", line 353, in sync
    restarter.restart()
  File "/application/kubewatch.py", line 117, in restart
    config = self.generate_config(output)
  File "/application/kubewatch.py", line 139, in generate_config
    aconf = Config(output)
  File "/usr/local/lib/python3.4/dist-packages/ambassador-0.20.0-py3.4.egg/ambassador/config.py", line 292, in __init__
  File "/usr/local/lib/python3.4/dist-packages/ambassador-0.20.0-py3.4.egg/ambassador/config.py", line 366, in process_yaml
  File "/usr/local/lib/python3.4/dist-packages/ambassador-0.20.0-py3.4.egg/ambassador/config.py", line 418, in process_object
TypeError: 'NoneType' object is not subscriptable
2017-12-21 02:49:18 AMBASSADOR: kubewatch sync exited with status 1
2017-12-21 02:49:18 AMBASSADOR: Here's the envoy.json we were trying to run with:
ls: cannot access /etc/envoy*.json: No such file or directory
2017-12-21 02:49:18 AMBASSADOR: No config generated.
2017-12-21 02:49:18 AMBASSADOR: shutting down
[rhs@venture argonath]$ 



Discussion:

Resolving patch:
diff --git a/ambassador/ambassador/config.py b/ambassador/ambassador/config.py
--- a/ambassador/ambassador/config.py
+++ b/ambassador/ambassador/config.py
@@ -414,6 +414,10 @@ def process_object(self, obj):
         # Cache the source key first thing...
         source_key = self.current_source_key()
 
+        # This should be impossible.
+        if not obj:
+            return RichStatus.fromError("undefined object???")
+
         try:
             obj_version = obj['apiVersion']
             obj_kind = obj['kind']
diff --git a/ambassador/kubewatch.py b/ambassador/kubewatch.py
--- a/ambassador/kubewatch.py
+++ b/ambassador/kubewatch.py
@@ -43,7 +43,7 @@ def get_source(svc):
     return "service %s, namespace %s" % (svc.metadata.name, svc.metadata.namespace)
 
 def get_filename(svc):
-    return "%s.yaml" % svc.metadata.name
+    return "%s-%s.yaml" % (svc.metadata.name, svc.metadata.namespace)
 
 class Restarter(threading.Thread):
 
@@ -184,7 +184,7 @@ def read_yaml(self, raw_yaml, source):
             'autogenerated: true'
         ])
 
-        sep = "---\n" if not raw_yaml.startswith("---") else ""
+        sep = "---\n" if not raw_yaml.lstrip().startswith("---") else ""
 
         return metadata + "\n" + sep + raw_yaml
 


Test patch: