Skip to content

Commit

Permalink
Add support for hostpath persistent volume definitions
Browse files Browse the repository at this point in the history
hostpath volumes [1] mount a file or directory from the host node’s
filesystem into a pod. This adds support for declaring a hostPath
volume as a persistent volume and do a persistent volume claim for
one for the hosted registry.

[1]: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
  • Loading branch information
David Moreau-Simard committed Nov 7, 2017
1 parent 7b2afd7 commit 81292a9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
19 changes: 19 additions & 0 deletions filter_plugins/oo_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,25 @@ def oo_component_persistent_volumes(hostvars, groups, component, subcomponent=No
path=path,
readOnly=read_only)))

elif kind == 'hostpath':
volume = params['volume']['name']
size = params['volume']['size']
if 'labels' in params:
labels = params['labels']
else:
labels = dict()
access_modes = params['access']['modes']
path = params['hostpath']['path']
persistent_volume = dict(
name="{0}-volume".format(volume),
capacity=size,
labels=labels,
access_modes=access_modes,
storage=dict(
hostPath=dict(
path=path,
)))

elif not (kind == 'object' or kind == 'dynamic'):
msg = "|failed invalid storage kind '{0}' for component '{1}'".format(
kind,
Expand Down
6 changes: 5 additions & 1 deletion roles/openshift_hosted/tasks/registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
type: persistentVolumeClaim
claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-claim"
when:
- openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack', 'glusterfs']
- openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack', 'glusterfs', 'hostpath']

- name: Create OpenShift registry
oc_adm_registry:
Expand Down Expand Up @@ -140,3 +140,7 @@
- include: storage/glusterfs.yml
when:
- openshift.hosted.registry.storage.kind | default(none) == 'glusterfs' or openshift.hosted.registry.storage.glusterfs.swap

- include: storage/hostpath.yml
when:
- openshift.hosted.registry.storage.kind | default(none) == 'hostpath'
36 changes: 36 additions & 0 deletions roles/openshift_hosted/tasks/storage/hostpath.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Get registry DeploymentConfig
oc_obj:
namespace: "{{ openshift_hosted_registry_namespace }}"
state: list
kind: dc
name: "{{ openshift_hosted_registry_name }}"
register: registry_dc

- name: Wait for registry pods
oc_obj:
namespace: "{{ openshift_hosted_registry_namespace }}"
state: list
kind: pod
selector: "{% for label, value in registry_dc.results.results[0].spec.selector.iteritems() %}{{ label }}={{ value }}{% if not loop.last %},{% endif %}{% endfor %}"
register: registry_pods
until:
- "registry_pods.results.results[0]['items'] | count > 0"
# There must be as many matching pods with 'Ready' status True as there are expected replicas
- "registry_pods.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count == openshift_hosted_registry_replicas | int"
delay: 10
retries: "{{ (600 / 10) | int }}"

- name: Determine registry fsGroup and runAsUser
set_fact:
openshift_hosted_registry_fsgroup: "{{ registry_pods.results.results[0]['items'][0].spec.securityContext.fsGroup }}"
openshift_hosted_registry_runasuser: "{{ registry_pods.results.results[0]['items'][0].spec.containers[0].securityContext.runAsUser }}"

# https://docs.openshift.com/container-platform/3.6/install_config/registry/deploy_registry_existing_clusters.html#registry-non-production-use
- name: Ensure permissions on the hostpath match the pod configuration
file:
path: "{{ openshift.hosted.registry.storage.hostpath.path }}"
state: directory
owner: "{{ openshift_hosted_registry_runasuser }}"
group: "{{ openshift_hosted_registry_fsgroup }}"
mode: "2750"

0 comments on commit 81292a9

Please sign in to comment.