Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hostpath persistent volume definitions #6022

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions inventory/hosts.example
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ debug_level=2
#openshift_hosted_registry_storage_openstack_volumeID=3a650b4f-c8c5-4e0a-8ca5-eaee11f16c57
#openshift_hosted_registry_storage_volume_size=10Gi
#
# hostPath (local filesystem storage)
# Suitable for "all-in-one" or proof of concept deployments
# Must not be used for high-availability and production deployments
#openshift_hosted_registry_storage_kind=hostpath
#openshift_hosted_registry_storage_access_modes=['ReadWriteOnce']
#openshift_hosted_registry_storage_hostpath_path=/var/lib/openshift_volumes
#openshift_hosted_registry_storage_volume_size=10Gi
#
# AWS S3
# S3 bucket must already exist.
#openshift_hosted_registry_storage_kind=object
Expand Down
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
# 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"