Add configmap deployment using support between formulas

Change-Id: Idf9ae2bd439ba315464e18188038d05b1e589f60
diff --git a/README.rst b/README.rst
index 7005d62..118efd8 100644
--- a/README.rst
+++ b/README.rst
@@ -430,6 +430,48 @@
                 mount: /certs
                 path: /etc/certs
 
+Configmap
+---------
+
+You are able to create configmaps using support layer between formulas.
+It works simple, eg. in nova formula there's file ``meta/config.yml`` which
+defines config files used by that service and roles.
+
+Kubernetes formula is able to generate these files using custom pillar and
+grains structure. This way you are able to run docker images built by any way
+while still re-using your configuration management.
+
+Example pillar:
+
+.. code-block:: bash
+
+    kubernetes:
+      control:
+        configmap:
+          nova-control:
+            grains:
+              # Alternate grains as OS running in container may differ from
+              # salt minion OS. Needed only if grains matters for config
+              # generation.
+              os_family: Debian
+            pillar:
+              # Generic pillar for nova controller
+              nova:
+                controller:
+                  enabled: true
+                  versionn: liberty
+                  ...
+
+To tell which services supports config generation, you need to ensure pillar
+structure like this to determine support:
+
+.. code-block:: yaml
+
+    nova:
+      _support:
+        config:
+          enabled: true
+
 Volumes
 -------
 
diff --git a/kubernetes/control/cluster.sls b/kubernetes/control/cluster.sls
index 8e3dd2d..98a8188 100644
--- a/kubernetes/control/cluster.sls
+++ b/kubernetes/control/cluster.sls
@@ -58,7 +58,6 @@
       service: {{ service|yaml }}
 
 {%- endif %}
-
 /srv/kubernetes/{{ service.cluster }}/{{ node_name }}-{{ service.kind }}.yml:
   file.managed:
   - source: salt://kubernetes/files/rc.yml
@@ -75,4 +74,40 @@
 
 {%- endfor %}
 
-{%- endif %}
\ No newline at end of file
+{%- for configmap_name, configmap in control.get('configmap', {}).iteritems() %}
+{%- if configmap.enabled|default(True) %}
+
+{%- if configmap.pillar is defined %}
+  {%- for service_name in configmap.pillar.keys() %}
+    {%- if pillar.get(service_name, {}).get('_support', {}).get('config', {}).get('enabled', False) %}
+
+      {%- set support_fragment_file = service_name+'/meta/config.yml' %}
+      {% macro load_support_file(pillar, grains) %}{% include support_fragment_file %}{% endmacro %}
+
+      {%- set service_config_files = load_support_file(configmap.pillar, configmap.get('grains', {}))|load_yaml %}
+      {%- for service_config_name, service_config in service_config_files.config.iteritems() %}
+
+/srv/kubernetes/configmap/{{ configmap_name }}/{{ service_config_name }}:
+  file.managed:
+  - source: {{ service_config.source }}
+  - user: root
+  - group: root
+  - template: {{ service_config.template }}
+  - makedirs: true
+  - require:
+    - file: /srv/kubernetes
+  - defaults:
+      pillar: {{ configmap.pillar|yaml }}
+      grains: {{ configmap.get('grains', {}) }}
+
+      {%- endfor %}
+    {%- endif %}
+  {%- endfor %}
+{%- else %}
+{# TODO: configmap not using support between formulas #}
+{%- endif %}
+
+{%- endif %}
+{%- endfor %}
+
+{%- endif %}
diff --git a/kubernetes/pool/kubelet.sls b/kubernetes/pool/kubelet.sls
index 7a976c8..71eb4dc 100644
--- a/kubernetes/pool/kubelet.sls
+++ b/kubernetes/pool/kubelet.sls
@@ -50,7 +50,7 @@
 
 /usr/bin/hyperkube:
   file.managed:
-     - source: {{ pool.hyperkube.get('source', 'http://apt.tcpcloud.eu/kubernetes/bin/') }}{{ pool.version }}/hyperkube
+     - source: {{ pool.hyperkube.get('source', {}).get('url', 'http://apt.tcpcloud.eu/kubernetes/bin/') }}{{ pool.version }}/hyperkube
      - source_hash: md5={{ pool.hyperkube.hash }}
      - mode: 751
      - makedirs: true
@@ -72,4 +72,4 @@
   - watch:
     - file: /etc/default/kubelet
 
-{%- endif %}
\ No newline at end of file
+{%- endif %}