Skip to content

Commit

Permalink
test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Parthiba-Hazra committed Jul 24, 2024
1 parent fe4f51c commit 3ff3897
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 22 deletions.
48 changes: 30 additions & 18 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,61 +1,73 @@
name: Build and Deploy

on: [push, pull_request]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
CHECKPOINT_DIR: /var/lib/kubelet/checkpoints
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version: 1.21

- name: Install dependencies
run: |
# Install kind
curl -sLo kind "$(curl -sL https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | jq -r '[.assets[] | select(.name == "kind-linux-amd64")] | first | .browser_download_url')"
curl -sLo kind "$(curl -sL https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | jq -r '[.assets[] | select(.name == "kind-linux-arm64")] | first | .browser_download_url')"
chmod +x kind
sudo mv kind /bin/
# Install kubectl
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/arm64/kubectl"
chmod +x kubectl
sudo mv kubectl /bin/
- name: Create Kubernetes cluster
- name: Prepare Checkpoints Directory in Host
run: |
kind delete cluster
kind create cluster
kind export kubeconfig
sudo mkdir -p ${{ env.CHECKPOINT_DIR }}
sudo chmod 700 ${{ env.CHECKPOINT_DIR }}
sudo chown $USER ${{ env.CHECKPOINT_DIR }}
sudo echo ${{ env.CHECKPOINT_DIR }}
- name: Generate Checkpoint Tar Files
run: ./test/generate_checkpoint_tar.sh

- name: Generate Kind Config
run: ./test/generate_kind_config.sh

- name: Delete Existing Kind Cluster
run: kind delete cluster || true

- name: Create Kubernetes cluster
run: kind create cluster --config=kind-config.yaml

- name: Load Docker image into kind cluster
run: |
docker rmi checkpoint-restore-operator:ci || true
make docker-build IMG=checkpoint-restore-operator:ci
docker images | grep checkpoint-restore-operator
kind load docker-image checkpoint-restore-operator:ci
- name: Replace Placeholder in Manager
run: |
sed -i "s#__CHECKPOINT_DIR__#${{ env.CHECKPOINT_DIR }}#g" ./config/manager/manager.yaml
- name: Deploy to Kubernetes
run: |
make install
make deploy IMG=checkpoint-restore-operator:ci
sudo ls ${{ env.CHECKPOINT_DIR }}
- name: Wait for deployments to be ready
run: ./test/wait_for_deployment.sh checkpoint-restore-operator-controller-manager

- name: Check resources
run: kubectl get all -n checkpoint-restore-operator-system

- name: Prepare Checkpoints Directory in Kind Node
run: |
sudo mkdir -p /var/lib/kubelet/checkpoints
sudo chmod 777 /var/lib/kubelet/checkpoints
- name: Generate Checkpoint Tar Files
run: ./test/generate_checkpoint_tar.sh

- name: Wait for Checkpoint Tar Files to Reduce
run: |
kubectl apply -f ./test/test_checkpointrestoreoperator.yaml
Expand Down
10 changes: 10 additions & 0 deletions internal/controller/checkpointrestoreoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ func (gc *garbageCollector) runGarbageCollector() {
gc.Lock()
defer gc.Unlock()

// Log the list of all files in the checkpointDirectory(dor debugging purpose)
files, err := os.ReadDir(checkpointDirectory)
if err != nil {
log.Error(err, "failed to read checkpointDirectory")
} else {
for _, file := range files {
log.Info("Existing file", "name", file.Name())
}
}

// based on fsnotify example code
watcher, err := fsnotify.NewWatcher()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions test/checkpoints/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
14 changes: 14 additions & 0 deletions test/generate_kind_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

CONFIG_FILE="kind-config.yaml"
CHECKPOINT_DIR="/var/lib/kubelet/checkpoints"

{
echo "kind: Cluster"
echo "apiVersion: kind.x-k8s.io/v1alpha4"
echo "nodes:"
echo "- role: control-plane"
echo " extraMounts:"
echo " - hostPath: /var/lib/kubelet/checkpoints"
echo " containerPath: $CHECKPOINT_DIR"
} >$CONFIG_FILE
2 changes: 1 addition & 1 deletion test/test_checkpointrestoreoperator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
app.kubernetes.io/created-by: checkpoint-restore-operator
name: checkpointrestoreoperator-sample
spec:
checkpointDirectory: /var/lib/kubelet/checkpoints/
checkpointDirectory: /var/lib/kubelet/checkpoints
applyPoliciesImmediately: true
globalPolicy:
maxCheckpointsPerNamespace: 10
Expand Down
2 changes: 1 addition & 1 deletion test/wait_for_checkpoint_reduction.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

CHECKPOINTS_DIR="/var/lib/kubelet/checkpoints/"
CHECKPOINTS_DIR="/var/lib/kubelet/checkpoints"
EXPECTED_COUNT=2
TIMEOUT=60
start_time=$(date +%s)
Expand Down
9 changes: 7 additions & 2 deletions test/wait_for_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

wait_for_deployment() {
local deployment_name="$1"
timeout=60 # 5 minutes (60 * 5 sec)
timeout=20 # 5 minutes (60 * 5 sec)
i=1
echo "Checking if the ${deployment_name} deployment is ready"
until kubectl -n checkpoint-restore-operator-system get deployment "${deployment_name}" -o jsonpath='{.status.conditions[?(@.status=="True")].type}' | grep "Available" 2>/dev/null; do
Expand All @@ -14,9 +14,14 @@ wait_for_deployment() {
kubectl -n checkpoint-restore-operator-system describe deployment "${deployment_name}"
kubectl -n checkpoint-restore-operator-system get pods
kubectl -n checkpoint-restore-operator-system describe pods
echo "Fetching detailed logs from the pods for further debugging:"
for pod in $(kubectl -n checkpoint-restore-operator-system get pods -o jsonpath='{.items[*].metadata.name}'); do
echo "Logs for pod ${pod}:"
kubectl -n checkpoint-restore-operator-system logs "${pod}"
done
exit 1
fi
echo "Waiting for ${deployment_name} deployment to report a ready status"
echo "Waiting for ${deployment_name} deployment to report a ready status (Attempt ${i}/${timeout})"
sleep 5
done
echo "The ${deployment_name} deployment is ready"
Expand Down

0 comments on commit 3ff3897

Please sign in to comment.