Merge "[Cinder] Add visibilty settings to volume types"

This commit is contained in:
Zuul
2022-05-03 21:36:22 +00:00
committed by Gerrit Code Review
5 changed files with 84 additions and 44 deletions

View File

@@ -14,7 +14,7 @@ apiVersion: v1
appVersion: v1.0.0 appVersion: v1.0.0
description: OpenStack-Helm Cinder description: OpenStack-Helm Cinder
name: cinder name: cinder
version: 0.2.18 version: 0.2.19
home: https://docs.openstack.org/cinder/latest/ home: https://docs.openstack.org/cinder/latest/
icon: https://www.openstack.org/themes/openstack/images/project-mascots/Cinder/OpenStack_Project_Cinder_vertical.png icon: https://www.openstack.org/themes/openstack/images/project-mascots/Cinder/OpenStack_Project_Cinder_vertical.png
sources: sources:

View File

@@ -22,30 +22,53 @@ export HOME=/tmp
{{- /* Create volume types defined in Values.bootstrap */}} {{- /* Create volume types defined in Values.bootstrap */}}
{{- /* Types can only be created for backends defined in Values.conf */}} {{- /* Types can only be created for backends defined in Values.conf */}}
{{- $volumeTypes := .Values.bootstrap.volume_types }} {{- $volumeTypes := .Values.bootstrap.volume_types }}
{{- /* Generating list of backends listed in .Values.conf.backends */}}
{{- $backendsList := list}}
{{- range $backend_name, $backend_properties := .Values.conf.backends }} {{- range $backend_name, $backend_properties := .Values.conf.backends }}
{{- if $backend_properties }} {{- if and $backend_properties $backend_properties.volume_backend_name }}
{{- $backendsList = append $backendsList $backend_properties.volume_backend_name }}
{{- end }}
{{- end }}
{{- range $name, $properties := $volumeTypes }} {{- range $name, $properties := $volumeTypes }}
{{- if $properties.volume_backend_name }} {{- if and $properties.volume_backend_name (has $properties.volume_backend_name $backendsList) }}
{{- if (eq $properties.volume_backend_name $backend_properties.volume_backend_name) }} {{- $access_type := $properties.access_type | default "public"}}
if [[ $(openstack volume type list -f value -c Name | grep -w {{ $name }}) ]]; then # Create a volume type if it doesn't exist.
if [[ ! $(openstack volume type show {{ $name }} | grep volume_backend_name) ]]; then # Assumption: the volume type name is unique.
openstack volume type set \ openstack volume type show {{ $name }} || \
{{- range $key, $value := $properties }}
--property {{ $key }}={{ $value }} \
{{- end }}
{{ $name }}
fi
else
openstack volume type create \ openstack volume type create \
--public \ --{{ $access_type }} \
{{- range $key, $value := $properties }}
--property {{ $key }}={{ $value }} \
{{- end }}
{{ $name }} {{ $name }}
{{/*
We will try to set or update volume type properties.
To update properties, the volume type MUST NOT BE IN USE,
and projects and domains with access to the volume type
MUST EXIST, as well.
*/}}
is_in_use=$(openstack volume list --long --all-projects -c Type -f value | grep -E "^{{ $name }}\s*$" || true)
if [[ -z ${is_in_use} ]]; then
{{- if (eq $access_type "private") }}
volumeTypeID=$(openstack volume type show {{ $name }} -f value -c id)
cinder type-update --is-public false ${volumeTypeID}
{{- end }}
{{- if and $properties.grant_access (eq $access_type "private") }}
{{- range $domain, $domainProjects := $properties.grant_access }}
{{- range $project := $domainProjects }}
project_id=$(openstack project show --domain {{ $domain }} -c id -f value {{ $project }})
if [[ -z $(openstack volume type show {{ $name }} -c access_project_ids -f value | grep ${project_id} || true) ]]; then
openstack volume type set --project-domain {{ $domain }} --project {{ $project }} {{ $name }}
fi fi
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- range $key, $value := $properties }}
{{- if and (ne $key "access_type") (ne $key "grant_access") $value }}
openstack volume type set --property {{ $key }}={{ $value }} {{ $name }}
{{- end }}
{{- end }}
fi
{{- end }} {{- end }}
{{- end }} {{- end }}
@@ -72,7 +95,7 @@ if ! openstack volume type show {{ . }}; then
type_defined=false type_defined=false
fi fi
{{- end }} {{- end }}
if $type_defined; then if [[ ${type_defined} ]]; then
openstack volume qos show {{ $qos_name }} || \ openstack volume qos show {{ $qos_name }} || \
openstack volume qos create \ openstack volume qos create \
--consumer {{ $qos_properties.consumer }} \ --consumer {{ $qos_properties.consumer }} \
@@ -90,7 +113,6 @@ fi
{{- /* Check volume type and properties were added */}} {{- /* Check volume type and properties were added */}}
openstack volume type list --long openstack volume type list --long
openstack volume qos list openstack volume qos list
{{- end }} {{- end }}
exit 0 exit 0

View File

@@ -368,6 +368,19 @@ bootstrap:
name: name:
group: group:
volume_backend_name: volume_backend_name:
# access_type: "private"
# If you set up access_type to private, only the creator
# will get an access to the volume type. You can extend
# the access to your volume type by providing a list of
# domain names and projects as shown below
# grant_access:
# <domain name 1>:
# - <project name 1>
# - <project name 2>
# <...>
# <domain name 2>:
# - <project name 1>
# <...>
# Volume QoS if any. By default, None QoS is created. # Volume QoS if any. By default, None QoS is created.
# Below values with a number at the end need to be replaced # Below values with a number at the end need to be replaced
# with real names. # with real names.

View File

@@ -22,6 +22,10 @@ bootstrap:
PURE-MULTIATTACH: PURE-MULTIATTACH:
multiattach: "\"<is> True\"" multiattach: "\"<is> True\""
volume_backend_name: "PURE_BE" volume_backend_name: "PURE_BE"
access_type: "private"
grant_access:
default:
- admin
conf: conf:
cinder: cinder:
DEFAULT: DEFAULT:

View File

@@ -35,4 +35,5 @@ cinder:
- 0.2.16 Enable taint toleration for Openstack services - 0.2.16 Enable taint toleration for Openstack services
- 0.2.17 Remove unsupported values overrides - 0.2.17 Remove unsupported values overrides
- 0.2.18 Add helm hook in bootstrap job - 0.2.18 Add helm hook in bootstrap job
- 0.2.19 Add volume types visibility (public/private)
... ...