-
Notifications
You must be signed in to change notification settings - Fork 30
Added cronjob to fetch for latest release and notify in UI #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a423d63
added cronjob to check latest release
sarika-pf9 4f45339
lints
sarika-pf9 68f9597
fixing spaces
sarika-pf9 43d1a91
copied while building image
sarika-pf9 1dcfb32
Merge branch 'main' into private/main/cron-for-upgrade
sarika-pf9 d0e4db9
pinned kubectl version
sarika-pf9 90393e1
Merge branch 'main' into private/main/cron-for-upgrade
sarika-pf9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: version-checker-sa | ||
| namespace: migration-system | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: configmap-editor-role | ||
| namespace: migration-system | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: ["configmaps"] | ||
| resourceNames: ["version-config"] | ||
| verbs: ["get", "patch"] | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: version-checker-binding | ||
| namespace: migration-system | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: version-checker-sa | ||
| namespace: migration-system | ||
| roleRef: | ||
| kind: Role | ||
| name: configmap-editor-role | ||
| apiGroup: rbac.authorization.k8s.io | ||
| --- | ||
| apiVersion: batch/v1 | ||
| kind: CronJob | ||
| metadata: | ||
| name: vjailbreak-version-checker | ||
| namespace: migration-system | ||
| spec: | ||
| schedule: "0 21 * * *" | ||
| concurrencyPolicy: Forbid | ||
| jobTemplate: | ||
| spec: | ||
| ttlSecondsAfterFinished: 300 | ||
| template: | ||
| spec: | ||
| serviceAccountName: version-checker-sa | ||
| restartPolicy: OnFailure | ||
| containers: | ||
| - name: version-checker | ||
| image: alpine:3.18 | ||
| command: | ||
| - /bin/sh | ||
| - -c | ||
| - | | ||
| set -e | ||
| apk add --no-cache curl jq | ||
|
|
||
| curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | ||
|
sarika-pf9 marked this conversation as resolved.
Outdated
|
||
|
|
||
| chmod +x kubectl | ||
| mv kubectl /usr/local/bin/ | ||
|
|
||
| echo "Checking for latest version" | ||
| CURRENT_VERSION=$(kubectl get configmap version-config -n migration-system -o jsonpath='{.data.version}') | ||
|
sarika-pf9 marked this conversation as resolved.
|
||
| echo "Current version: $CURRENT_VERSION" | ||
|
|
||
| if [ -z "$CURRENT_VERSION" ]; then | ||
| echo "Error: 'version' key not found in ConfigMap. Exiting." | ||
| exit 1 | ||
| fi | ||
|
|
||
| LATEST_TAG=$(curl -s "https://api.github.com/repos/platform9/vjailbreak/tags" | jq -r '.[0].name') | ||
|
sarika-pf9 marked this conversation as resolved.
|
||
|
|
||
| if [ -z "$LATEST_TAG" ] || [ "$LATEST_TAG" == "null" ]; then | ||
| echo "Error: Could not fetch latest tag from GitHub. Exiting." | ||
| exit 1 | ||
| fi | ||
| echo "Latest tag on GitHub: $LATEST_TAG" | ||
|
|
||
| CURRENT_SEMVER=${CURRENT_VERSION#v} | ||
| LATEST_SEMVER=${LATEST_TAG#v} | ||
| HIGHEST_VERSION=$(printf "%s\n%s" "$CURRENT_SEMVER" "$LATEST_SEMVER" | sort -V | tail -n1) | ||
|
|
||
| if [ "$LATEST_SEMVER" != "$CURRENT_SEMVER" ] && [ "$HIGHEST_VERSION" == "$LATEST_SEMVER" ]; then | ||
| echo "New version found! Updating ConfigMap..." | ||
| PATCH_DATA="{\"data\":{\"upgradeAvailable\":\"true\",\"upgradeVersion\":\"$LATEST_TAG\"}}" | ||
| kubectl patch configmap version-config -n migration-system --type='merge' -p="$PATCH_DATA" | ||
| echo "ConfigMap 'version-config' updated successfully." | ||
| else | ||
| echo "You are on the latest version. No update needed." | ||
| fi | ||
|
sarika-pf9 marked this conversation as resolved.
|
||
|
|
||
| echo "Version Check Complete" | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.