Table of Contents
- Terms
- Certificate of Origin
- DCO Sign Off
- Code of Conduct
- Development Environment Setup
- Development Workflow
- Code Style and Best Practices
- Testing Requirements
- Code Coverage Requirements
- API and CRD Changes
- Enhancement Proposals
- Documentation Requirements
- Pull Request Guidelines
- Contributing a patch
- Issue and pull request management
All contributions to the repository must be submitted under the terms of the Apache Public License 2.0.
By contributing to this project, you agree to the Developer Certificate of Origin (DCO). This document was created by the Linux Kernel community and is a simple statement that you, as a contributor, have the legal right to make the contribution. See the DCO file for details.
You must sign off your commit to state that you certify the DCO. To certify your commit for DCO, add a line like the following at the end of your commit message:
Signed-off-by: John Smith <john@example.com>
This can be done with the --signoff option to git commit. See the Git documentation for details.
The Open Cluster Management project has adopted the CNCF Code of Conduct. Refer to the Community Code of Conduct for details.
- Go 1.21 or later
- Docker or Podman for building container images
- kubectl for Kubernetes cluster interaction
- Make
-
Clone the repository:
git clone https://github.com/stolostron/siteconfig.git cd siteconfig -
Install dependencies:
make common-deps-update
-
Build the project:
make build
Before submitting any code changes, ensure your development environment is properly set up and all CI checks pass locally.
Before submitting a pull request, you must run the CI validation suite locally to ensure there are no linter errors and all unit tests pass:
make ci-jobThe ci-job target runs the following checks:
- Dependency updates: Updates and tidies Go modules
- Code generation: Generates DeepCopy methods and mock implementations
- Formatting: Runs
go fmtto format the code - Vetting: Runs
go vetto detect suspicious constructs - Linting: Runs
golangci-lintto catch common code issues - Unit tests: Executes all unit tests
- Shell script validation: Runs shellcheck and bashate on shell scripts
- Bundle validation: Checks that operator bundle manifests are up-to-date
All checks must pass before your code can be merged.
You can also run individual targets during development:
make fmt- Format codemake vet- Run go vetmake golangci-lint- Run lintermake unittest- Run unit testsmake test-coverage- Generate coverage reportmake generate- Generate codemake manifests- Generate CRDs and RBAC manifests
This project follows standard Go coding conventions and best practices:
- Follow Effective Go guidelines
- Use
gofmtfor code formatting (automatically applied bymake fmt) - Follow the Uber Go Style Guide for additional best practices
- Keep functions focused and concise
- Use meaningful variable and function names
- Add comments for exported functions, types, and complex logic
As this is a Kubernetes operator project, follow these additional guidelines:
- Controller Logic: Keep reconciliation logic idempotent and handle edge cases
- Status Updates: Always update resource status with meaningful conditions
- Error Handling: Return errors appropriately to trigger reconciliation with backoff
- Finalizers: Use finalizers for cleanup logic when resources are deleted
- Watches: Be mindful of what resources your controller watches to avoid unnecessary reconciliations
- Logging: Use structured logging with appropriate log levels (Info, Error, Debug)
- Place API types in
api/v1alpha1/ - Place controller logic in
internal/controller/ - Keep utility functions in separate packages with clear responsibilities
- Use interfaces to enable testing and mocking
Write clear, descriptive commit messages:
Short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 72
characters. The blank line separating the summary from the body is
critical.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Signed-off-by: Your Name <your.email@example.com>
All code changes must include appropriate unit tests. When adding new functionality or fixing bugs:
- Write unit tests that cover the new code paths
- Ensure existing tests still pass
- Run tests locally before submitting:
make unittest
- Place unit tests in
*_test.gofiles alongside the code they test - Use table-driven tests where appropriate for better test coverage
- Mock external dependencies using the mock framework (see
internal/controller/mocks/)
All new functionality must meet the following code coverage requirements:
- Minimum: 70% code coverage for newly added code
- Target: 90% code coverage (strongly encouraged)
To generate and view a coverage report:
make test-coverage
go tool cover -html=test-coverage.outThe coverage report will help identify untested code paths. Reviewers will check coverage as part of the pull request review process.
- Focus on testing business logic and error handling paths
- Mock external dependencies to enable thorough testing
- Document any intentionally untested code with a clear justification
Changes to the ClusterInstance API or Custom Resource Definitions (CRDs) require special attention:
When modifying types in api/v1alpha1/:
-
Backward Compatibility: Ensure changes are backward compatible when possible
- Use optional fields (pointers) for new additions
- Avoid removing or renaming existing fields
- Use deprecation notices for fields being phased out
-
Validation: Add appropriate validation tags and webhook validation
- Use kubebuilder markers for OpenAPI validation
- Implement webhook validation for complex rules
-
Documentation: Add
// +kubebuilder:markers and comments- Document field purpose and expected values
- Include examples in comments
-
Generation: After API changes, regenerate manifests and code:
make generate make manifests make bundle
- Update sample CRs in
config/samples/to reflect API changes - Ensure samples are valid and demonstrate new functionality
- Test samples against the updated operator
Breaking API changes must be:
- Documented in the pull request with migration guide
- Backed by a JIRA issue with architecture/design review
- Discussed with maintainers before implementation
- Include deprecation warnings in the previous version when possible
Significant changes to the siteconfig project require an enhancement proposal before implementation begins. This includes:
- New features or significant behavioral changes
- Changes to the ClusterInstance API or CRDs
- Architectural decisions affecting controllers, templates, or the rendering pipeline
Enhancement proposals are Markdown documents that describe the motivation, design, and impact of a change. They are reviewed and approved through the normal PR process.
For the full process, template, and lifecycle details, see the Enhancement Proposals guide.
Enhancement proposals must be merged before implementation PRs are submitted.
Proper documentation is essential for maintainability and user adoption:
- Add godoc comments for all exported types, functions, and constants
- Document complex algorithms or business logic with inline comments
- Include examples in function documentation when helpful
When adding new features or changing behavior, update relevant documentation in the docs/ directory:
- Configuration Guide (
docs/configure_siteconfig.md): Document new configuration options - Troubleshooting (
docs/troubleshooting.md): Add common issues and solutions - Architecture Docs: Explain significant design decisions
- Update example manifests in
config/samples/andexamples/ - Ensure examples are complete and can be used directly by users
- Add comments to explain non-obvious configurations
Update the main README.md if your changes affect:
- Installation instructions
- Quick start guide
- Requirements or dependencies
For complex configuration or CRD fields, add:
- Field descriptions in struct tags
- Usage examples in comments
- Links to related documentation
When you create a pull request, GitHub will automatically populate a template to help you provide all necessary information. Please fill out all applicable sections of the template.
- All pull requests must be opened against the
mainbranch - Create a feature branch from the latest
mainfor your changes
Pull request titles must follow this format:
JIRA-12345: Brief description of the change
or, if there is no associated JIRA issue:
NO-ISSUE: Brief description of the change
Examples:
JIRA-12345: Add contributing guidelineJIRA-67890: Fix validation error for multi-node clustersNO-ISSUE: Update README with new examples
- Breaking changes or significant functionality changes must be backed by an official JIRA issue
- Minor changes (documentation, typos, minor up-versioning) can use
NO-ISSUE - Reference the JIRA issue in your pull request description
If you used Artificial Intelligence (AI) tools (e.g., Claude, Gemini, GPT-4, GitHub Copilot) to generate, co-develop, or assist with your code changes, you must disclose this information in your pull request using the AI Assistance section in the pull request template.
Important Requirements:
- All AI-generated code must be thoroughly reviewed and understood by the contributor
- Contributors remain fully responsible for ensuring AI-generated code meets all project standards
- AI-generated code must pass all tests, linting, and coverage requirements
- Contributors must verify that AI-generated code does not introduce security vulnerabilities or licensing issues
Using AI tools is acceptable and can improve productivity, but transparency is essential for code quality, security auditing, and knowledge transfer.
Before submitting your pull request:
- Run
make ci-joblocally and ensure all checks pass - Review the checklist in the pull request template and ensure all applicable items are completed
- Verify your PR title follows the required format (
JIRA-12345: DescriptionorNO-ISSUE: Description) - Ensure all commits are signed off with DCO (
git commit --signoff)
- Discuss the change: For significant changes, submit an issue or JIRA ticket describing your proposed change. The repository owners will respond to your issue promptly.
- Fork and develop: Fork the repository, create a feature branch, and develop your code changes following the Development Workflow guidelines.
- Test thoroughly: Ensure all tests pass and code coverage requirements are met (see Testing Requirements and Code Coverage Requirements).
- Run CI checks: Execute
make ci-joblocally and fix any issues. - Submit a pull request: Follow the Pull Request Guidelines for title format and description requirements.
Anyone can comment on issues and submit reviews for pull requests. In order to be assigned an issue or pull request, you can leave a /assign <your Github ID> comment on the issue or pull request.