Skip to content

Commit efce14b

Browse files
committed
add lab 7
1 parent 537a6a9 commit efce14b

10 files changed

Lines changed: 106 additions & 0 deletions

health.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Sat Oct 18 00:46:25 MSK 2025] HEALTHY: States match

labs/current-state.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
version: 1.0
3+
app: myapp
4+
replicas: 3

labs/desired-state.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
version: 1.0
3+
app: myapp
4+
replicas: 3

labs/health.log

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Sat Oct 18 00:46:28 MSK 2025] HEALTHY: States match
2+
[Sat Oct 18 00:46:33 MSK 2025] DRIFT: States differ
3+
[Sat Oct 18 00:46:35 MSK 2025] HEALTHY: States match
4+
[Sat Oct 18 00:46:43 MSK 2025] HEALTHY: States match
5+
[Sat Oct 18 00:46:48 MSK 2025] HEALTHY: States match

labs/healthcheck.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Healthcheck: compare md5 of desired-state.txt and current-state.txt
3+
md5_desired=$(md5sum desired-state.txt | awk '{print $1}')
4+
md5_current=$(md5sum current-state.txt | awk '{print $1}')
5+
if [ "$md5_desired" = "$md5_current" ]; then
6+
echo "[$(date)] HEALTHY: States match" >> health.log
7+
else
8+
echo "[$(date)] DRIFT: States differ" >> health.log
9+
fi

labs/monitor.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# Monitor loop: run healthcheck and reconcile in a loop
3+
while true; do
4+
./healthcheck.sh
5+
./reconcile.sh
6+
sleep 5
7+
done

labs/reconcile.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Sat Oct 18 00:46:20 MSK 2025] Reconciled current-state.txt with desired-state.txt
2+
[Sat Oct 18 00:46:35 MSK 2025] Reconciled current-state.txt with desired-state.txt

labs/reconcile.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# Reconcile current-state.txt with desired-state.txt
3+
if ! cmp -s desired-state.txt current-state.txt; then
4+
cp desired-state.txt current-state.txt
5+
echo "[$(date)] Reconciled current-state.txt with desired-state.txt" >> reconcile.log
6+
fi

labs/submission7.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Lab 7 Submission
2+
3+
## Task 1 — Git State Reconciliation
4+
5+
6+
### 1. Filling desired-state.txt and current-state.txt
7+
```bash
8+
echo 'version: 1.0' > labs/desired-state.txt
9+
echo 'app: myapp' >> labs/desired-state.txt
10+
echo 'replicas: 3' >> labs/desired-state.txt
11+
cp labs/desired-state.txt labs/current-state.txt
12+
```
13+
14+
### 2. Example of drift and reconcile
15+
```bash
16+
echo 'version: 2.0' > labs/current-state.txt
17+
echo 'app: myapp' >> labs/current-state.txt
18+
echo 'replicas: 5' >> labs/current-state.txt
19+
cd labs; bash reconcile.sh; cat current-state.txt
20+
# Output:
21+
version: 1.0
22+
app: myapp
23+
replicas: 3
24+
```
25+
26+
### 3. Reconcile-loop
27+
```bash
28+
cd labs; bash monitor.sh
29+
# (stop manually with Ctrl+C)
30+
```
31+
32+
## Task 2 — GitOps Health Monitoring
33+
34+
### 1. Healthcheck verification
35+
```bash
36+
cd labs; bash healthcheck.sh; cat health.log
37+
# Output:
38+
[Sat Oct 18 00:46:28 MSK 2025] HEALTHY: States match
39+
```
40+
41+
### 2. Introducing drift and re-check
42+
```bash
43+
cd labs; echo 'unapproved-change: true' >> current-state.txt; bash healthcheck.sh; cat health.log
44+
# Output:
45+
[Sat Oct 18 00:46:33 MSK 2025] DRIFT: States differ
46+
```
47+
48+
### 3. State recovery
49+
```bash
50+
cd labs; bash reconcile.sh; bash healthcheck.sh; cat health.log
51+
# Output:
52+
[Sat Oct 18 00:46:35 MSK 2025] HEALTHY: States match
53+
```
54+
55+
### 4. Example of monitor.sh in action
56+
```bash
57+
cd labs; bash monitor.sh
58+
# (stop manually with Ctrl+C)
59+
cat health.log
60+
# Output:
61+
[Sat Oct 18 00:46:43 MSK 2025] HEALTHY: States match
62+
[Sat Oct 18 00:46:48 MSK 2025] HEALTHY: States match
63+
```
64+
65+
## Conclusion:
66+
Thank you for the lab! That was interesting!

reconcile.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Sat Oct 18 00:46:09 MSK 2025] Reconciled current-state.txt with desired-state.txt
2+
[Sat Oct 18 00:46:16 MSK 2025] Reconciled current-state.txt with desired-state.txt

0 commit comments

Comments
 (0)