summaryrefslogtreecommitdiffstats
path: root/roles/ands_kaas/templates
diff options
context:
space:
mode:
Diffstat (limited to 'roles/ands_kaas/templates')
-rw-r--r--roles/ands_kaas/templates/00-block-volumes.yml.j248
-rw-r--r--roles/ands_kaas/templates/00-gfs-volumes.yml.j211
-rw-r--r--roles/ands_kaas/templates/50-kaas-pods.yml.j2166
3 files changed, 188 insertions, 37 deletions
diff --git a/roles/ands_kaas/templates/00-block-volumes.yml.j2 b/roles/ands_kaas/templates/00-block-volumes.yml.j2
new file mode 100644
index 0000000..9982d61
--- /dev/null
+++ b/roles/ands_kaas/templates/00-block-volumes.yml.j2
@@ -0,0 +1,48 @@
+apiVersion: v1
+kind: Template
+metadata:
+ name: {{ kaas_project }}-block-volumes
+ annotations:
+ descriptions: "{{ kaas_project }} glusterfs block volumes"
+objects:
+{% for name, vol in kaas_block_volumes.iteritems() %}
+{% set oc_name = vol.name | default(name) | regex_replace('_','-') %}
+{% if oc_name | regex_search("^" + kaas_project) %}
+{% set pvname = oc_name %}
+{% else %}
+{% set pvname = (kaas_project + "-" + oc_name) | regex_replace('_','-') %}
+{% endif %}
+ - apiVersion: v1
+ kind: PersistentVolume
+ metadata:
+ name: {{ pvname }}
+ spec:
+ persistentVolumeReclaimPolicy: Retain
+ accessModes:
+ - ReadWriteOnce
+ iscsi:
+ fsType: xfs
+ iqn: iqn.2016-12.org.gluster-block:{{ kaas_block_iqn[name] }}
+ iscsiInterface: default
+ lun: 0
+ targetPortal: {{ kaas_block_portals[name][0] }}
+{% if kaas_block_portals[name] | length > 1 %}
+ portals: {{ kaas_block_portals[name][1:] | to_json }}
+{% endif %}
+ capacity:
+ storage: {{ vol.capacity | default(kaas_default_volume_capacity) }}
+ claimRef:
+ name: {{ oc_name }}
+ namespace: {{ kaas_project }}
+ - apiVersion: v1
+ kind: PersistentVolumeClaim
+ metadata:
+ name: {{ oc_name }}
+ spec:
+ volumeName: {{ pvname }}
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: {{ vol.capacity | default(kaas_default_volume_capacity) }}
+{% endfor %}
diff --git a/roles/ands_kaas/templates/00-gfs-volumes.yml.j2 b/roles/ands_kaas/templates/00-gfs-volumes.yml.j2
index a69942d..54064e4 100644
--- a/roles/ands_kaas/templates/00-gfs-volumes.yml.j2
+++ b/roles/ands_kaas/templates/00-gfs-volumes.yml.j2
@@ -7,6 +7,10 @@ metadata:
descriptions: "{{ kaas_project }} glusterfs volumes"
objects:
{% for name, vol in kaas_project_volumes.iteritems() %}
+{% set voltypes = kaas_storage_domains | json_query("[*].volumes." + vol.volume + ".type") %}
+{% set voltype = voltypes[0] | default('host') %}
+{% set mntpaths = kaas_storage_domains | json_query("[*].volumes." + vol.volume + ".mount") %}
+{% set mntpath = mntpaths[0] | default('') %}
{% set oc_name = vol.name | default(name) | regex_replace('_','-') %}
{% set cfgpath = vol.path | default("") %}
{% set path = cfgpath if cfgpath[:1] == "/" else "/" + kaas_project + "/" + cfgpath %}
@@ -21,9 +25,14 @@ objects:
name: {{ pvname }}
spec:
persistentVolumeReclaimPolicy: Retain
+{% if voltype == 'host' %}
+ hostPath:
+ path: "{{ mntpath }}{{ path }}"
+{% else %}
glusterfs:
endpoints: {{ kaas_glusterfs_endpoints }}
- path: "{{ vol.volume }}{{path}}"
+ path: "{{ vol.volume }}{{ path }}"
+{% endif %}
readOnly: {{ not (vol.write | default(false)) }}
accessModes:
- {{ vol.access | default(vol.write | default(false) | ternary('ReadWriteMany', 'ReadOnlyMany')) }}
diff --git a/roles/ands_kaas/templates/50-kaas-pods.yml.j2 b/roles/ands_kaas/templates/50-kaas-pods.yml.j2
index ad1fc58..761004d 100644
--- a/roles/ands_kaas/templates/50-kaas-pods.yml.j2
+++ b/roles/ands_kaas/templates/50-kaas-pods.yml.j2
@@ -3,39 +3,65 @@
apiVersion: v1
kind: Template
metadata:
- name: {{ kaas_project }}-pods
+ name: {{ name | default(kaas_project) }}-pods
annotations:
- descriptions: {{ kaas_project_config.description | default(kaas_project ~ " auto-generated pod template") }}
+ descriptions: {{ kaas_project_config.description | default(name | default(kaas_project) ~ " auto-generated pod template") }}
objects:
-{% for name, pod in kaas_project_pods.iteritems() %}
- {% set pubkey = "kaas_" ~ name ~ "_pubkey" %}
- {% set privkey = "kaas_" ~ name ~ "_privkey" %}
- {% set cakey = "kaas_" ~ name ~ "_ca" %}
- {% if pod.variant is defined %}
- {% set pod = pod[pod.variant] %}
- {% endif %}
- {% set sched = pod.sched | default({}) %}
- {% set node_selector = (sched.selector is defined) | ternary(sched.selector, ands_default_node_selector | combine(sched.restrict | default({}))) %}
-
- {% if pod.service is defined %}
+{% for name, pod in pods.iteritems() %}
+ {% set kind = pod.kind | default('DeploymentConfig') %}
+ {% if pod.enabled | default(true) %}
+ {% set pubkey = "kaas_" ~ name ~ "_pubkey" %}
+ {% set privkey = "kaas_" ~ name ~ "_privkey" %}
+ {% set cakey = "kaas_" ~ name ~ "_ca" %}
+ {% if pod.variant is defined %}
+ {% set pod = pod[pod.variant] %}
+ {% endif %}
+ {% set sched = pod.sched | default({}) %}
+ {% set node_selector = (sched.selector is defined) | ternary(sched.selector, ands_default_node_selector | combine(sched.restrict | default({}))) %}
+ {% if pod.service is defined %}
+ {% if kind == 'StatefulSet' and pod.service.ports is defined %}
- apiVersion: v1
kind: Service
metadata:
- name: {{ pod.name | default(name) }}
+ name: {{ pod.name | default(name) }}-ss
+ annotations: {{ pod.service.annotations | default({}) | combine({"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true" }) | to_json }}
spec:
+ clusterIP: None
+ publishNotReadyAddresses: True
selector:
name: {{ pod.name | default(name) }}
- {% if pod.service.ports is defined %}
ports:
{% for port in pod.service.ports %}
- {% set portmap = (port | string).split('/') %}
+ {% set portmap = (port | string).split('/') %}
- name: "{{ portmap[0] }}"
port: {{ portmap[0] }}
targetPort: {{ (portmap[1] is defined) | ternary(portmap[1], portmap[0]) }}
{% endfor %}
- {% endif %}
- {% if (pod.service.ports is defined) and (pod.service.host is defined) %}
- {% set first_port = (pod.service.ports[0] | string).split('/') %}
+ {% endif %}
+ - apiVersion: v1
+ kind: Service
+ metadata:
+ name: {{ pod.name | default(name) }}
+ {% if pod.service.annotations is defined %}
+ annotations: {{ pod.service.annotations | to_json }}
+ {% endif %}
+ spec:
+ selector:
+ name: {{ pod.name | default(name) }}
+ {% if pod.service.ip is defined %}
+ clusterIP: {{ pod.service.ip }}
+ {% endif %}
+ {% if pod.service.ports is defined %}
+ ports:
+ {% for port in pod.service.ports %}
+ {% set portmap = (port | string).split('/') %}
+ - name: "{{ portmap[0] }}"
+ port: {{ portmap[0] }}
+ targetPort: {{ (portmap[1] is defined) | ternary(portmap[1], portmap[0]) }}
+ {% endfor %}
+ {% endif %}
+ {% if (pod.service.ports is defined) and (pod.service.host is defined) %}
+ {% set first_port = (pod.service.ports[0] | string).split('/') %}
- apiVersion: v1
kind: Route
metadata:
@@ -47,27 +73,27 @@ objects:
name: {{ pod.name | default(name) }}
port:
targetPort: {{ (first_port[1] is defined) | ternary(first_port[1], first_port[0]) }}
- {% if (first_port[0] == "80") %}
+ {% if (first_port[0] == "80") %}
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
- {% if hostvars[inventory_hostname][pubkey] is defined %}
+ {% if hostvars[inventory_hostname][pubkey] is defined %}
certificate: |-
{{ hostvars[inventory_hostname][pubkey] | indent(10) }}
- {% endif %}
- {% if hostvars[inventory_hostname][privkey] is defined %}
+ {% endif %}
+ {% if hostvars[inventory_hostname][privkey] is defined %}
key: |-
{{ hostvars[inventory_hostname][privkey] | indent(10) }}
- {% endif %}
- {% if hostvars[inventory_hostname][cakey] is defined %}
+ {% endif %}
+ {% if hostvars[inventory_hostname][cakey] is defined %}
caCertificate: |-
{{ hostvars[inventory_hostname][cakey] | indent(10) }}
+ {% endif %}
{% endif %}
{% endif %}
{% endif %}
- {% endif %}
- - apiVersion: v1
- kind: DeploymentConfig
+ - apiVersion: {{ kaas_openshift_api_versions[kind] | default('v1') }}
+ kind: {{ kind }}
metadata:
name: {{ pod.name | default(name) }}
spec:
@@ -75,13 +101,32 @@ objects:
revisionHistoryLimit: 2
strategy:
type: {{ (sched | default({})).strategy | default('Rolling') }}
+ updateStrategy:
+ {% if pod.update %}
+ type: {{ pod.update.strategy | default('OnDelete') }}
+ {% if pod.update.min_ready is defined %}
+ minReadySeconds: {{ pod.update.min_ready }}
+ {% endif %}
+ {% endif %}
triggers:
- type: ConfigChange
+ {% if kind == 'StatefulSet' %}
+ serviceName: {{ pod.name | default(name) }}-ss
+ selector:
+ matchLabels:
+ name: {{ pod.name | default(name) }}
+ {% else %}
selector:
name: {{ pod.name | default(name) }}
+ {% endif %}
template:
metadata:
name: {{ pod.name | default(name) }}
+ {% if kind == 'StatefulSet' %}
+ annotations: {{ pod.annotations | default({}) | combine({"pod.alpha.kubernetes.io/initialized": "true"}) | to_json }}
+ {% elif pod.annotations is defined %}
+ annotations: {{ pod.annotations | to_json }}
+ {% endif %}
labels:
name: {{ pod.name | default(name) }}
spec:
@@ -89,16 +134,22 @@ objects:
nodeSelector: {{ node_selector | to_json }}
{% endif %}
{% set mappings = (pod.images | json_query('[*].mappings') | length) %}
- {% if mappings > 0 %}
+ {% set paths = (pod.images | json_query('[*].hostpath') | length) %}
+ {% if mappings > 0 or paths > 0 %}
volumes:
{% for img in pod.images %}
{% set imgidx = loop.index %}
- {% for vol in img.mappings %}
+ {% for vol in (img.mappings | default([])) %}
{% set oc_name = vol.name | default(name) | regex_replace('_','-') %}
- name: vol-{{imgidx}}-{{loop.index}}
persistentVolumeClaim:
claimName: {{ oc_name }}
{% endfor %}
+ {% for vol in (img.hostpath | default([])) %}
+ - name: host-{{imgidx}}-{{loop.index}}
+ hostPath:
+ path: {{ vol.path }}
+ {% endfor %}
{% endfor %}
{% endif %}
{% if (pod.groups is defined) or (pod.run_as is defined) %}
@@ -121,21 +172,31 @@ objects:
{% set imgidx = loop.index %}
- name: {{ img.name | default(pod.name) | default(name) }}
image: {{ img.image }}
- imagePullPolicy: Always
- ports:
+ imagePullPolicy: {{ img.pull | default('Always') }}
+ {% if (img.command is defined) %}
+ command: {{ img.command | to_json }}
+ {% endif %}
{% if img.ports is defined %}
+ ports:
{% for port in img.ports %}
- containerPort: {{ port }}
{% endfor %}
- {% else %}
+ {% elif pod.service.ports is defined %}
+ ports:
{% for port in pod.service.ports %}
{% set portmap = (port | string).split('/') %}
- containerPort: {{ (portmap[1] is defined) | ternary(portmap[1], portmap[0]) }}
{% endfor %}
{% endif %}
+ {% if kind == 'StatefulSet' %}
+ {% set extra_env = [ { "name": "POD_NAMESPACE", "value": "fieldref@metadata.namespace" }, { "name": "POD_REPLICAS", "value": sched.replicas } ] %}
+ {% set env = img.env | default([]) | union(extra_env) %}
+ {% elif img.env is defined %}
+ {% set env = img.env %}
+ {% endif %}
{% if img.env is defined %}
env:
- {% for env_item in img.env %}
+ {% for env_item in env %}
{% set env_name = env_item.name %}
{% set env_val = env_item.value %}
{% set env_parts = (env_val | string).split('@') %}
@@ -152,18 +213,50 @@ objects:
configMapKeyRef:
name: {{ env_cm[0] }}
key: {{ env_cm[1] }}
+ {% elif env_parts[0] == "fieldref" %}
+ valueFrom:
+ fieldRef:
+ apiVersion: v1
+ fieldPath: {{ env_parts[1] }}
{% else %}
value: "{{ env_val }}"
{% endif %}
{% endfor %}
{% endif %}
- {% if img.mappings is defined %}
+ {% if img.mappings is defined or img.hostpath is defined %}
volumeMounts:
- {% for vol in img.mappings %}
+ {% for vol in (img.mappings | default([])) %}
- name: vol-{{imgidx}}-{{loop.index}}
subPath: {{ vol.path | default("") }}
mountPath: {{ vol.mount }}
{% endfor %}
+ {% for vol in (img.hostpath | default([])) %}
+ - name: host-{{imgidx}}-{{loop.index}}
+ mountPath: {{ vol.mount }}
+ {% endfor %}
+ {% endif %}
+ {% if img.resources is defined %}
+ resources:
+ {% if img.resources.request is defined %}
+ {% set res = img.resources.request %}
+ requests:
+ {% if res.cpu %}
+ cpu: {{ res.cpu }}
+ {% endif %}
+ {% if res.cpu %}
+ memory: {{ res.mem }}
+ {% endif %}
+ {% endif %}
+ {% if img.resources.limit is defined %}
+ {% set res = img.resources.limit %}
+ limits:
+ {% if res.cpu %}
+ cpu: {{ res.cpu }}
+ {% endif %}
+ {% if res.cpu %}
+ memory: {{ res.mem }}
+ {% endif %}
+ {% endif %}
{% endif %}
{% if img.probes is defined %}
{% for probe in img.probes %}
@@ -201,4 +294,5 @@ objects:
{% endfor %}
{% endif %}
{% endfor %}
+ {% endif %}
{% endfor %}