Skip to content

Commit

Permalink
feat: added a support for updating argocd template file with correct …
Browse files Browse the repository at this point in the history
…tag and added doc as well
  • Loading branch information
ashish1099 committed Oct 30, 2024
1 parent 38ba0c1 commit fef4c5c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
17 changes: 10 additions & 7 deletions .gitea/Dockerfile
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]>"

Expand All @@ -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]
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ this repository.

All customizations happens in your `kubeaid-config` repo.

## support
## Support

Besides the community support, the primary developers of this project offers support via services on
[Obmondo.com](https://obmondo.com) - where you can opt to have us observe your world - and react to your alerts, and/or
Expand Down
58 changes: 58 additions & 0 deletions bin/update-kubeaid-argocd-app.sh
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."
12 changes: 12 additions & 0 deletions docs/update_kubeaid_argocd_apps.md
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>
```

0 comments on commit fef4c5c

Please sign in to comment.