Skip to content

Commit abdae2b

Browse files
Merge pull request #2925 from nrb/doc-replicated-types
📖 Document data types that are replicated
2 parents 0ba47ec + 08b2064 commit abdae2b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/content/CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,33 @@ All of the built-in types for `kcp` are `CustomResourceDefinitions`, and we gene
156156

157157
When adding a field that requires validation, custom annotations are used to translate this logic into the generated OpenAPI spec. [This doc](https://book.kubebuilder.io/reference/markers/crd-validation.html) gives an overview of possible validations. These annotations map directly to concepts in the [OpenAPI Spec](https://swagger.io/specification/#data-type-format) so, for instance, the `format` of strings is defined there, not in kubebuilder. Furthermore, Kubernetes has forked the OpenAPI project [here](https://github.com/kubernetes/kube-openapi/tree/master/pkg/validation) and extends more formats in the extensions-apiserver [here](https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/types_jsonschema.go#L27).
158158

159+
160+
### Replicated Data Types
161+
162+
Some objects are replicated and cached amongst shards when `kcp` is run in a sharded configuration. When writing code to list or get these objects, be sure to reference both shard-local and cache informers. To make this more convenient, wrap the look up in a function pointer.
163+
164+
For example:
165+
166+
```Golang
167+
168+
func NewController(ctx,
169+
localAPIExportInformer, cacheAPIExportInformer apisinformers.APIExportClusterInformer
170+
) (*controller, error) {
171+
...
172+
return &controller{
173+
listAPIExports: func(clusterName logicalcluster.Name) ([]apisv1apha1.APIExport, error) {
174+
exports, err := localAPIExportInformer.Cluster(clusterName).Lister().List(labels.Everything())
175+
if err != nil {
176+
return cacheAPIExportInformer.Cluster(clusterName).Lister().List(labels.Everything())
177+
}
178+
return exports, nil
179+
...
180+
}
181+
}
182+
```
183+
184+
A full list of replicated resources is currently outlined in the [replication controller](https://github.com/kcp-dev/kcp/blob/main/pkg/reconciler/cache/replication/replication_controller.go).
185+
159186
### Getting your PR Merged
160187
161188
The `kcp` project uses `OWNERS` files to denote the collaborators who can assist you in getting your PR merged. There

0 commit comments

Comments
 (0)