|
1 | | -# sdk-go |
2 | | -sdk for the go programming language use by other components in open-cluster-management |
| 1 | +# Open Cluster Management SDK for Go |
| 2 | + |
| 3 | +A Go SDK providing libraries and utilities for building applications that integrate with Open Cluster Management (OCM). This SDK enables developers to build controllers, agents, and other components that work with OCM's multi-cluster management capabilities. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The OCM SDK for Go provides essential building blocks for: |
| 8 | + |
| 9 | +- Building controllers and agents for multi-cluster management |
| 10 | +- Implementing event-based communication using CloudEvents |
| 11 | +- Managing ManifestWork resources across clusters |
| 12 | +- Certificate management and rotation |
| 13 | +- Resource patching and manipulation |
| 14 | +- Testing OCM-related components |
| 15 | + |
| 16 | +## Main Components |
| 17 | + |
| 18 | +### CloudEvents Clients |
| 19 | + |
| 20 | +The SDK includes comprehensive CloudEvents-based clients for implementing event-driven communication between hub clusters and managed clusters. This supports the Event Based ManifestWork architecture. |
| 21 | + |
| 22 | +**Supported Protocols:** |
| 23 | +- MQTT Protocol/Driver |
| 24 | +- gRPC Protocol/Driver |
| 25 | +- Kafka Protocol/Driver |
| 26 | + |
| 27 | +**Key Features:** |
| 28 | +- Generic CloudEvents clients for custom resources |
| 29 | +- Specialized ManifestWork clients |
| 30 | +- Source and agent client implementations |
| 31 | +- Automatic reconnection handling |
| 32 | +- Resource synchronization capabilities |
| 33 | + |
| 34 | +### Base Controller Utilities |
| 35 | + |
| 36 | +Foundation components for building Kubernetes controllers that integrate with OCM: |
| 37 | + |
| 38 | +- Controller factories and base implementations |
| 39 | +- Event handling utilities |
| 40 | +- Common controller patterns |
| 41 | + |
| 42 | +### API Definitions |
| 43 | + |
| 44 | +Go types and clients for OCM APIs: |
| 45 | + |
| 46 | +- Cluster management APIs |
| 47 | +- WorkV1 APIs for ManifestWork resources |
| 48 | +- Typed clients for OCM resources |
| 49 | + |
| 50 | +### Helper Utilities |
| 51 | + |
| 52 | +Common utilities for OCM development: |
| 53 | + |
| 54 | +- Resource application helpers |
| 55 | +- Client utilities |
| 56 | +- Certificate Signing Request (CSR) utilities |
| 57 | + |
| 58 | +### Additional Components |
| 59 | + |
| 60 | +- **Certificate Rotation**: Automated certificate lifecycle management |
| 61 | +- **Resource Patchers**: Utilities for modifying Kubernetes resources |
| 62 | +- **Testing Utilities**: Helper functions and mocks for testing OCM components |
| 63 | +- **Serving Certificates**: Certificate management for webhooks and APIs |
| 64 | + |
| 65 | +## Getting Started |
| 66 | + |
| 67 | +### Installation |
| 68 | + |
| 69 | +```bash |
| 70 | +go get open-cluster-management.io/sdk-go |
| 71 | +``` |
| 72 | + |
| 73 | +### Basic Usage |
| 74 | + |
| 75 | +#### CloudEvents Client Example |
| 76 | + |
| 77 | +```go |
| 78 | +import ( |
| 79 | + "open-cluster-management.io/sdk-go/pkg/cloudevents/generic" |
| 80 | + "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options/mqtt" |
| 81 | +) |
| 82 | + |
| 83 | +// Create a CloudEvents source client |
| 84 | +client, err := generic.NewCloudEventSourceClient[*YourResource]( |
| 85 | + ctx, |
| 86 | + mqtt.NewSourceOptions(mqttConfig, "client-id", "source-id"), |
| 87 | + resourceLister, |
| 88 | + statusHashGetter, |
| 89 | + resourceCodec, |
| 90 | +) |
| 91 | + |
| 92 | +// Subscribe to receive events |
| 93 | +client.Subscribe(ctx, resourceHandler) |
| 94 | +``` |
| 95 | + |
| 96 | +#### ManifestWork Client Example |
| 97 | + |
| 98 | +```go |
| 99 | +import ( |
| 100 | + "open-cluster-management.io/sdk-go/pkg/cloudevents/work" |
| 101 | + "open-cluster-management.io/sdk-go/pkg/cloudevents/work/codec" |
| 102 | +) |
| 103 | + |
| 104 | +// Build a ManifestWork client |
| 105 | +clientHolder, err := work.NewClientHolderBuilder(config). |
| 106 | + WithClientID("controller-client"). |
| 107 | + WithSourceID("controller"). |
| 108 | + WithCodec(codec.NewManifestBundleCodec()). |
| 109 | + NewSourceClientHolder(ctx) |
| 110 | + |
| 111 | +manifestWorkClient := clientHolder.ManifestWorks(namespace) |
| 112 | +``` |
| 113 | + |
| 114 | +## Documentation |
| 115 | + |
| 116 | +- **CloudEvents**: See [pkg/cloudevents/README.md](pkg/cloudevents/README.md) for detailed CloudEvents client documentation |
| 117 | +- **API Reference**: Go package documentation available via `go doc` |
| 118 | +- **Examples**: Check the test directories for usage examples |
| 119 | + |
| 120 | +## Development |
| 121 | + |
| 122 | +### Prerequisites |
| 123 | + |
| 124 | +- Go 1.24.0 or later |
| 125 | +- Access to a Kubernetes cluster (for testing) |
| 126 | + |
| 127 | +### Building |
| 128 | + |
| 129 | +```bash |
| 130 | +make build |
| 131 | +``` |
| 132 | + |
| 133 | +### Testing |
| 134 | + |
| 135 | +```bash |
| 136 | +make test |
| 137 | +``` |
| 138 | + |
| 139 | +## Contributing |
| 140 | + |
| 141 | +We welcome contributions! Please see: |
| 142 | + |
| 143 | +- [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines |
| 144 | +- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for community standards |
| 145 | +- [DCO](DCO) for sign-off requirements |
| 146 | + |
| 147 | +### Development Certificate of Origin |
| 148 | + |
| 149 | +All commits must be signed off to indicate agreement with the Developer Certificate of Origin: |
| 150 | + |
| 151 | +```bash |
| 152 | +git commit --signoff |
| 153 | +``` |
| 154 | + |
| 155 | +## License |
| 156 | + |
| 157 | +This project is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details. |
| 158 | + |
| 159 | +## Community |
| 160 | + |
| 161 | +Open Cluster Management is a CNCF project. For more information: |
| 162 | + |
| 163 | +- [OCM Website](https://open-cluster-management.io/) |
| 164 | +- [OCM GitHub Organization](https://github.com/open-cluster-management-io) |
| 165 | +- [Community Meetings and Resources](https://github.com/open-cluster-management-io/community) |
| 166 | + |
| 167 | +## Related Projects |
| 168 | + |
| 169 | +- [OCM Core](https://github.com/open-cluster-management-io/ocm) - Core OCM components |
| 170 | +- [OCM API](https://github.com/open-cluster-management-io/api) - OCM API definitions |
| 171 | +- [Addon Framework](https://github.com/open-cluster-management-io/addon-framework) - Framework for building OCM addons |
0 commit comments