Skip to content

Commit 0c2829d

Browse files
authored
Merge pull request #3 from authzed/doc-comments
Add doc comments to packages
2 parents f8cd314 + 036c5fc commit 0c2829d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1820
-29
lines changed

NOTICE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ktrllib
1+
controller-idioms
22
Copyright 2022 Authzed, Inc
33

44
This product includes software developed at

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ secrets, err := secretIndexer.ByIndex("my-index-name", "my-index-value")
147147

148148
### Controllers and Managers
149149

150-
The `manager` package provides an optional lightweight controller `Manager` abstraction (similar to kubernetes controller manager, or the manager from controller runtime). It also provides a simple `Controller` abstraction and some basic implementations. Both are optional, `ktrllib` can be used without these.
150+
The `manager` package provides an optional lightweight controller `Manager` abstraction (similar to kubernetes controller manager, or the manager from controller runtime). It also provides a simple `Controller` abstraction and some basic implementations.
151151

152-
The rest of `ktrllib` can be used without using these if you are already using another solution.
152+
The rest of `controller-idioms` can be used without using these if you are already using another solution.
153153

154154
#### `Manager`
155155

adopt/adopt.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,51 @@ import (
3939
// TODO: a variant where there can only be one owner (label only, fail if labelled for someone else)
4040
// TODO: a variant where a real client is used to check for existence before applying
4141

42+
// Annotator is any type that can have annotations added to it. All standard
43+
// applyconfiguration packages from client-go implement this type. Custom types
44+
// should implement it themselves.
4245
type Annotator[T any] interface {
4346
WithAnnotations(entries map[string]string) T
4447
}
4548

49+
// Labeler is any type that can have labels added to it. All standard
50+
// applyconfiguration packages from client-go implement this type. Custom types
51+
// should implement it themselves.
4652
type Labeler[T any] interface {
4753
WithLabels(entries map[string]string) T
4854
}
4955

56+
// Adoptable is any type that can be labelled and annotated.
57+
// Labels are used for including in a watch stream, and annotations are used
58+
// to indicated ownership by a specific object.
5059
type Adoptable[T any] interface {
5160
Annotator[T]
5261
Labeler[T]
5362
}
5463

64+
// Object is satisfied by any standard kube object.
5565
type Object interface {
5666
comparable
5767
runtime.Object
5868
metav1.Object
5969
}
6070

71+
// ApplyFunc should apply a patch defined by the object A with server-side apply
72+
// and should return the base type. For example a SecretApplyConfiguration would
73+
// be applied with a client-go Patch call, and return a Secret.
6174
type ApplyFunc[K Object, A Adoptable[A]] func(ctx context.Context, object A, opts metav1.ApplyOptions) (result K, err error)
6275

76+
// IndexKeyFunc returns the name of an index to use and the value to query it for.
6377
type IndexKeyFunc func(ctx context.Context) (indexName string, indexValue string)
6478

79+
// Owned is used in object annotations to indicate an object is managed.
6580
const Owned = "owned"
6681

82+
// AdoptionHandler implements handler.Handler to "adopt" an existing resource
83+
// under the controller's management. See the package description for more info.
6784
type AdoptionHandler[K Object, A Adoptable[A]] struct {
85+
// OperationsContext allows the adoption handler to control the sync loop
86+
// it's called from to deal with transient errors.
6887
queue.OperationsContext
6988

7089
// ControllerFieldManager is the value to use when adopting the object
@@ -88,8 +107,8 @@ type AdoptionHandler[K Object, A Adoptable[A]] struct {
88107
// ObjectAdoptedFunc is called when an adoption was performed
89108
ObjectAdoptedFunc func(ctx context.Context, obj K)
90109

91-
// TODO: GetFromCache and Indexer should be replaced with an informer factory that can be
92-
// used to get both
110+
// TODO: GetFromCache and Indexer could be replaced with an informerfactory
111+
// that can be used to get both
93112

94113
// GetFromCache is where we expect to find the object if it is being watched
95114
// This will usually be a wrapper around an informer cache `Get`.

0 commit comments

Comments
 (0)