-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a support for updating argocd template file with correct …
…tag and added doc as well
- Loading branch information
1 parent
38ba0c1
commit fef4c5c
Showing
4 changed files
with
81 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM harbor.obmondo.com/obmondo/dockerfiles/jammy-generic-build@sha256:2145c7adffd30bc0d38f32c2b814fd60a537c7886a749e799daa9848707fd51f | ||
FROM harbor.obmondo.com/obmondo/jammy-generic-build@sha256:0d656390da967ca7e6cbcef3de1f9c1b560b3be5a269d988ab59f7d4d2270ce2 | ||
|
||
LABEL org.opencontainers.image.authors="Ashish Jaiswal <[email protected]>" | ||
|
||
|
@@ -9,14 +9,12 @@ WORKDIR /tmp | |
|
||
RUN apt-get update \ | ||
&& apt-get install software-properties-common -y \ | ||
&& add-apt-repository ppa:rmescandon/yq -y \ | ||
&& add-apt-repository ppa:longsleep/golang-backports -y \ | ||
&& apt-get update \ | ||
&& apt-get install -y \ | ||
shellcheck \ | ||
prometheus \ | ||
golang-1.19 \ | ||
yq | ||
golang-1.19 | ||
|
||
# jsonnet | ||
RUN go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/[email protected] | ||
|
@@ -33,6 +31,11 @@ RUN ./get_helm.sh --version v3.9.1 | |
RUN wget https://github.com/open-policy-agent/opa/releases/download/v0.43.0/opa_linux_amd64_static -O /usr/local/bin/opa | ||
RUN chmod +x /usr/local/bin/opa | ||
|
||
# tag script | ||
RUN curl -fsSL -o tag-update.sh https://raw.githubusercontent.com/Obmondo/kubeaid/refs/heads/master/bin/tag-update.sh | ||
RUN chmod +x tag-update.sh | ||
# YQ | ||
RUN wget https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -O /usr/local/bin/yq | ||
RUN chmod +x /usr/local/bin/yq | ||
|
||
# Add kubeaid argocd app update script | ||
COPY bin/update-kubeaid-argocd-app.sh /usr/bin/update-kubeaid-argocd-app.sh | ||
|
||
WORKDIR /workspace |
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,58 @@ | ||
#!/bin/bash | ||
|
||
# Function to display usage | ||
usage() { | ||
echo "Usage: $0 -c <cluster-name> -r <new-target-revision>" | ||
exit 1 | ||
} | ||
|
||
# Parse command-line options | ||
while getopts ":c:r:" opt; do | ||
case ${opt} in | ||
c ) | ||
CLUSTER_NAME="$OPTARG" | ||
;; | ||
r ) | ||
NEW_TARGET_REVISION="$OPTARG" | ||
;; | ||
\? ) | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
# Check if all required arguments are provided | ||
if [ -z "$CLUSTER_NAME" ] || [ -z "$NEW_TARGET_REVISION" ]; then | ||
usage | ||
fi | ||
|
||
TEMPLATES_DIR="${CLUSTER_NAME}/argocd-apps/templates" | ||
|
||
if [ ! -f "$CLUSTER_NAME/kube-prometheus/argocd-application-prometheus-rulesprometheusRuleExample.yaml" ]; then | ||
echo "File $CLUSTER_NAME/kube-prometheus/argocd-application-prometheus-rulesprometheusRuleExample.yaml does not exist. Exiting." | ||
echo "We need above file, to get the list of kubeaid managed apps" | ||
exit 1 | ||
fi | ||
|
||
# Extract labels.name using yq | ||
mapfile -t LABELS_NAMES < <(yq eval '.spec.groups[].rules[].labels.name' "$CLUSTER_NAME/kube-prometheus/argocd-application-prometheus-rulesprometheusRuleExample.yaml") | ||
|
||
# Loop through each label name and update the corresponding YAML file | ||
for label_name in "${LABELS_NAMES[@]}"; do | ||
yaml_file="${label_name}.yaml" # Assuming the YAML files are named after the labels | ||
file_path="${TEMPLATES_DIR}/${yaml_file}" | ||
|
||
# Check if the file exists | ||
if [[ -f "$file_path" ]]; then | ||
echo "Updating targetRevision in $file_path" | ||
|
||
# Use yq to update the targetRevision only if the repoURL contains kubeaid.git or k8id.git | ||
yq eval -i "(.spec.sources[] | select(.repoURL | test(\"kubeaid\\.git|k8id\\.git\")) | .targetRevision) = \"$NEW_TARGET_REVISION\"" "$file_path" | ||
|
||
echo "Updated targetRevision in $file_path" | ||
else | ||
echo "File $file_path does not exist, skipping." | ||
fi | ||
done | ||
|
||
echo "All specified YAML files have been processed." |
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,12 @@ | ||
# Update kubeaid apps managed via argocd | ||
|
||
* This scripts need to be run manually during the service or a day before and raise the PR and get it to merged. | ||
* The script basically point to the given tag as a flag to the script | ||
* Make sure the same tag is used for the entire service window cycle **DO NOT: use latest/recent tag in the middle of service window cycle** | ||
|
||
|
||
## Update the tags for a cluster | ||
|
||
```sh | ||
docker run --rm -it -v $(pwd):/workspace harbor.obmondo.com/obmondo/kubeaid:4.3.0 /bin/update-kubeaid-argocd-app.sh -c <cluster-name> -r <tag-for-the-current-window-cycle> | ||
``` |