Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/packer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,5 @@ jobs:
image_builder/deploy/00controller.yaml
image_builder/deploy/01ui.yaml
image_builder/deploy/version-config.yaml
image_builder/deploy/version-checker.yaml
image_builder/deploy/vjailbreak-settings.yaml
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ generate-manifests: vjail-controller ui
rm -rf image_builder/deploy && mkdir -p image_builder/deploy && chmod 755 image_builder/deploy
envsubst < ui/deploy/ui.yaml > image_builder/deploy/01ui.yaml
envsubst < image_builder/configs/version-config.yaml > image_builder/deploy/version-config.yaml
cp image_builder/cronjob/version-checker.yaml image_builder/deploy/version-checker.yaml
cp image_builder/configs/vjailbreak-settings.yaml image_builder/deploy/vjailbreak-settings.yaml
make -C k8s/migration/ build-installer && cp k8s/migration/dist/install.yaml image_builder/deploy/00controller.yaml

Expand All @@ -81,4 +82,4 @@ build-image: generate-manifests
docker build --platform linux/amd64 --output=artifacts/ -t vjailbreak-image:local image_builder/

run-local:
cd k8s/migration/cmd/ && go run main.go --kubeconfig ${KUBECONFIG} --local true
cd k8s/migration/cmd/ && go run main.go --kubeconfig ${KUBECONFIG} --local true
92 changes: 92 additions & 0 deletions image_builder/cronjob/version-checker.yaml
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"]
Comment thread
sarika-pf9 marked this conversation as resolved.
---
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 0 * * *"
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/v1.34.0/bin/linux/amd64/kubectl"

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}')
Comment thread
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')
Comment thread
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
Comment thread
sarika-pf9 marked this conversation as resolved.

echo "Version Check Complete"
6 changes: 6 additions & 0 deletions image_builder/vjailbreak-image.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ build {
destination = "/tmp/vjailbreak-settings.yaml"
}

provisioner "file" {
source = "${path.root}/cronjob/version-checker.yaml"
destination = "/tmp/version-checker.yaml"
}

provisioner "file" {
source = "${path.root}/images"
destination = "/home/ubuntu"
Expand All @@ -97,6 +102,7 @@ build {
"sudo mv /tmp/daemonset.yaml /etc/pf9/yamls/daemonset.yaml",
"sudo mv /tmp/env /etc/pf9/env",
"sudo mv /tmp/vjailbreak-settings.yaml /etc/pf9/yamls/vjailbreak-settings.yaml",
"sudo mv /tmp/version-checker.yaml /etc/pf9/yamls/version-checker.yaml",
"sudo mv /tmp/opensource.txt /home/ubuntu/opensource.txt",
"sudo chmod +x /etc/pf9/install.sh",
"sudo chown root:root /etc/pf9/k3s.env",
Expand Down
Loading