Skip to content

Commit 50e5062

Browse files
committed
improved docs
1 parent bb89b69 commit 50e5062

6 files changed

Lines changed: 345 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ go.work
2323
kalco-dump-*/
2424
kalco-dump-*
2525
guestbook-exports/
26-
26+
demos/
2727

2828
# IDE files
2929
.vscode/

demos/gitops-validation/helm/.github/workflows/validation.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
- name: Checkout Source Code
1717
uses: actions/checkout@v3
1818

19-
# Install Tools
19+
- name: Install Tools
2020
run: |
2121
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
2222
# Install Kalco
23-
curl -sL https://github.com/graz-dev/kalco/releases/download/v0.1.21/kalco_Linux_x86_64.tar.gz | tar xz
23+
curl -sL https://github.com/graz-dev/kalco/releases/latest/download/kalco_Linux_x86_64.tar.gz | tar xz
2424
sudo mv kalco /usr/local/bin/
2525
2626
- name: Configure Kalco

docs/commands/diff.md

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,29 @@ kalco diff [flags]
3333
| `--snapshot-dir` | Root directory of snapshot repository | - | Yes |
3434
| `--refresh` | Fetch live resource from K8s via export | `false` | No |
3535
| `--format` | Output format (`text`, `markdown`) | `text` | No |
36+
| `--namespace` | Override namespace for local resources | - | No |
37+
| `--ignore-base` | Path to base manifest (from destination branch) for Smart Drift Detection | - | No |
38+
| `--ignore-extra-fields` | Ignore K8s default fields missing from local manifest | `false` | No |
3639

37-
## Usage Examples
40+
## Advanced Features
3841

39-
### Basic Diff
42+
### Smart Drift Detection (`--ignore-base`)
4043

41-
Compare a local deployment file against the existing snapshot:
44+
When validating a Pull Request, you often have changes that are *intentional*.
45+
- **Snapshot**: Old State
46+
- **Base Branch**: Current State
47+
- **PR Branch**: New State
4248

43-
```bash
44-
kalco diff \
45-
--target ./charts/my-app/deployment.yaml \
46-
--snapshot-dir ./cluster-exports
47-
```
48-
49-
### Diff with Live Refresh
49+
If you just diff **PR vs Snapshot**, you see *all* differences.
50+
By providing `--ignore-base <path-to-file-in-base-branch>`, Kalco calculates:
51+
`(Base -> PR)` changes are **INTENTIONAL**.
52+
It then masks these changes when comparing **(PR vs Snapshot)**.
53+
Result: You *only* see drift (unexpected changes), not your PR changes.
5054

51-
Update the snapshot from the cluster (via export) before performing the diff. This ensures you are comparing against the latest live state.
52-
53-
```bash
54-
kalco diff \
55-
--target ./charts/my-app/deployment.yaml \
56-
--snapshot-dir ./cluster-exports \
57-
--refresh
58-
```
59-
60-
### Markdown Output
61-
62-
Generate a Markdown-formatted diff, useful for automated CI/CD pipelines (e.g., GitHub Actions PR comments):
63-
64-
```bash
65-
kalco diff \
66-
--target ./charts/my-app/deployment.yaml \
67-
--snapshot-dir ./cluster-exports \
68-
--format markdown
69-
```
55+
### Ignore Defaults (`--ignore-extra-fields`)
56+
Kubernetes often adds default fields (e.g., `dnsPolicy`, `strategy`, `revisionHistoryLimit`).
57+
If your local manifest doesn't specify them, a strict diff shows them as specific values on the cluster vs missing locally.
58+
Use `--ignore-extra-fields` to ensure Kalco only validates fields *you explicitly defined*.
7059

7160
## Output Explained
7261

