Skip to content

Commit a6bbfff

Browse files
committed
*fixed readme and docs
1 parent 0c6304a commit a6bbfff

35 files changed

Lines changed: 27640 additions & 159 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ go.work
2222
# Output directories
2323
kalco-dump-*/
2424
kalco-dump-*
25+
guestbook-exports/
2526

2627
# IDE files
2728
.vscode/

README.md

Lines changed: 20 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,130 +6,54 @@
66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
77
[![Documentation](https://img.shields.io/badge/docs-available-brightgreen)](https://graz-dev.github.io/kalco)
88

9-
*Extract, analyze, and version control your entire Kubernetes cluster with Git integration*
9+
*Extract, analyze, and version control your entire Kubernetes cluster with Git integration.*
1010

11-
[Quick Start](#quick-start)[Documentation](https://graz-dev.github.io/kalco)[Examples](#examples)[Contributing](#contributing)
11+
## 🚀 Overview
1212

13-
---
13+
Kalco acts as a bridge between your Kubernetes cluster **Reality** and your GitOps **Intention**. It allows you to:
14+
- **Snapshot** your cluster state into organized YAML (Deployment, Service, CRDs...).
15+
- **Detect Drift** between Git manifests (Helm/Kustomize/Raw) and the live cluster.
16+
- **Audit** changes over time with automated Git commits.
1417

15-
## Overview
18+
## 📚 Documentation
1619

17-
Kalco is a CLI tool designed for comprehensive Kubernetes cluster analysis, resource extraction, and lifecycle management. Kalco provides automated cluster backup and change tracking capabilities through a clean interface.
20+
Full documentation is available at [**graz-dev.github.io/kalco**](https://graz-dev.github.io/kalco).
1821

19-
## Core Features
20-
21-
### Context Management
22-
Manage multiple Kubernetes clusters through a unified interface:
23-
24-
- **Multi-Cluster Support** - Handle dev, staging, and production environments
25-
- **Configuration Persistence** - Store cluster settings and output directories
26-
- **Team Collaboration** - Share and import context configurations
27-
- **Environment Isolation** - Separate configurations for different clusters
28-
29-
### Resource Export
30-
Export cluster resources with professional organization:
31-
32-
- **Structured Output** - Intuitive directory organization by namespace and resource type
33-
- **Complete Coverage** - Native Kubernetes resources and Custom Resource Definitions (CRDs)
34-
- **Clean YAML** - Metadata optimization for re-application
35-
- **Context-Based Configuration** - Output directory automatically derived from active context
36-
37-
### Git Integration
38-
Automatic version control for cluster changes:
39-
40-
- **Repository Initialization** - Automatic Git setup for new export directories
41-
- **Change Tracking** - Commit history with timestamp-based or custom messages
42-
- **Remote Push** - Optional automatic push to remote repositories
43-
- **Branch Management** - Support for main/master branch conventions
44-
45-
### Report Generation
46-
Professional change analysis reports:
47-
48-
- **Change Tracking** - Detailed analysis of resource modifications
49-
- **Git Integration** - Complete commit history and diff information
50-
- **Professional Formatting** - Clean Markdown reports with actionable insights
51-
52-
## Quick Start
22+
## ⚡ Quick Start
5323

5424
### Installation
5525

56-
**Package Managers (recommended):**
26+
**Homebrew (macOS/Linux)**
5727
```bash
58-
# Homebrew
5928
brew install graz-dev/tap/kalco
60-
61-
# Build from source
62-
git clone https://github.com/graz-dev/kalco.git
63-
cd kalco && go build -o kalco
6429
```
6530

66-
**Linux/macOS:**
31+
**Install Script**
6732
```bash
6833
curl -fsSL https://raw.githubusercontent.com/graz-dev/kalco/master/scripts/install.sh | bash
6934
```
7035

71-
**Windows (PowerShell):**
72-
```powershell
73-
iwr -useb https://raw.githubusercontent.com/graz-dev/kalco/master/scripts/install.ps1 | iex
74-
```
75-
7636
### Basic Usage
7737

78-
1. **Create a Context:**
38+
1. **Setup Context**:
7939
```bash
80-
kalco context set production \
81-
--kubeconfig ~/.kube/prod-config \
82-
--output ./prod-exports \
83-
--description "Production cluster for customer workloads"
40+
kalco context set prod --output ./prod-backup
8441
```
8542

86-
2. **Export Cluster Resources:**
43+
2. **Snapshot Cluster**:
8744
```bash
88-
kalco export --git-push --commit-message "Weekly backup"
45+
kalco export --git-push
8946
```
9047

91-
3. **Load Existing Context:**
48+
3. **Verify GitOps Drift** (New!):
9249
```bash
93-
kalco context load ./existing-kalco-export
50+
kalco diff --target ./my-app/deploy.yaml --snapshot-dir ./prod-backup --refresh
9451
```
9552

96-
## Command Reference
53+
## 🤝 Contributing
9754

98-
### Core Commands
55+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
9956

100-
| Command | Description | Usage |
101-
|---------|-------------|-------|
102-
| `kalco context` | Manage cluster contexts | `kalco context set/list/use/load` |
103-
| `kalco export` | Export cluster resources | `kalco export [flags]` |
104-
| `kalco completion` | Shell completion | `kalco completion bash\|zsh\|fish\|powershell` |
105-
| `kalco version` | Version information | `kalco version` |
106-
107-
Read the [docs](https://graz-dev.github.io/kalco) for more details.
108-
109-
## Contributing
110-
111-
We welcome contributions to improve Kalco:
112-
113-
- **Bug Reports**: [Create an issue](https://github.com/graz-dev/kalco/issues/new)
114-
- **Feature Requests**: [Create an issue](https://github.com/graz-dev/kalco/issues/new)
115-
- **Code Contributions**: Fork, develop, and submit pull requests
116-
- **Documentation**: Help improve guides and examples
117-
118-
## License
57+
## 📄 License
11958

12059
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
121-
122-
## Support
123-
124-
- **Documentation**: [https://graz-dev.github.io/kalco](https://graz-dev.github.io/kalco)
125-
- **Issues**: [GitHub Issues](https://github.com/graz-dev/kalco/issues)
126-
127-
---
128-
129-
<div align="center">
130-
131-
**Built with ❤️ for the Kubernetes community**
132-
133-
[Star us on GitHub](https://github.com/graz-dev/kalco)[Read the Docs](https://graz-dev.github.io/kalco)
134-
135-
</div>

cmd/diff.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
7+
"kalco/pkg/diff"
8+
"kalco/pkg/dumper"
9+
"kalco/pkg/kube"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var (
15+
diffTarget string
16+
diffSnapshotDir string
17+
diffRefresh bool
18+
diffFormat string
19+
)
20+
21+
var diffCmd = &cobra.Command{
22+
Use: "diff",
23+
Short: "Compare local manifest with snapshot or live cluster state",
24+
RunE: func(cmd *cobra.Command, args []string) error {
25+
return runDiff()
26+
},
27+
}
28+
29+
func init() {
30+
rootCmd.AddCommand(diffCmd)
31+
32+
diffCmd.Flags().StringVar(&diffTarget, "target", "", "Path to local manifest file")
33+
diffCmd.Flags().StringVar(&diffSnapshotDir, "snapshot-dir", "", "Root directory of snapshot repository")
34+
diffCmd.Flags().BoolVar(&diffRefresh, "refresh", false, "Fetch live resource from K8s instead of snapshot")
35+
diffCmd.Flags().StringVar(&diffFormat, "format", "text", "Output format (text|markdown)")
36+
37+
diffCmd.MarkFlagRequired("target")
38+
diffCmd.MarkFlagRequired("snapshot-dir")
39+
}
40+
41+
func runDiff() error {
42+
// 1. Refresh/Export if requested
43+
if diffRefresh {
44+
printInfo("Refreshing snapshot via export...")
45+
requireActiveContext()
46+
activeContext, err := getActiveContext()
47+
if err != nil {
48+
return err
49+
}
50+
51+
clientset, discoveryClient, dynamicClient, err := kube.NewClients(activeContext.KubeConfig)
52+
if err != nil {
53+
return fmt.Errorf("failed to create K8s clients: %w", err)
54+
}
55+
56+
d := dumper.NewDumper(clientset, discoveryClient)
57+
d.SetDynamicClient(dynamicClient)
58+
59+
// Use diffSnapshotDir as the output for this "refresh" export
60+
// The user specified this dir, so we update it.
61+
// Note: This exports ALL resources.
62+
if err := d.DumpAllResources(diffSnapshotDir); err != nil {
63+
return fmt.Errorf("failed to refresh snapshot: %w", err)
64+
}
65+
printSuccess("Snapshot refreshed")
66+
}
67+
68+
// 2. Initialize Differ
69+
differ := diff.NewDiffer()
70+
71+
// 3. Load local resource
72+
localResource, err := differ.LoadLocalResource(diffTarget)
73+
if err != nil {
74+
return fmt.Errorf("failed to load target file: %w", err)
75+
}
76+
77+
// 4. Get comparison resource (Snapshot)
78+
// We always compare against snapshot (which might have been just refreshed)
79+
remoteResource, err := differ.LoadSnapshotResource(diffSnapshotDir, localResource.Object)
80+
if err != nil {
81+
return fmt.Errorf("failed to load snapshot: %w", err)
82+
}
83+
84+
// 5. Perform Diff
85+
result, err := differ.Diff(localResource, remoteResource)
86+
if err != nil {
87+
return fmt.Errorf("diff failed: %w", err)
88+
}
89+
90+
// 6. Print Result
91+
diff.PrintDiff(result, diffFormat)
92+
93+
return nil
94+
}

cmd/export.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
var (
1616
exportGitPush bool
1717
exportCommitMessage string
18+
exportReport string
1819
exportDryRun bool
1920
)
2021

@@ -126,12 +127,14 @@ func runExport() error {
126127
}
127128

128129
// Generate change report
129-
printSeparator()
130-
reportGen := reports.NewReportGenerator(outputDir)
131-
if err := reportGen.GenerateReport(commitMsg); err != nil {
132-
printWarning(fmt.Sprintf("Report generation failed: %v", err))
133-
} else {
134-
printSuccess("Analysis report generated")
130+
if exportReport == "on" || exportReport == "true" {
131+
printSeparator()
132+
reportGen := reports.NewReportGenerator(outputDir)
133+
if err := reportGen.GenerateReport(commitMsg); err != nil {
134+
printWarning(fmt.Sprintf("Report generation failed: %v", err))
135+
} else {
136+
printSuccess("Analysis report generated")
137+
}
135138
}
136139

137140
// Success summary
@@ -146,6 +149,7 @@ func init() {
146149
// Add flags
147150
exportCmd.Flags().BoolVar(&exportGitPush, "git-push", false, "automatically push changes to remote origin")
148151
exportCmd.Flags().StringVarP(&exportCommitMessage, "commit-message", "m", "", "custom Git commit message")
152+
exportCmd.Flags().StringVar(&exportReport, "report", "on", "enable/disable analysis report (on/off)")
149153
exportCmd.Flags().BoolVar(&exportDryRun, "dry-run", false, "show what would be exported without writing files")
150154

151155
// Add aliases

0 commit comments

Comments
 (0)