fiaas / mast

Apache License 2.0
2 stars 7 forks source link

Support empty config maps #7

Closed xavileon closed 5 years ago

xavileon commented 5 years ago

Users may add empty ConfigMap files, which may lead to errors when iterating over the keys. This patch returns an empty map in case the ConfigMap is None.

This patch fixes the error seen in the fiaas-mast pod:

Starting new HTTPS connection (1): artifacts.schibsted.io https://artifacts.schibsted.io:443 "GET /artifactory/k8s-manifest/Yapo/pulse-service/config-dev.0.278.6129743.yml HTTP/1.1" 200 0
An error occured: AttributeError("'NoneType' object has no attribute 'items'",)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "<decorator-gen-5>", line 2, in generate_configmap_application
  File "/usr/local/lib/python3.6/site-packages/prometheus_client/core.py", line 991, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/fiaas_mast/web.py", line 132, in generate_configmap_application
    data.get("metadata_annotations", {}))
  File "/usr/local/lib/python3.6/site-packages/fiaas_mast/configmap_generator.py", line 15, in generate_configmap
    "data": {k: str(v) for k, v in data.items()},
AttributeError: 'NoneType' object has no attribute 'items'
xavileon commented 5 years ago

@oyvindio @birgirst Could you take a look? it's a side effect of the previous patch. Thanks! PS: the Codacy issue is the same as other methods, won't fix to keep consistency. cc/ @gardleopard