docs/commands/validate.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
layout: default
3+
title: kalco validate
4+
nav_order: 4
5+
parent: Commands Reference
6+
---
7+
8+
# Validate Command
9+
10+
The `kalco validate` command is a high-level wrapper designed specifically for **CI/CD Pipelines**. It automates the entire drift detection workflow for Pulse/Merge Requests.
11+
12+
## Overview
13+
14+
Unlike `kalco diff`, which compares a single file, `kalco validate`:
15+
1. **Auto-Detects Changes**: Finds which manifests changed between your current branch and the base branch (e.g., `origin/master`).
16+
2. **Fetches Base Content**: Automatically retrieves the "before" state of files from git to enable [Smart Drift Detection]({{ site.baseurl }}/commands/diff#smart-drift-detection---ignore-base).
17+
3. **Generates Report**: Produces a consolidated Markdown report of all validations.
18+
4. **Ignores Defaults**: Automatically enables `--ignore-extra-fields` to reduce noise.
19+
20+
## Syntax
21+
22+
```bash
23+
kalco validate [flags]
24+
```
25+
26+
## Flags
27+
28+
| Flag | Description | Default | Required |
29+
|------|-------------|---------|----------|
30+
| `--base` | Base branch/ref to compare against | `origin/master` | No |
31+
| `--snapshot-dir` | Directory containing snapshots | - | Yes |
32+
| `--dirs` | Directories to scan for changes | `.` | No |
33+
| `--namespace` | Override namespace for resources | - | No |
34+
| `--report-file` | File path to write Markdown report to | - | No |
35+
36+
## Usage Examples
37+
38+
### Basic CI Integration (GitHub Actions)
39+
40+
In a GitHub Action workflow, use `kalco validate` to check changed manifests:
41+
42+
```bash
43+
kalco validate \
44+
--base origin/${{ github.base_ref }} \
45+
--dirs manifests \
46+
--snapshot-dir tmp-snapshot \
47+
--report-file report.md
48+
```
49+
50+
This single command replaces complex bash scripting loops.
51+
52+
### Local Validation
53+
54+
You can also run it locally to verify your changes before pushing:
55+
56+
```bash
57+
# Validate changes in 'charts/' against 'main'
58+
kalco validate \
59+
--base origin/main \
60+
--dirs charts \
61+
--snapshot-dir ./cluster-backup
62+
```
63+
64+
## How it works (Under the hood)
65+
66+
1. **Git Diff**: Runs `git diff --name-only <base> -- <dirs>` to find changed YAML files.
67+
2. **Loop**: Iterates through each file.
68+
3. **Load Base**: Runs `git show <base>:<file>` to get the original content.
69+
4. **Kalco Diff**: Runs `kalco diff` using the local file, the fetched base content (as `--ignore-base`), and the snapshot.
70+
5. **Report**: Aggregates the results into a single output.
71+
72+
If **Drift** is detected (changes that are *not* in your PR intent), the command exits with code 1.

docs/index.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ nav_order: 1
88

99
Welcome to the official documentation for **Kalco** (Kubernetes Analysis & Lifecycle Control).
1010

11-
Kalco is the CLI tool that bridges the gap between your Git configuration and your actual Kubernetes cluster state.
11+
Kalco is a powerful CLI tool designed to bridge the gap between your Git configuration (Intent) and your running Kubernetes cluster (Reality). It provides a robust workflow for **Snapshotting**, **Diffing**, and **Validating** cluster state.
1212

1313
## 🌟 Why Kalco?
1414

15-
- **Backup & Audit**: Snapshot your entire cluster to Git-friendly YAML.
16-
- **GitOps Validation**: Detect "drift" between what you *think* is deployed (Git) and what *is* deployed (Cluster).
17-
- **Environment Management**: Switch context configurations easily between Prod, Staging, and Dev.
15+
In complex Kubernetes environments, "Drift" is inevitable. Someone patches a deployment manually, a controller adds default fields, or a Helm chart renders differently than expected. Kalco solves this by:
16+
17+
- **📸 Snapshotting**: Exporting your entire cluster state into clean, Git-friendly YAML files.
18+
- **🔍 Diffing**: performing "Smart Diffs" that ignore noise (like timestamps, `managedFields`, and dynamic status) to show only *real* changes.
19+
- **🛡️ Validating**: Integrating into CI/CD pipelines to prevent drift *before* it merges.
20+
21+
## 🏗️ How It Works
22+
23+
Kalco operates on a simple but powerful loop:
24+
25+
1. **Export**: `kalco export` connects to your cluster and downloads resources, stripping away runtime noise to create a "Golden Snapshot".
26+
2. **Compare**: `kalco diff` compares your local manifests (or Helm charts) against this snapshot.
27+
3. **Validate**: `kalco validate` automates this process in CI, fetching the base branch, detecting changed files, and verifying that your PR matches the cluster state (or intended changes).
1828

1929
## 🚀 Getting Started
2030

@@ -36,18 +46,22 @@ curl -fsSL https://raw.githubusercontent.com/graz-dev/kalco/master/scripts/insta
3646
2. **[Export Resources]({{ site.baseurl }}/commands/export)**: Take your first snapshot.
3747
3. **[Verify Drift]({{ site.baseurl }}/commands/diff)**: Compare your local manifests against the snapshot.
3848

39-
## 📚 Command Reference
49+
## 📚 Documentation Sections
4050

41-
| Command | Purpose |
42-
|---------|---------|
43-
| **[context]({{ site.baseurl }}/commands/context)** | Manage cluster connections and output settings. |
44-
| **[export]({{ site.baseurl }}/commands/export)** | Dump cluster state to local files. |
45-
| **[diff]({{ site.baseurl }}/commands/diff)** | **[NEW]** Compare local YAML vs Snapshot/Live state. |
46-
| **version** | Check version information. |
51+
### Command Reference
52+
Deep dive into every command and flag.
53+
54+
- **[context]({{ site.baseurl }}/commands/context)**: Manage cluster connections.
55+
- **[export]({{ site.baseurl }}/commands/export)**: Snapshot cluster state.
56+
- **[diff]({{ site.baseurl }}/commands/diff)**: Compare local files vs cluster.
57+
- **[validate]({{ site.baseurl }}/commands/validate)**: **[NEW]** Automated CI/CD drift detection.
58+
59+
### Tutorials & Use Cases
60+
Real-world examples of Kalco in action.
61+
62+
- **[GitOps Validation Pipeline]({{ site.baseurl }}/tutorials/gitops-validation)**: A complete walkthrough of setting up a Drift Detection Pipeline for raw manifests using GitHub Actions and ArgoCD.
4763

4864
## 🤝 Support & Contributing
4965

5066
- **Issues**: [GitHub Issues](https://github.com/graz-dev/kalco/issues)
5167
- **Repo**: [github.com/graz-dev/kalco](https://github.com/graz-dev/kalco)
52-
53-
Is something missing in these docs? [Edit this page on GitHub](https://github.com/graz-dev/kalco/edit/master/docs/index.md).

0 commit comments

Comments
 (0)