This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added deploy container-storage command.
1) Added the logic to the deploy container storage. This addresses issue #4 2) Rearranged deploy folder to be more flexible 3) Added ability for ansible to save stats to a yaml file
- Loading branch information
Showing
12 changed files
with
413 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import os | ||
import sys | ||
import pickle | ||
import yaml | ||
from collections import defaultdict | ||
import ansible.parsing.yaml.objects | ||
import ansible.utils.unsafe_proxy | ||
from PyInquirer import Token, prompt, Separator | ||
|
||
|
||
def checkbox(prompt_label, options, cache=None): | ||
# ask for input | ||
cached_data = [] | ||
if cache: | ||
try: | ||
cached_data = pickle.load(open(cache, 'rb')) | ||
except (IOError, EOFError): | ||
pass | ||
|
||
if type(options) == list: | ||
choices = [{'name': item, | ||
'checked': item in cached_data} for item in options] | ||
else: | ||
choices = [] | ||
for item in options.keys(): | ||
item = str(item) | ||
choices += [Separator(item)] | ||
choices += [{'name': f'{item}: {option}', | ||
'checked': f'{item}: {option}' in cached_data} | ||
for option in options[item]] | ||
questions = [ | ||
{ | ||
'type': 'checkbox', | ||
'message': str(prompt_label), | ||
'name': 'results', | ||
'choices': choices | ||
} | ||
] | ||
result = prompt(questions)['results'] | ||
result.sort() | ||
|
||
# update cache | ||
if cache and result != cached_data: | ||
pickle.dump(result, open(cache, 'wb')) | ||
|
||
# nice format results | ||
if type(options) != list: | ||
nice_result = defaultdict(list) | ||
for key, val in [item.split(': ') for item in result]: | ||
nice_result[key].append(val) | ||
return nice_result | ||
|
||
# return results to ansible | ||
return result | ||
|
||
|
||
def load_stats(stats_file): | ||
return yaml.load(open(stats_file, 'r'), Loader=yaml.FullLoader) | ||
|
||
|
||
def save_stats(stats_file, stats_data): | ||
yaml.dump(stats_data, open(stats_file, 'w')) | ||
|
||
|
||
def main(): | ||
# load data | ||
stats = load_stats(os.environ['STATS_FILE']) | ||
|
||
# ask for storage nodes | ||
stg_nodes = checkbox('Select nodes to use for storage', | ||
stats['cluster_nodes'], | ||
'/data/container-storage-nodes.cache') | ||
stg_nodes = [str(item) for item in stg_nodes] | ||
|
||
# ask for storage devices | ||
drives = dict(zip(stg_nodes, | ||
[stats['cluster_drives'][item] | ||
for item in stg_nodes])) | ||
for key in drives.keys(): | ||
drives[key].sort() | ||
stg_drives = checkbox('Select the block devices to use for storage', | ||
drives, | ||
'/data/container-storage-drives.cache') | ||
stg_drives_out = [] | ||
for key, val in stg_drives.items(): | ||
stg_drives_out.append({'host': key, 'drives': val}) | ||
|
||
# count drives per node | ||
drives_per_node = min([len(item['drives']) for item in stg_drives_out]) | ||
|
||
# save data | ||
save_stats(os.environ['STATS_FILE'], { | ||
'stg_nodes': stg_nodes, | ||
'stg_drives': stg_drives_out, | ||
'cluster_nodes': stats['cluster_nodes'], | ||
'cluster_drives': stats['cluster_drives'], | ||
'drives_per_node': drives_per_node | ||
}) | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
- name: install openshift container storage | ||
hosts: localhost | ||
become: no | ||
gather_facts: no | ||
|
||
tasks: | ||
- name: ensure project exists | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: project.openshift.io/v1 | ||
kind: Project | ||
metadata: | ||
name: openshift-storage | ||
annotations: | ||
openshift.io/cluster-monitoring: "true" | ||
spec: | ||
|
||
- name: ensure operatorgroup exists | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: operators.coreos.com/v1 | ||
kind: OperatorGroup | ||
metadata: | ||
name: openshift-storage | ||
namespace: openshift-storage | ||
spec: | ||
targetNamespaces: | ||
- openshift-storage | ||
|
||
- name: ensure subscription exists | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: operators.coreos.com/v1alpha1 | ||
kind: Subscription | ||
metadata: | ||
name: ocs-operator | ||
namespace: openshift-storage | ||
spec: | ||
channel: "{{ lookup('ini', 'container_storage section=operators file=/app/versions.ini') }}" | ||
name: ocs-operator | ||
source: redhat-operators | ||
sourceNamespace: openshift-marketplace | ||
installPlanApproval: "Automatic" | ||
|
||
- name: save clusterserviceversion object | ||
set_fact: | ||
k8s_obj: | ||
apiVersion: operators.coreos.com/v1alpha1 | ||
kind: ClusterServiceVersion | ||
name: ocs-operator* | ||
namepace: openshift-storage | ||
|
||
- name: wait for operator to become ready | ||
assert: | ||
that: "lookup('k8s', resource_definition=k8s_obj)[0].status.phase | default('error') == 'Succeeded'" | ||
retries: 60 | ||
delay: 15 | ||
|
||
- name: ensure storagecluster exists | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: ocs.openshift.io/v1 | ||
kind: StorageCluster | ||
metadata: | ||
name: ocs-storagecluster | ||
namespace: openshift-storage | ||
spec: | ||
manageNodes: false | ||
monDataDirHostPath: /var/lib/rook | ||
storageDeviceSets: | ||
- count: "{{ drives_per_node }}" | ||
dataPVCTemplate: | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 1Gi | ||
storageClassName: localblock | ||
volumeMode: Block | ||
name: ocs-deviceset | ||
placement: {} | ||
portable: false | ||
replica: 3 | ||
resources: | ||
mds: | ||
limits: | ||
cpu: 0.5 | ||
requests: | ||
cpu: 0.25 | ||
noobaa-core: | ||
limits: | ||
cpu: 0.5 | ||
memory: 4Gi | ||
requests: | ||
cpu: 0.25 | ||
memory: 2Gi | ||
noobaa-db: | ||
limits: | ||
cpu: 0.5 | ||
memory: 4Gi | ||
requests: | ||
cpu: 0.25 | ||
memory: 2Gi | ||
mon: | ||
limits: | ||
cpu: 0.5 | ||
memory: 2Gi | ||
requests: | ||
cpu: 0.25 | ||
memory: 1Gi | ||
rook-ceph-rgw: | ||
limits: | ||
cpu: 250m | ||
memory: 2Gi | ||
requests: | ||
cpu: 100m | ||
memory: 1Gi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
- name: query cluster facts | ||
hosts: localhost | ||
become: no | ||
gather_facts: no | ||
|
||
pre_tasks: | ||
- name: lookup cluster nodes | ||
set_fact: | ||
cluster_nodes: "{{ lookup('k8s', api_version='v1', kind='Node') | json_query('[*].metadata.name')}}" | ||
|
||
- name: query cluster node drives | ||
shell: oc debug node/{{ item }} -- chroot /host lsblk -o NAME 2>/dev/null | egrep -v '((^ *`|^\|)|^NAME)' | ||
loop: "{{ cluster_nodes }}" | ||
register: cluster_drives | ||
ignore_errors: yes | ||
|
||
- name: save discovered hosts | ||
set_stats: | ||
data: | ||
cluster_nodes: "{{ cluster_nodes }}" | ||
|
||
- name: save discovered drives | ||
set_stats: | ||
data: | ||
cluster_drives: "{{ {item.item: item.stdout_lines} }}" | ||
loop: "{{ cluster_drives.results }}" |
Oops, something went wrong.