Skip to content

Commit 71db65e

Browse files
authored
Merge pull request #190 from RS-PYTHON/fix-postgresql-labels
Improve cloudnative-pg deployment
2 parents f55ef3d + ec7b33e commit 71db65e

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

.github/workflows/test-deployment.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
uses: medyagh/setup-minikube@latest
5959
with:
6060
start-args: '--profile cluster.local'
61+
cpus: 4
6162
memory: 8000m
6263
- name: "Configure cluster"
6364
run: |
@@ -80,6 +81,7 @@ jobs:
8081
run: |
8182
sed -i 's!debug: false!debug: true!g' roles/app-installer/tasks/install_app.yaml
8283
sed -i 's!cinder.csi.openstack.org!k8s.io/minikube-hostpath!g' apps/00-storage-class/sc-retain.yaml
84+
sed -i 's!instances: 3!instances: 2!g' apps/01-cloudnative-pg/cluster.yaml
8385
sed -i -e 's!https://iam.{{ platform_domain_name }}!http://keycloak-service.iam.svc.cluster.local:8080!g' -e 's!insecure_oidc_skip_issuer_verification="false"!insecure_oidc_skip_issuer_verification="true"!g' apps/oauth2-proxy/values.yaml
84-
conda run -n rspy --no-capture-output env PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=1 ansible-playbook -v apps.yaml -i inventory/mycluster/hosts.yaml
86+
conda run -n rspy --no-capture-output env PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=1 ansible-playbook apps.yaml -i inventory/mycluster/hosts.yaml
8587
shell: bash

apps/00-crds-grafana-operator/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namePrefix: grafana-operator-
1616

1717

1818
resources:
19-
- https://raw.githubusercontent.com/grafana/grafana-operator/refs/tags/v5.9.0/deploy/kustomize/base/crds.yaml
19+
- https://github.com/grafana/grafana-operator/releases/download/v5.18.0/crds.yaml
2020
apiVersion: kustomize.config.k8s.io/v1beta1
2121
kind: Kustomization
2222
labels:

apps/01-cloudnative-pg/cluster.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ apiVersion: postgresql.cnpg.io/v1
1616
kind: Cluster
1717
metadata:
1818
name: postgresql-cluster
19+
labels:
20+
app.kubernetes.io/instance: '{{ app_name }}'
21+
wait-for-deployment: Ready
1922
spec:
2023
instances: 3
2124

roles/app-installer/tasks/install_app.yaml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
msg: "No kustomization.yaml file found in {{ app_dir }}. Documentation available at https://github.com/RS-PYTHON/rs-infra-core/blob/develop/docs/installation.md"
3131
when: not kustomization_file.stat.exists
3232

33-
- name: "{{ package_name }} - {{ app_name }} | Include vars from kustomization.yaml"
33+
- name: "{{ package_name }} - {{ app_name }} | Include vars from {{ kustomization_file.stat.path }}"
3434
include_vars:
35-
file: "{{ app_dir }}/kustomization.yaml"
35+
file: "{{ kustomization_file.stat.path }}"
3636
name: kustomization
3737
delegate_to: bastion
3838

@@ -124,6 +124,7 @@
124124
{% endif %} \
125125
--server-side \
126126
--force-conflicts \
127+
-o yaml \
127128
-l app.kubernetes.io/instance={{ app_name }}
128129
register: result
129130
delegate_to: bastion
@@ -142,16 +143,40 @@
142143

143144
- name: "{{ package_name }} - {{ app_name }} | Extract deployed resources"
144145
set_fact:
145-
resources: "{{ resources|d([]) + [item.split()[0]] }}"
146-
loop: "{{ result.stdout_lines }}"
146+
# cleanup the yaml to fix invalid CRD definitions before parsing
147+
resources: >-
148+
{{
149+
result.stdout
150+
| regex_replace('(?m)^([ ]*)- =$' , '\1- "="')
151+
| regex_replace('(?m)^([ ]*)- =~$', '\1- "=~"')
152+
| from_yaml_all
153+
| list
154+
}}
147155
delegate_to: bastion
148156

149157
- name: "{{ package_name }} - {{ app_name }} | Collect deployed resources and write them into resources.txt"
150158
copy:
151-
content: "{{ resources | join(' ') }}"
159+
content: "{{ resources }}"
152160
dest: "{{ app_dir }}/resources.txt"
153161
delegate_to: bastion
154162

163+
- name: "{{ package_name }} - {{ app_name }} | Wait for deployed resources readiness (when asked)"
164+
include_tasks: wait_ready.yaml
165+
args:
166+
apply:
167+
delegate_to: bastion
168+
# kubectl apply -o yaml does not produce the exact same output when applying one resource or several ones
169+
# make sure our resources list handles all cases
170+
loop: >-
171+
{{
172+
resources
173+
| map('community.general.json_query', "items || [@]")
174+
| flatten
175+
| list
176+
}}
177+
loop_control:
178+
label: "{{ item.kind }}/{{ item.metadata.name }}"
179+
155180
- name: "{{ package_name }} - {{ app_name }} | Detect jobs for this app"
156181
kubernetes.core.k8s_info:
157182
kind: Job
@@ -214,6 +239,11 @@
214239
delegate_to: bastion
215240

216241
rescue:
242+
- name: "{{ package_name }} - {{ app_name }} | Show resources"
243+
debug:
244+
var: resources
245+
when: resources | length > 0
246+
217247
- name: "{{ package_name }} - {{ app_name }} | Show jobs status"
218248
debug:
219249
var: jobs.resources
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2025 CS Group
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
- name: "{{ package_name }} - {{ app_name }} | Wait for {{ item.kind }} {{ item.metadata.name }} readiness (if asked)"
16+
kubernetes.core.k8s_info:
17+
api_version: "{{ item.apiVersion }}"
18+
kind: "{{ item.kind }}"
19+
name: "{{ item.metadata.name }}"
20+
namespace: "{{ item.metadata.namespace }}"
21+
wait: true
22+
wait_sleep: 1
23+
wait_timeout: 180
24+
wait_condition:
25+
type: "{{ item.metadata.labels['wait-for-deployment'] }}"
26+
when:
27+
- not ansible_check_mode
28+
- item.metadata.labels['wait-for-deployment'] is defined
29+
delegate_to: bastion

0 commit comments

Comments
 (0)