This file provides AI agents with comprehensive context about the operator-framework/api repository to enable effective navigation, understanding, and contribution.
This repository contains the API definitions and validation libraries used by Operator Lifecycle Manager (OLMv0). It's a foundational library in the Operator Framework ecosystem.
- API Definitions: Kubernetes Custom Resource Definitions (CRDs) for OLM resources
- Manifest Validation: Static validators for operator bundles and package manifests
- CLI Tool:
operator-verifyfor manifest verification - Common Libraries: Shared utilities for bundle and manifest manipulation
| Resource | API Group | Description |
|---|---|---|
| ClusterServiceVersion (CSV) | operators.coreos.com/v1alpha1 | Defines operator metadata, installation strategy, permissions, and owned/required CRDs |
| Subscription | operators.coreos.com/v1alpha1 | Tracks operator updates from a catalog channel |
| InstallPlan | operators.coreos.com/v1alpha1 | Calculated list of resources to install/upgrade |
| CatalogSource | operators.coreos.com/v1alpha1 | Repository of operators and metadata |
| OperatorGroup | operators.coreos.com/v1 | Groups namespaces for operator installation scope |
| OperatorCondition | operators.coreos.com/v2 | Tracks operator health status and conditions |
api/
├── cmd/ # Entry point binaries
│ └── operator-verify/ # CLI tool for manifest verification
│
├── pkg/ # Core implementation
│ ├── operators/ # OLM API types
│ │ ├── v1alpha1/ # Core OLM types (CSV, Subscription, etc.)
│ │ ├── v1/ # OperatorGroup, OperatorCondition v1
│ │ ├── v2/ # OperatorCondition v2
│ │ └── reference/ # Image reference parsing
│ │
│ ├── validation/ # Operator manifest validators
│ │ ├── errors/ # Validation error types
│ │ ├── interfaces/ # Validator interfaces
│ │ └── internal/ # Validator implementations
│ │
│ ├── manifests/ # Bundle and manifest loaders
│ │
│ ├── constraints/ # Constraint and CEL validation
│ │
│ ├── lib/version/ # Version utilities
│ │
│ └── apis/scorecard/ # Scorecard configuration types
│
├── crds/ # Generated CRD YAML files
│
└── hack/ # Build scripts and tools
Defines all Kubernetes custom resources used by OLM:
v1alpha1/: Core types (CSV, Subscription, InstallPlan, CatalogSource)v1/: OperatorGroup, Operator, OperatorConditionv2/: OperatorCondition v2reference/: Container image reference parsing utilities
Key files:
v1alpha1/clusterserviceversion_types.go- CSV API definitionv1/operatorgroup_types.go- OperatorGroup API definition
Static validators for operator bundles and manifests:
- Default Validators: Required checks for all operators
- Optional Validators: Community, OperatorHub, and best practice validators
- Custom Validators: Extensible validator interface
Key files:
validation.go- Main validator orchestrationinternal/bundle.go- Bundle structure validationinternal/csv.go- CSV validation rulesinternal/operatorhub.go- OperatorHub requirements
Validator Types:
BundleValidator- Bundle format and structureCSVValidator- ClusterServiceVersion validationCRDValidator- CRD validationOperatorHubValidator- OperatorHub.io requirementsGoodPracticesValidator- Best practices checksAlphaDeprecatedAPIsValidator- Deprecated API detection
Bundle and package manifest loaders:
- Bundle loading from directories
- PackageManifest parsing
- Metadata extraction
Key files:
bundle.go- Bundle representation and loadingbundleloader.go- Bundle loading logic
make install # Build and install operator-verify CLImake test-unit # Run unit tests
make test # Run all tests
make TEST=<name> test-unit # Run specific testmake generate # Generate deep-copy methods
make manifests # Generate CRD manifests
make verify # Verify generated code is up-to-datemake format # Format source code
make tidy # Update and verify dependenciesimport (
apimanifests "github.com/operator-framework/api/pkg/manifests"
apivalidation "github.com/operator-framework/api/pkg/validation"
)
// Load bundle
bundle, err := apimanifests.GetBundleFromDir(path)
if err != nil {
return err
}
// Run default validators
validators := apivalidation.DefaultBundleValidators
results := validators.Validate(bundle.ObjectsToValidate()...)
// Check results
for _, result := range results {
if result.HasError() {
fmt.Printf("Error: %v\n", result)
}
}// Add optional validators
validators := apivalidation.DefaultBundleValidators
validators = validators.WithValidators(apivalidation.OperatorHubValidator)
validators = validators.WithValidators(apivalidation.GoodPracticesValidator)
// Pass optional key/values
optionalValues := map[string]string{
"k8s-version": "1.28",
}
objs := append(bundle.ObjectsToValidate(), optionalValues)
results := validators.Validate(objs...)# Install operator-verify
make install
# Verify manifests
operator-verify manifests /path/to/manifest.yamlThis repository uses controller-gen for code generation:
- Deep-copy methods: Auto-generated for all API types (
zz_generated.deepcopy.go) - CRD manifests: Generated from Go type definitions in
crds/ - Embedded CRDs: Go code embedding CRD YAML in
crds/zz_defs.go
make generate manifests # Regenerate everything
make verify # Verify nothing changedImportant: Never edit generated files directly - modify the source types and regenerate.
- Bundle loaded via
pkg/manifests - Validators instantiated from
pkg/validation - Each validator checks specific aspects (CSV format, CRD structure, etc.)
- Results aggregated with errors/warnings
- Results returned to caller
- Create new validator in
pkg/validation/internal/ - Implement
interfaces.Validatorinterface - Add validator to appropriate suite in
pkg/validation/validation.go - Write unit tests in
*_test.go - Document validator behavior
- Edit type definition in
pkg/operators/v*/ - Update CRD markers (kubebuilder comments) if needed
- Run
make generate manifeststo regenerate code - Run
make verifyto ensure clean state - Update tests if behavior changed
- All CRDs defined in
pkg/operators/v*/ - Generated to
crds/*.yamlvia controller-gen - Embedded in Go code at
crds/zz_defs.go - Used by OLM and other operator-framework components
| Dependency | Purpose |
|---|---|
| k8s.io/api | Kubernetes core types |
| k8s.io/apimachinery | Kubernetes meta types |
| sigs.k8s.io/controller-tools | Code generation (controller-gen) |
| github.com/blang/semver/v4 | Semantic versioning |
| github.com/operator-framework/operator-registry | Registry integration |
- Core OLM types:
pkg/operators/v1alpha1/ - OperatorGroup:
pkg/operators/v1/operatorgroup_types.go - OperatorCondition:
pkg/operators/v2/operatorcondition_types.go
- Validator implementations:
pkg/validation/internal/ - Validator interfaces:
pkg/validation/interfaces/ - Main orchestration:
pkg/validation/validation.go
- Bundle loading:
pkg/manifests/bundle.go - Image references:
pkg/operators/reference/ - Version utilities:
pkg/lib/version/
- Don't modify generated code - Edit source types and regenerate
- Don't skip
make verify- Always verify generated code is current - Don't add breaking API changes - This is a library used by multiple projects
- Don't add validators without tests - All validators must be thoroughly tested
- Don't bypass validation interfaces - Use the provided validator framework
- OLM Documentation
- Operator SDK Bundle Validation
- Operator Framework Community
- Validation Package Docs
make install # Install operator-verify CLI
make test-unit # Run unit tests
make generate manifests # Generate code and CRDs
make verify # Verify no uncommitted changes
make format tidy # Format and tidy codeTools are managed via Makefile and installed to ./bin/:
controller-gen- Kubernetes code generatoryq- YAML processor for CRD patchingkind- Local Kubernetes clusters
See DCO for Developer Certificate of Origin requirements.
When contributing:
- Run
make verifybefore submitting PRs - Add tests for new validators or API changes
- Update CRD generation if modifying types
- Follow existing patterns for consistency