Skip to content

Commit 2243ab6

Browse files
feat: add Lima VM configurations and tests for k3s and Debian VPS
- Introduced new BATS tests in tests/bats/lima.bats to validate Lima VM configurations and Kubernetes resources. - Created k3s-master.yaml and debian-vps.yaml for k3s master node and Debian VPS setups, respectively. - Added smoke-test.yaml and smoke-monitoring.yaml to test TLS pipelines for whoami and Grafana applications. - Implemented grafana-cert.yaml for self-signed TLS certificate generation for Grafana. - Added verification scripts for k3s and VPS setups to ensure proper installation and configuration. - Updated scripts.bats to check for existence of new setup scripts.
1 parent 0cb28cb commit 2243ab6

File tree

15 files changed

+1312
-27
lines changed

15 files changed

+1312
-27
lines changed

Makefile

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ include makefiles/40-kubeconfig.mk
3535
include makefiles/50-deploy.mk
3636
include makefiles/60-status.mk
3737
include makefiles/70-ssh.mk
38-
39-
# ── Testing ──────────────────────────────────────────────────────────────────
40-
41-
.PHONY: test
42-
43-
test: ## Run BATS unit tests (offline — no cluster needed)
44-
@bats tests/bats/
45-
46-
# ── Hooks ────────────────────────────────────────────────────────────────────
47-
48-
.PHONY: hooks-update
49-
50-
hooks-update: ## Update prek hook revisions to latest (prek autoupdate)
51-
@prek autoupdate
38+
include makefiles/80-dev.mk
39+
include makefiles/90-provision.mk
40+
include makefiles/99-lima.mk

makefiles/00-lib.mk

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
# Macros (use with $(call ...)):
1212
# run-remote-script(rel-path, host, env-prefix)
1313
# Run a script on a remote SSH host.
14-
# rel-path — path relative to k3s-lab root, e.g. k3s/install-master.sh
15-
# host — target hostname/IP
16-
# env-prefix — space-separated VAR=value pairs prepended to the command
1714
#
1815
# run-local-script(rel-path, args...)
1916
# Run a script on the local machine.
20-
# rel-path — path relative to k3s-lab root, e.g. scripts/get-kubeconfig.sh
21-
# args — positional arguments forwarded to the script
17+
#
18+
# lima-run-script(rel-path)
19+
# Run a script inside a Lima VM (path relative to k3s-lab root).
20+
# Local: Lima mounts $HOME, so direct path access works.
21+
# Remote: curl the script from GitHub inside the VM.
2222
# ──────────────────────────────────────────────────────────────────────────────
2323

2424
ifdef K3S_LAB
@@ -40,6 +40,11 @@ SSH_KEY=$(SSH_KEY) SSH_PORT=$(SSH_PORT) \
4040
bash $(K3S_LAB)/$(1) $(2)
4141
endef
4242

43+
# Run a script path inside a Lima VM (Lima mounts $HOME by default).
44+
define lima-run-script
45+
bash '$(K3S_LAB)/$(1)'
46+
endef
47+
4348
else
4449

4550
# ── Remote mode: K3S_LAB is empty — fetch scripts via curl ───────────────────
@@ -58,4 +63,18 @@ SSH_KEY=$(SSH_KEY) SSH_PORT=$(SSH_PORT) \
5863
bash <(curl -fsSL $(K3S_LAB_RAW)/$(1)) $(2)
5964
endef
6065

66+
# Run a script inside a Lima VM by curling from GitHub.
67+
define lima-run-script
68+
bash <(curl -fsSL '$(K3S_LAB_RAW)/$(1)')
69+
endef
70+
71+
endif
72+
73+
# ── Lima test config path ─────────────────────────────────────────────────────
74+
# Local mode: use filesystem path. Remote mode: use raw GitHub URL.
75+
# Both limactl start and kubectl apply -f support URLs natively.
76+
ifdef K3S_LAB
77+
LIMA_TESTS_DIR := $(K3S_LAB)/tests/lima
78+
else
79+
LIMA_TESTS_DIR := $(K3S_LAB_RAW)/tests/lima
6180
endif

makefiles/50-deploy.mk

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Uses run-local-script from 00-lib.mk (local bash or remote curl, transparent).
55
# ──────────────────────────────────────────────────────────────────────────────
66

7-
.PHONY: deploy deploy-dashboard-secret deploy-monitoring deploy-grafana-secret deploy-logging
7+
.PHONY: deploy deploy-dashboard-secret deploy-monitoring deploy-grafana-secret
88

