Add kubernets.client state
Add kubernetes.client state that allows to manage kubectl resources.
This patch adds support to manage node lables.
kubernetes:
client:
enabled: true
apiserver:
insecure_address: 0.0.0.0
insecure_port: 8080
resources:
enabled: true
label:
test:
value: enabled
node:
- cmp1
- cmp2
enabled: true
key: mylabel
Change-Id: Id9b3b21467ccc390977d47aba5034ac26e24502b
Related-Prod: PROD-27977
diff --git a/README.rst b/README.rst
index 263d1a3..3cf026d 100644
--- a/README.rst
+++ b/README.rst
@@ -1185,6 +1185,29 @@
test:
kind: User
+Manage client (kubectl resources)
+Assign labels to nodes:
+
+.. code-block:: yaml
+
+ kubernetes:
+ client:
+ enabled: true
+ apiserver:
+ insecure_address: 0.0.0.0
+ insecure_port: 8080
+ resources:
+ enabled: true
+ label:
+ test:
+ value: enabled
+ status: 'present'
+ node:
+ - cmp1
+ - cmp2
+ enabled: true
+ key: mylabel
+
More Information
================
diff --git a/kubernetes/client.sls b/kubernetes/client.sls
new file mode 100644
index 0000000..9c1c383
--- /dev/null
+++ b/kubernetes/client.sls
@@ -0,0 +1,33 @@
+{%- from "kubernetes/map.jinja" import client with context -%}
+{%- if client.enabled %}
+ {%- if client.get('resources', {}).get('enabled') %}
+
+ {%- for name,label in client.resources.get('label', {}).iteritems() %}
+
+ {%- if label.enabled %}
+ {%- if label.get('status', 'present') == 'present' %}
+ {%- for node in label.node %}
+# TODO(vsaienko) switch to kubernetes. salt module once kubernets-client python is packages and
+# awailable for installation.
+{{ name }}_{{ node }}:
+ k8s.label_present:
+ - name: {{ label.key }}
+ - value: {{ label.value }}
+ - node: {{ node }}
+ # TODO(vsaienko): move to profiles
+ - apiserver: http://{{ client.apiserver.insecure_address }}:{{ client.apiserver.insecure_port }}
+ {%- endfor %}
+
+ {%- elif label.get('status', 'present') == 'absent' %}
+ {%- for node in label.node %}
+{{ name }}_{{ node }}:
+ k8s.label_absent:
+ - name: {{ label.key }}
+ - node: {{ node }}
+ - apiserver: http://{{ client.apiserver.insecure_address }}:{{ client.apiserver.insecure_port }}
+ {%- endfor %} # endfor label.node.iteritems
+ {%- endif %} # endif label.present
+ {%- endif %} # endif label.enabled
+ {%- endfor %} # endfor client.resources.label
+ {%- endif %} # endif client.resources.enabled
+{%- endif %} # endif client.enabled
diff --git a/kubernetes/init.sls b/kubernetes/init.sls
index 22aad26..a882a97 100644
--- a/kubernetes/init.sls
+++ b/kubernetes/init.sls
@@ -10,4 +10,7 @@
{%- if pillar.kubernetes.control is defined %}
- kubernetes.control
{%- endif %}
+{%- if pillar.kubernetes.client is defined %}
+- kubernetes.client
+{%- endif %}
{%- endif %}
diff --git a/kubernetes/map.jinja b/kubernetes/map.jinja
index 615404c..3c3d4cb 100644
--- a/kubernetes/map.jinja
+++ b/kubernetes/map.jinja
@@ -111,6 +111,9 @@
},
}, merge=salt['pillar.get']('kubernetes:control')) %}
+{% set client = salt['grains.filter_by']({
+}, merge=salt['pillar.get']('kubernetes:client')) %}
+
{%- set monitoring = salt['grains.filter_by']({
'default': {
'instance_minor_threshold_percent': 0.3,