This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
populate.yml
159 lines (131 loc) · 5 KB
/
populate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2021-2022, Intel Corporation
#
---
- import_playbook: "include/playbooks/check_dimms.yml"
- hosts: utility[0]
become: true
become_user: root
environment:
PATH: "{{ ansible_env.PATH }}:/usr/local/bin"
pre_tasks:
- name: "populate | Load playbook variables"
include_vars: "vars/vars.yml"
tasks:
- name: "populate | Generate run_id variable"
set_fact:
run_id: "{{ lookup('env', 'run_id') | default((99999999 | random | to_uuid | hash('md5'))[:4], true) }}\
-th{{ threads }}-cln{{ clients }}-p{{ pipeline }}-req{{ requests }}"
- name: "populate | Write run_id to group_vars"
lineinfile:
create: true
insertafter: EOF
line: "run_id: {{ run_id }}"
path: "{{ playbook_dir }}/group_vars/all"
state: present
- name: "populate | Print run_id"
debug:
var: run_id
- name: "populate | Clear variables"
set_fact:
namespaces_counter: []
namespaces: []
- name: "populate | Generate namespaces indexes"
set_fact:
namespaces_counter: "{{ namespaces_counter | default([]) + [ item ] }}"
with_sequence: start=1 end="{{ clusters_count }}"
- name: "populate | Generate namespaces names"
set_fact:
namespaces: "{{ namespaces | default([]) + [ namespace_prefix + '%s' | format(item) ] }}"
loop: "{{ namespaces_counter }}"
- set_fact:
single_cluster_testcase: "{{ True if clusters_count|int == 1 else False }}"
- name: "populate | Get nodes with client label"
kubernetes.core.k8s_info:
kind: Node
label_selectors:
- node-type=redis-client
register: labeled_nodes_raw_info
- set_fact:
labeled_nodes_info: "{{ labeled_nodes_info | default([]) + [ item.metadata['name'] ] }}"
with_items: "{{ labeled_nodes_raw_info['resources'] }}"
no_log: true
- name: "populate | Remove old client labels"
kubernetes.core.k8s:
definition:
apiVersion: v1
kind: Node
metadata:
name: "{{ item }}"
labels:
node-type: null
state: patched
with_items: "{{ labeled_nodes_info }}"
when: labeled_nodes_info is defined
- name: "populate | Add client labels to nodes"
kubernetes.core.k8s:
definition:
apiVersion: v1
kind: Node
metadata:
name: "{{ item }}"
labels:
node-type: redis-client
state: patched
with_items: "{{ groups['clients'] }}"
- name: "populate | Create populate_db job config directory"
file:
path: "{{ k8s_definitions_dir }}/{{ redis_cluster_namespace }}/populate_db"
recurse: yes
loop: "{{ namespaces }}"
loop_control:
loop_var: redis_cluster_namespace
- set_fact:
populate_job_name: "redis-populate-{{ run_id }}"
- include_tasks: "include/tasks/create_job_config.yml"
vars:
job_name: "{{ populate_job_name }}"
kustomization_dir: "populate_db"
namespace: "{{ redis_cluster_namespace }}"
templates_path: "{{ playbook_dir }}/templates"
loop: "{{ namespaces }}"
loop_control:
loop_var: redis_cluster_namespace
- set_fact:
sequence_counter: 12
- include_tasks: "include/tasks/populate_clusters.yml"
vars:
job_name: "{{ populate_job_name }}"
population_namespaces: "{{ namespaces[(item | int - 1) * (sequence_counter | int):(item | int) * (sequence_counter | int)] }}"
with_sequence: start=1 end="{{ (clusters_count | int / sequence_counter | int) | round(0, 'ceil') | int }}"
- set_fact:
exec_stamp: "{{ ansible_date_time.epoch }}"
- include_tasks: "include/tasks/save_pods_info.yml"
vars:
namespace: "{{ redis_cluster_namespace }}"
loop: "{{ namespaces }}"
loop_control:
loop_var: redis_cluster_namespace
- name: "populate | Collect masters and replicas instances distribution"
shell: "{{ playbook_dir }}/utils/distribution_of_redis_masters_and_replicas_on_k8s_nodes.sh"
register: distribution_stdout
- name: "populate | Save distribution info to file"
lineinfile:
line: "{{ distribution_stdout.stdout }}"
dest: "{{ logdir }}/{{ log_dir_structure }}/{{ run_id }}/masters-replicas-distribution-{{ run_id }}.txt"
create: yes
- set_fact:
timestamp_file_path: "{{ logdir }}/{{ log_dir_structure }}/{{ run_id }}/timestamp.txt"
- name: "populate | Save timestamp to file"
copy:
content: "{{ exec_stamp }}"
dest: "{{ timestamp_file_path }}"
- block:
- set_fact:
pods_info_file_path: "{{ logdir }}/{{ log_dir_structure }}/{{ run_id }}/single_redis-cluster_pods_info_raw.txt"
- name: "populate | Save pods info to file"
copy:
content: "{{ pods }}"
dest: "{{ pods_info_file_path }}"
when: single_cluster_testcase
# vi:et:sw=2 ts=2 sts=2 ft=ansible