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/
  • Loading branch information
David Moreau Simard committed Jun 13, 2018
1 parent a1634c3 commit e8ea5b4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
23 changes: 23 additions & 0 deletions roles/lib_utils/action_plugins/generate_pv_pvcs_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ def build_pv_glusterfs(self, varname=None):
path=path,
readOnly=read_only)))

def build_pv_hostpath(self, varname=None):
"""Build pv dictionary for hostpath storage type"""
volume, size, labels, _, access_modes = self.build_common(varname=varname)
# hostpath only supports ReadWriteOnce
if access_modes[0] != 'ReadWriteOnce':
msg = "Hostpath storage only supports 'ReadWriteOnce' Was given {}."
raise errors.AnsibleModuleError(msg.format(access_modes.join(', ')))
path = self.get_templated(str(varname) + '_hostpath_path')
return dict(
name="{0}-volume".format(volume),
capacity=size,
labels=labels,
access_modes=access_modes,
storage=dict(
hostPath=dict(
path=path
)
)
)

def build_pv_dict(self, varname=None):
"""Check for the existence of PV variables"""
kind = self.task_vars.get(str(varname) + '_kind')
Expand All @@ -106,6 +126,9 @@ def build_pv_dict(self, varname=None):
elif kind == 'glusterfs':
return self.build_pv_glusterfs(varname=varname)

elif kind == 'hostpath':
return self.build_pv_hostpath(varname=varname)

elif not (kind == 'object' or kind == 'dynamic' or kind == 'vsphere'):
msg = "|failed invalid storage kind '{0}' for component '{1}'".format(
kind,
Expand Down
4 changes: 3 additions & 1 deletion roles/openshift_facts/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ openshift_hosted_registry_storage_glusterfs_readOnly: False
openshift_hosted_registry_storage_glusterfs_swap: False
openshift_hosted_registry_storage_glusterfs_swapcopy: True
openshift_hosted_registry_storage_glusterfs_ips: []
openshift_hosted_registry_storage_hostpath_path: /var/lib/openshift_volumes/registry
# Default to ReadWriteOnce if using hostpath, else default to ReadWriteMany
openshift_hosted_registry_storage_access_modes:
- 'ReadWriteMany'
- "{{ (openshift_hosted_registry_storage_kind == 'hostpath') | ternary('ReadWriteOnce', 'ReadWriteMany') }}"

openshift_logging_storage_nfs_directory: '/exports'
openshift_logging_storage_nfs_options: '*(rw,root_squash)'
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 @@ -77,7 +77,7 @@
type: persistentVolumeClaim
claim_name: "{{ openshift_hosted_registry_storage_volume_name }}-claim"
when:
- openshift_hosted_registry_storage_kind | default(none) in ['nfs', 'openstack', 'glusterfs', 'vsphere']
- openshift_hosted_registry_storage_kind | default(none) in ['nfs', 'glusterfs', 'hostpath', 'openstack', 'vsphere']

- include_tasks: storage/glusterfs_endpoints.yml
when:
Expand All @@ -96,3 +96,7 @@
volume_mounts: "{{ openshift_hosted_registry_volumes }}"
edits: "{{ openshift_hosted_registry_edits }}"
force: "{{ True|bool in openshift_hosted_registry_force }}"

- include_tasks: storage/hostpath.yml
when:
- openshift_hosted_registry_storage_kind | default(none) in ['hostpath']
31 changes: 31 additions & 0 deletions roles/openshift_hosted/tasks/storage/hostpath.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- 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.items() %}{{ 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'] | lib_utils_oo_collect(attribute='status.conditions') | lib_utils_oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count == openshift_hosted_registry_replicas | int"
delay: 10
retries: 60

# https://docs.openshift.com/container-platform/3.9/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: "{{ registry_pods.results.results[0]['items'][0].spec.containers[0].securityContext.runAsUser }}"
group: "{{ registry_pods.results.results[0]['items'][0].spec.securityContext.fsGroup }}"
mode: "2750"

0 comments on commit e8ea5b4

Please sign in to comment.