forked from opendatahub-io/opendatahub-operator
-
Notifications
You must be signed in to change notification settings - Fork 28
281 lines (238 loc) · 11.6 KB
/
operator-processor.yaml
File metadata and controls
281 lines (238 loc) · 11.6 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: Operator Processor
on:
workflow_dispatch:
push:
branches:
- 'rhoai-[23].[0-9]' # e.g. rhoai-2.1, rhoai-3.1, rhoai-3.4
- 'rhoai-[23].[0-9][0-9]' # e.g. rhoai-2.10, rhoai-3.10, rhoai-3.22
- 'rhoai-[23].[0-9]-ea.[0-9]' # e.g. rhoai-2.4-ea.1, rhoai-3.4-ea.1, rhoai-3.5-ea.2
- 'rhoai-[23].[0-9][0-9]-ea.[0-9]' # e.g. rhoai-2.10-ea.1, rhoai-3.10-ea.3
paths:
- build/operator-nudging.yaml
env:
GITHUB_ORG: red-hat-data-services
LOG_FILE_DIR: ${{ github.workspace }}
LOG_FILE_NAME: operator-processor.log
permissions:
contents: write
jobs:
operator-processor:
if: ${{ github.ref_name != 'main' && (github.event_name == 'workflow_dispatch' || ( github.event_name == 'push' && github.event.commits[0].author.name == 'konflux-internal-p02[bot]' )) }}
runs-on: ubuntu-latest
steps:
- name: Checkout RBC repo
uses: actions/checkout@v4
with:
repository: ${{ env.GITHUB_ORG }}/RHOAI-Build-Config
ref: ${{ github.ref_name }}
path: RBC
sparse-checkout: |
bundle/bundle-patch.yaml
sparse-checkout-cone-mode: false
- name: Git checkout utils
uses: actions/checkout@v4
with:
repository: ${{ env.GITHUB_ORG }}/RHOAI-Konflux-Automation
ref: main
path: utils
sparse-checkout: |
utils/processors
sparse-checkout-cone-mode: false
- name: Git checkout operator repo
uses: actions/checkout@v4
with:
repository: ${{ env.GITHUB_ORG }}/rhods-operator
ref: ${{ github.ref_name }}
path: rhods-operator
sparse-checkout: |
build
prefetched-manifests
prefetched-charts
.tekton
sparse-checkout-cone-mode: false
- name: Install dependencies
run: |
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m | sed 's/x86_64/amd64/')"
yq_version="v4.44.3"
yq_filename="yq-$yq_version"
echo "-> Downloading yq" >&2
curl -sSfLo "$yq_filename" "https://github.com/mikefarah/yq/releases/download/$yq_version/yq_${os}_${arch}"
chmod +x $yq_filename
ln -s $yq_filename yq
cp $yq_filename /usr/local/bin/yq
pip install --default-timeout=100 -r utils/utils/processors/requirements.txt
- name: Execute Operator Processor
env:
BRANCH: ${{ github.ref_name }}
RHOAI_QUAY_API_TOKEN: ${{ secrets.RHOAI_QUAY_API_TOKEN }}
run: |
RHOAI_VERSION=v${BRANCH/rhoai-/}
COMPONENT_SUFFIX=${RHOAI_VERSION//./-}
ODH_OPERATOR_COMPONENT_NAME=odh-operator-${COMPONENT_SUFFIX}
PUSH_PIPELINE_PATH=rhods-operator/.tekton/${ODH_OPERATOR_COMPONENT_NAME}-push.yaml
PATCH_YAML_PATH=RBC/bundle/bundle-patch.yaml
OPERANDS_MAP_PATH=rhods-operator/build/operands-map.yaml
NUDGING_YAML_PATH=rhods-operator/build/operator-nudging.yaml
MANIFEST_CONFIG_PATH=rhods-operator/build/manifests-config.yaml
python3 utils/utils/processors/operator-processor.py -op process-operator-yamls --patch-yaml-path ${PATCH_YAML_PATH} --operands-map-path ${OPERANDS_MAP_PATH} --nudging-yaml-path ${NUDGING_YAML_PATH} --manifest-config-path ${MANIFEST_CONFIG_PATH} --rhoai-version ${BRANCH} --push-pipeline-yaml-path ${PUSH_PIPELINE_PATH} --push-pipeline-operation enable
- name: Print debug logs
if: always()
run: |
LOG_FILE="${{ env.LOG_FILE_DIR }}/${{ env.LOG_FILE_NAME }}"
if [ -f "$LOG_FILE" ]; then
cat "$LOG_FILE"
else
echo "Log file not found at $LOG_FILE"
fi
- name: Fetch all manifests
env:
BRANCH: ${{ github.ref_name }}
run: |
#!/bin/bash
set -e
echo "current dir = $(pwd)"
MANIFEST_CONFIG_PATH=${{ github.workspace }}/rhods-operator/build/manifests-config.yaml
PREFETCHED_MANIFEST_DIR_PATH="rhods-operator/prefetched-manifests"
# Clean up old prefetched manifests
if [ -d "$PREFETCHED_MANIFEST_DIR_PATH" ]; then
echo "Cleaning up old prefetched manifests..."
rm -rf "$PREFETCHED_MANIFEST_DIR_PATH"
fi
# Create fresh directories
mkdir -p "$PREFETCHED_MANIFEST_DIR_PATH"
mkdir -p manifests
cd manifests
while IFS= read -r value;
do
value=${value/- /}
component=$value
# Skip empty keys
[[ -z "$component" ]] && continue
echo "=============================================================="
echo "Fetching Manifest for component: $component"
echo "=============================================================="
if [[ -n $component ]]
then
git_url=$(value="$value" yq '.map[strenv(value)]["git.url"]' ${MANIFEST_CONFIG_PATH})
git_commit=$(value="$value" yq '.map[strenv(value)]["git.commit"]' ${MANIFEST_CONFIG_PATH})
ref_type=$(value="$value" yq '.map[strenv(value)]["ref_type"]' ${MANIFEST_CONFIG_PATH})
# If ref_type is branch, resolve the actual commit SHA
if [[ "$ref_type" == "branch" ]]; then
# Fetch latest commit SHA for the branch from remote
git_commit=$(git ls-remote "$git_url" "refs/heads/$BRANCH" | awk '{print $1}')
echo "Resolved git.commit for branch '$BRANCH' to commit SHA $git_commit"
# Update the git.commit field in manifests-config.yaml for the current component.
# Using strenv() to safely reference both the component key ($value) and the new commit SHA ($git_commit).
# This avoids issues with --arg, which is not supported in this yq version, and prevents creating an empty "" key.
value="$value" git_commit="$git_commit" yq -i eval '.map[strenv(value)]["git.commit"] = strenv(git_commit)' ${MANIFEST_CONFIG_PATH}
fi
src=$(value="$value" yq '.map[strenv(value)]["src"]' ${MANIFEST_CONFIG_PATH})
dest=$(value="$value" yq '.map[strenv(value)]["dest"]' ${MANIFEST_CONFIG_PATH})
echo "component = $component"
echo "git_url = $git_url"
echo "git_commit = $git_commit"
echo "src = $src"
echo "dest = $dest"
mkdir -p $component
cd $component
git config --global init.defaultBranch ${BRANCH}
git init
git remote add origin $git_url
git config core.sparseCheckout true
git config core.sparseCheckoutCone false
echo "$src" >> .git/info/sparse-checkout
git fetch --depth=1 origin $git_commit
git checkout $git_commit
cd ../
echo "current dir = $(pwd)"
dest_dir_path=${{ github.workspace }}/${PREFETCHED_MANIFEST_DIR_PATH}/$dest
mkdir -p ${dest_dir_path}
cp -r $component/$src/* ${dest_dir_path}
echo ""
fi
done < <(yq e '.map | keys' ${MANIFEST_CONFIG_PATH} )
cd ${{ github.workspace }}/${PREFETCHED_MANIFEST_DIR_PATH}
tree
- name: Fetch all charts
env:
BRANCH: ${{ github.ref_name }}
run: |
#!/bin/bash
set -e
echo "current dir = $(pwd)"
CHARTS_CONFIG_PATH=${{ github.workspace }}/rhods-operator/build/charts-config.yaml
PREFETCHED_CHARTS_DIR_PATH="rhods-operator/prefetched-charts"
# Clean up old prefetched charts
if [ -d "$PREFETCHED_CHARTS_DIR_PATH" ]; then
echo "Cleaning up old prefetched charts..."
rm -rf "$PREFETCHED_CHARTS_DIR_PATH"
fi
# Create fresh directories
mkdir -p "$PREFETCHED_CHARTS_DIR_PATH"
mkdir -p charts
cd charts
while IFS= read -r value;
do
value=${value/- /}
component=$value
# Skip empty keys
[[ -z "$component" ]] && continue
echo "=============================================================="
echo "Fetching Chart for component: $component"
echo "=============================================================="
if [[ -n $component ]]
then
git_url=$(value="$value" yq '.map[strenv(value)]["git.url"]' ${CHARTS_CONFIG_PATH})
git_commit=$(value="$value" yq '.map[strenv(value)]["git.commit"]' ${CHARTS_CONFIG_PATH})
ref_type=$(value="$value" yq '.map[strenv(value)]["ref_type"]' ${CHARTS_CONFIG_PATH})
if [[ "$ref_type" == "branch" ]]; then
git_commit=$(git ls-remote "$git_url" "refs/heads/$BRANCH" | awk '{print $1}')
echo "Resolved git.commit for branch '$BRANCH' to commit SHA $git_commit"
value="$value" git_commit="$git_commit" yq -i eval '.map[strenv(value)]["git.commit"] = strenv(git_commit)' ${CHARTS_CONFIG_PATH}
fi
src=$(value="$value" yq '.map[strenv(value)]["src"]' ${CHARTS_CONFIG_PATH})
dest=$(value="$value" yq '.map[strenv(value)]["dest"]' ${CHARTS_CONFIG_PATH})
echo "component = $component"
echo "git_url = $git_url"
echo "git_commit = $git_commit"
echo "src = $src"
echo "dest = $dest"
mkdir -p $component
cd $component
git config --global init.defaultBranch ${BRANCH}
git init
git remote add origin $git_url
git config core.sparseCheckout true
git config core.sparseCheckoutCone false
echo "$src" >> .git/info/sparse-checkout
git fetch --depth=1 origin $git_commit
git checkout $git_commit
cd ../
echo "current dir = $(pwd)"
dest_dir_path=${{ github.workspace }}/${PREFETCHED_CHARTS_DIR_PATH}/$dest
mkdir -p ${dest_dir_path}
cp -r $component/$src/* ${dest_dir_path}
echo ""
fi
done < <(yq e '.map | keys' ${CHARTS_CONFIG_PATH} )
cd ${{ github.workspace }}/${PREFETCHED_CHARTS_DIR_PATH}
tree
- name: Commit and push the changes to release branch
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}
message: "Updating the operator repo with latest images and manifests"
repository: ${{ env.GITHUB_ORG }}/rhods-operator
directory: rhods-operator
author_name: Openshift-AI DevOps
author_email: openshift-ai-devops@redhat.com
- name: Upload debug logs
if: always()
uses: actions/upload-artifact@v4
with:
name: operator-processor-output
path: ${{ env.LOG_FILE_DIR }}/${{ env.LOG_FILE_NAME }}
if-no-files-found: warn
retention-days: 30