Contributing to Stratos
Thank you for your interest in contributing to Stratos! This guide covers how to get started with development.
Getting Started
Prerequisites
- Go 1.21 or later
- Docker (for building images)
- kubectl configured with a Kubernetes cluster
- make
Clone the Repository
git clone https://github.com/stratos-sh/stratos.git
cd stratos
Build
# Build the binary
make build
# Build the container image
make docker-build
Run Tests
# Unit tests
make test
# Integration tests (requires envtest)
make test-integration
# Generate coverage report
make coverage
Development Workflow
1. Fork and Branch
- Fork the repository on GitHub
- Create a feature branch:
git checkout -b feature/my-feature
2. Make Changes
Follow the coding guidelines below when making changes.
3. Run Quality Checks
# Format code
make fmt
# Run linter
make lint
# Run vet
make vet
# Run all tests
make test
4. Regenerate Code (if needed)
If you modify CRD types in api/v1alpha1/:
# Regenerate deepcopy methods
make generate
# Regenerate CRD and RBAC manifests
make manifests
5. Submit a Pull Request
- Push your branch to your fork
- Open a pull request against
main - Fill out the PR template
- Wait for CI checks to pass
Code Organization
cmd/stratos/main.go # Entry point
api/v1alpha1/ # CRD types (kubebuilder markers)
internal/
├── controller/ # Kubernetes reconcilers
├── cloudprovider/ # Cloud abstraction layer
└── metrics/ # Prometheus metrics
config/
├── crd/ # Generated CRD manifests
├── rbac/ # Generated RBAC manifests
└── samples/ # Example NodePool resources
tests/
└── integration/ # Integration tests
Coding Guidelines
Go Style
- Follow Effective Go
- Follow Go Code Review Comments
- Use
gofmtandgoimportsfor formatting
Error Handling
- Always handle errors explicitly
- Use wrapped errors with context:
return fmt.Errorf("failed to start instance %s: %w", instanceID, err) - Define sentinel errors for expected conditions:
var ErrInstanceNotFound = errors.New("instance not found")
Logging
- Use structured logging with key-value pairs:
log.Info("scaling up", "pool", poolName, "count", count) - Log at appropriate levels:
Error: Unexpected failuresInfo: Significant operationsDebug: Detailed debugging information
Testing
- Write unit tests for all exported functions
- Use table-driven tests where appropriate
- Mock external dependencies (cloud providers, Kubernetes API)
Comments
- Document exported types and functions
- Explain why, not what the code does
- Keep comments up to date with code changes
Pull Request Guidelines
PR Title
Use conventional commit format:
feat: Add support for GCP instancesfix: Handle rate limit errors in AWS providerdocs: Update installation guiderefactor: Simplify scale calculator logictest: Add integration tests for scale-down
PR Description
Include:
- What: Brief description of changes
- Why: Motivation for the changes
- How: Implementation approach
- Testing: How you tested the changes
Review Process
- All PRs require at least one approval
- CI checks must pass
- Address review feedback promptly
- Squash commits before merge (or use squash merge)
Adding a New Cloud Provider
To add support for a new cloud provider:
-
Implement the interface:
// internal/cloudprovider/newprovider/provider.go
type Provider struct {
// ...
}
func (p *Provider) LaunchInstance(ctx context.Context, cfg *cloudprovider.LaunchConfig) (*cloudprovider.Instance, error) {
// Implementation
}
// ... implement all interface methods -
Register in the factory:
// internal/cloudprovider/factory.go
func NewProvider(name string) (cloudprovider.CloudProvider, error) {
switch name {
case "aws":
return aws.NewProvider()
case "newprovider":
return newprovider.NewProvider()
// ...
}
} -
Add CRD types:
// api/v1alpha1/cloudprovider_types.go
type NewProviderConfig struct {
// Configuration fields
} -
Add documentation:
- Update
docs/concepts/cloud-providers.md - Add setup guide in
docs/guides/
- Update
-
Add tests:
- Unit tests for provider methods
- Integration tests with fake/mock services
Reporting Issues
Bug Reports
Include:
- Stratos version
- Kubernetes version
- Cloud provider and region
- Steps to reproduce
- Expected vs actual behavior
- Controller logs (if applicable)
Feature Requests
Include:
- Use case description
- Proposed solution
- Alternatives considered
- Potential impact on existing features
Code of Conduct
Be respectful and constructive in all interactions. We are committed to providing a welcoming and inclusive environment for all contributors.
License
By contributing to Stratos, you agree that your contributions will be licensed under the Apache License 2.0.
Next Steps
- Local Development - Running Stratos locally
- Testing - Testing patterns and practices