This guide is intended for developers who want to contribute to K8sMed. It provides detailed information about the project structure, development workflow, and technical architecture.
# Fork on GitHub first, then clone your fork
git clone https://github.com/YOUR-USERNAME/k8smed.git
cd k8smed
# Add the upstream repository
git remote add upstream https://github.com/k8smed/k8smed.git
# Fetch Go dependencies
go mod download
# Install development tools
make tools
# Build binary
make build
# Install the kubectl plugin locally for testing
make install
kubectl k8smed version
K8sMed is organized into the following directories:
.
├── api/ # API definitions and Custom Resource Definitions
├── cmd/ # Command-line interfaces
│ └── kubectl-k8smed/ # The kubectl plugin entry point
├── deploy/ # Deployment manifests and charts
├── docs/ # Documentation
├── examples/ # Example configurations and use cases
├── hack/ # Scripts for development, CI/CD, etc.
├── internal/ # Internal packages not meant for external use
├── pkg/ # Public packages that can be imported by other projects
│ ├── ai/ # AI provider integrations
│ ├── analyzer/ # Resource analyzers
│ ├── collector/ # Kubernetes resource collectors
│ └── config/ # Configuration management
└── tests/ # Integration and end-to-end tests
K8sMed follows a modular architecture with these key components:
The collector component is responsible for gathering information about Kubernetes resources. Its main interfaces are defined in pkg/collector/collector.go.
Key concepts:
ResourceCollector: Interface for collecting resources from a Kubernetes clusterResourceData: Struct containing resource information, status, manifest, events, and logsResourceInfo: Basic metadata about a resource (kind, name, namespace)Analyzers examine collected resources for potential issues. The analyzer framework is in pkg/analyzer/analyzer.go.
Key concepts:
Analyzer: Interface that all analyzers must implementAnalysisContext: Shared context for analyzers with resources and resultsAnalysisDetail: Analysis results with problem details and remediation stepsThe AI component connects to different LLM providers to process analysis results. Its interfaces are in pkg/ai/llm/client.go.
Key concepts:
Client: Interface for communicating with LLM providersRequest: Struct representing a prompt to the LLMResponse: Struct containing the LLM’s responseThe kubectl plugin interface is defined in cmd/kubectl-k8smed/main.go.
git checkout -b feature/your-feature-name
Implement your feature or bug fix.
Add tests for your changes in the appropriate package’s _test.go files.
make test
make lint
git add .
git commit -m "Add feature: your feature description"
git push origin feature/your-feature-name
Open a pull request against the main repository’s main branch.
K8sMed uses Go’s standard testing package for unit tests and integration tests.
# Run all tests
make test
# Run specific tests
go test ./pkg/analyzer/...
# Run tests with verbose output
go test -v ./...
# Run integration tests
make integration-test
_test.go suffixtests/ directoryK8sMed follows standard Go coding conventions:
gofmt to format your codeAnalyzers are the core of K8sMed’s functionality. To create a new analyzer:
pkg/analyzer/ for your resource typeAnalyzer interface:type YourResourceAnalyzer struct{}
func (a *YourResourceAnalyzer) Analyze(ctx context.Context, analysisCtx *AnalysisContext) error {
// Your analyzer implementation
return nil
}
func (a *YourResourceAnalyzer) Name() string {
return "YourResourceAnalyzer"
}
func (a *YourResourceAnalyzer) SupportedKinds() []string {
return []string{"YourResource"}
}
pkg/analyzer/registry.goTo add a new AI provider:
pkg/ai/llm/ for your providerClient interfacepkg/ai/llm/factory.go# Run with verbose logging
kubectl k8smed analyze pod my-pod --debug
# Inspect collected resources
kubectl k8smed collect pod my-pod --output json > resources.json
# Test AI prompt without analyzing
kubectl k8smed prompt "Your prompt here" --dry-run
Update the version in pkg/version/version.go.
Document all changes since the last release.
git tag -a v0.1.0 -m "Release v0.1.0"
git push origin v0.1.0
Create a new release on GitHub with the changelog content.
make release
Thank you for contributing to K8sMed! If you have questions or need help, please open an issue on GitHub or contact the maintainers directly.