blob: 0e80393b4f81ba5a1d477072a4030d987c398578 [file] [log] [blame]
{% from "kubernetes/map.jinja" import control with context %}
apiVersion: {{ service.apiVersion }}
kind: {{ service.kind }}
metadata:
name: {{ service.service }}-{{ service.role }}
namespace: {{ service.namespace }}
labels:
app: {{ service.service }}-{{ service.role }}
spec:
replicas: {{ service.replicas }}
{%- if service.kind == 'PetSet' %}
serviceName: {{ service.service_name }}
{%- endif %}
template:
metadata:
labels:
app: {{ service.service }}-{{ service.role }}
annotations:
{%- if service.hostname is defined %}
pod.beta.kubernetes.io/hostname: {{ service.hostname }}
{%- endif %}
{%- if service.init_containers is defined %}
pod.alpha.kubernetes.io/init-containers: '[
{%- for container in service.init_containers %}
{
"name": "{{ container.name }}",
"image": "{% if container.registry is defined %}{{ container.registry }}/{%- endif %}{{ container.image }}{%- if container.tag is defined %}:{{ container.tag }}{%- endif %}",
"command": [{%- for command in container.command %}"{{ command }}"{% if not loop.last %},{% endif %}{%- endfor %}]
{%- if container.volumes is defined -%}
,
{%- for volume in container.volumes %}
"volumeMounts": [
{
"name": "{{ volume.name }}",
{%- if volume.sub_path is defined %}
"subPath": "{{ volume.sub_path }}",
{%- endif %}
"mountPath": "{{ volume.mount }}"
}
]
{%- if not loop.last %},{% endif %}{%- endfor %}
{%- endif %}
}
{%- if not loop.last %},{% endif %}{% endfor %}
]'
{%- endif %}
{%- if service.affinity is defined %}
scheduler.alpha.kubernetes.io/affinity: >
{
{%- for affinity_name, affinity in service.affinity.iteritems() %}
"{{ affinity.name }}": {
{%- for expression_name, expression in affinity.expression.iteritems() %}
{%- if expression.name == 'matchExpressions' %}
"{{ affinity.get('type','required') }}DuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{%- for selector in expression.selectors %}
{
"key": "{{ selector.key }}",
"operator": "{{ selector.operator }}",
"values": [{%- for value in selector['values'] %}"{{ value }}"{%- if not loop.last %},{% endif %}{%- endfor %}]
}{%- if not loop.last %},{% endif %}
{% endfor %}
]
}
]
}
{%- elif expression.name == 'labelSelector' %}
"{{ affinity.get('type','required') }}DuringSchedulingIgnoredDuringExecution": [
{
"labelSelector": {
"matchLabels": {
{%- for selector in expression.selectors %}
"{{ selector.key }}": "{{ selector.value }}"
{%- if not loop.last %},{% endif %}{%- endfor %}
}
},
{%- if affinity.name == 'podAntiAffinity' or affinity.name == 'podAffinity' %}
"topologyKey": "{{ affinity.topology_key }}"
{%- endif %}
}
]
{%- endif %}
{%- endfor %}
{%- if not loop.last %}},{% endif %}
{%- endfor %}
}
}
{%- endif %}
spec:
{%- if service.hostNetwork is defined %}
hostNetwork: True
{%- endif %}
{%- if service.host_pid is defined %}
hostPID: True
{%- endif %}
containers:
{%- for container_name, container in service.container.iteritems() %}
- name: {{ container_name }}
image: {% if container.registry is defined %}{{ container.registry }}/{%- endif %}{{ container.image }}{%- if container.tag is defined %}:{{ container.tag }}{%- endif %}
imagePullPolicy: {{ container.get('image_pull_policy','IfNotPresent') }}
{%- if container.privileged is defined %}
securityContext:
privileged: True
{%- endif %}
{%- if container.variables is defined %}
env:
{%- for variable in container.variables %}
- name: {{ variable.name }}
{%- if variable.fieldPath is defined %}
valueFrom:
fieldRef:
fieldPath: {{ variable.fieldPath }}
{%- else %}
value: {{ variable.value }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if container.ports is defined %}
ports:
{%- for port in container.ports %}
- containerPort: {{ port.port }}
name: {{ port.name }}
{%- endfor %}
{%- endif %}
{%- if container.command is defined %}
command:
{%- for command in container.command %}
- {{ command }}
{%- endfor %}
{%- endif %}
{%- if container.volumes is defined %}
volumeMounts:
{%- for volume in container.volumes %}
- name: {{ volume.name }}
mountPath: {{ volume.mount }}
readOnly: {{ volume.get('read_only', 'False') }}
{%- if volume.sub_path is defined %}
subPath: {{ volume.sub_path }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if container.liveness_probe is defined %}
livenessProbe:
{%- if container.liveness_probe.type == 'http' %}
httpGet:
path: {{ container.liveness_probe.path }}
port: {{ container.liveness_probe.port }}
{%- elif container.liveness_probe.type == 'exec' %}
exec:
command:
{%- for command in container.liveness_probe.command %}
- {{ command }}
{%- endfor %}
{%- endif %}
initialDelaySeconds: {{ container.liveness_probe.initial_delay }}
timeoutSeconds: {{ container.liveness_probe.timeout }}
{%- endif %}
{%- if container.readiness_probe is defined %}
readinessProbe:
{%- if container.readiness_probe.type == 'http' %}
httpGet:
path: {{ container.readiness_probe.path }}
port: {{ container.readiness_probe.port }}
{%- elif container.readiness_probe.type == 'exec' %}
exec:
command:
{%- for command in container.readiness_probe.command %}
- {{ command }}
{%- endfor %}
{%- endif %}
initialDelaySeconds: {{ container.readiness_probe.initial_delay }}
timeoutSeconds: {{ container.readiness_probe.timeout }}
{%- endif %}
{%- endfor %}
{%- if service.volume is defined %}
volumes:
{%- for volume_name, volume in service.volume.iteritems() %}
- name: {{ volume_name }}
{%- if volume.type == 'emptyDir' %}
emptyDir: {}
{%- elif volume.type == 'hostPath' %}
hostPath:
path: {{ volume.path }}
{%- elif volume.type == 'glusterfs' %}
glusterfs:
endpoints: {{ volume.endpoints }}
path: {{ volume.path }}
readOnly: {{ volume.read_only }}
{%- elif volume.type == 'config_map' %}
configMap:
name: {{ volume_name }}-{{ volume.get('version', '1') }}
items:
{%- for name, item in volume.item.iteritems() %}
- key: {{ item.key }}
path: {{ item.path }}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if service.nodeSelector is defined %}
nodeSelector:
{%- for selector in service.nodeSelector %}
{{ selector.key }}: {{ selector.value }}
{%- endfor %}
{%- endif %}
{%- if service.image_pull_secretes is defined %}
imagePullSecrets:
- name: {{ service.image_pull_secretes }}
{%- endif %}