99
deploy: ## Deploy base stack (Traefik, cert-manager, ClusterIssuers)
1010
@echo "$(YELLOW)→ Deploying base stack on $(shell kubectl config current-context 2>/dev/null)...$(RESET)"
@@ -30,20 +30,16 @@ deploy-monitoring: ## Deploy observability stack (Prometheus + Grafana + Loki +
3030
-- grafana-cli admin reset-admin-password "$(GRAFANA_PASSWORD)"
3131
@echo "$(GREEN)✅ Observability stack deployed$(RESET)"
3232

33-
deploy-logging: ## Deploy centralized logs stack (Loki + Promtail + Grafana dashboard)
34-
@echo "$(YELLOW)→ Deploying centralized logging stack...$(RESET)"
35-
@$(call run-local-script,scripts/deploy-monitoring.sh)
36-
@echo "$(GREEN)✅ Centralized logging deployed$(RESET)"
37-
3833
deploy-grafana-secret: ## Create Grafana admin secret (requires GRAFANA_PASSWORD)
3934
@[ -n "$(GRAFANA_PASSWORD)" ] || (echo "$(RED)❌ GRAFANA_PASSWORD is not set$(RESET)"; exit 1)
4035
@kubectl --context $(KUBECONFIG_CONTEXT) cluster-info --request-timeout=5s >/dev/null 2>&1 || \
4136
(echo "$(RED)❌ Cannot reach cluster $(KUBECONFIG_CONTEXT) — is k3s running? Try: ssh kevin@<VPS> 'sudo systemctl restart k3s'$(RESET)"; exit 1)
4237
@echo "$(YELLOW)→ Creating monitoring namespace + Grafana admin secret...$(RESET)"
43-
@kubectl --context $(KUBECONFIG_CONTEXT) create namespace monitoring --dry-run=client -o yaml | kubectl --context $(KUBECONFIG_CONTEXT) apply --validate=false -f -
38+
@kubectl --context $(KUBECONFIG_CONTEXT) create namespace monitoring --dry-run=client -o yaml \
39+
| kubectl --context $(KUBECONFIG_CONTEXT) apply -f -
4440
@kubectl --context $(KUBECONFIG_CONTEXT) create secret generic grafana-admin-secret \
4541
--from-literal=username=admin \
4642
--from-literal=password="$(GRAFANA_PASSWORD)" \
4743
-n monitoring \
48-
--dry-run=client -o yaml | kubectl --context $(KUBECONFIG_CONTEXT) apply --validate=false -f -
44+
--dry-run=client -o yaml | kubectl --context $(KUBECONFIG_CONTEXT) apply -f -
4945
@echo "$(GREEN)✅ Grafana admin secret created$(RESET)"

makefiles/80-dev.mk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Module: makefiles/80-dev.mk
2+
# ──────────────────────────────────────────────────────────────────────────────
3+
# Developer workflow
4+
# Requires: brew install bats-core prek
5+
# ──────────────────────────────────────────────────────────────────────────────
6+
7+
.PHONY: test test-watch lint lint-install hooks-update
8+
9+
test: ## Run BATS unit tests (offline — no cluster needed)
10+
@bats tests/bats/
11+
12+
test-watch: ## Re-run BATS tests on every file change (requires: brew install entr)
13+
@find tests/bats -name '*.bats' -o -name '*.bash' | entr bats tests/bats/
14+
15+
lint: ## Run all linters (shellcheck + kubeconform + yaml) via prek
16+
@prek run --all-files
17+
@echo "$(GREEN)✅ All lint checks passed$(RESET)"
18+
19+
lint-install: ## Install prek git hooks (run once after cloning)
20+
@prek install
21+
@echo "$(GREEN)✅ prek hooks installed$(RESET)"
22+
23+
hooks-update: ## Update prek hook revisions to latest
24+
@prek autoupdate

makefiles/90-provision.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Module: makefiles/90-provision.mk
2+
# ──────────────────────────────────────────────────────────────────────────────
3+
# Full provisioning workflow
4+
# ──────────────────────────────────────────────────────────────────────────────
5+
6+
.PHONY: provision
7+
8+
provision: setup-all k3s-master k3s-worker kubeconfig deploy deploy-dashboard-secret deploy-grafana-secret deploy-monitoring ## Full provision: setup VPS → k3s → kubeconfig → deploy stack → secrets → monitoring
9+
@echo ""
10+
@echo "$(GREEN)🎉 Cluster ready!$(RESET)"
11+
@echo " kubectl config use-context $(KUBECONFIG_CONTEXT)"
12+
@echo " make nodes"

0 commit comments

Comments
 (0)