Skip to content

Commit 762715b

Browse files
committed
Clean up docs
This cleans up the existing docs, clarifying working, improving spacing, and making sure all packages have docs.
1 parent 02c8fb4 commit 762715b

File tree

26 files changed

+264
-56
lines changed

26 files changed

+264
-56
lines changed

doc.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License.
2323
// and uncommon cases should be possible. In general, controller-runtime tries
2424
// to guide users towards Kubernetes controller best-practices.
2525
//
26-
// Overview
26+
// Getting Started
2727
//
2828
// The main entrypoint for controller-runtime is this root package, which
2929
// contains all of the common types needed to get started building controllers:
@@ -40,7 +40,7 @@ limitations under the License.
4040
//
4141
// Organization
4242
//
43-
// A brief walkthrough of the layout of this library can be found below. Each
43+
// A brief-ish walkthrough of the layout of this library can be found below. Each
4444
// package contains more information about how to use it.
4545
//
4646
// Frequently asked questions about using controller-runtime and designing
@@ -58,8 +58,8 @@ limitations under the License.
5858
//
5959
// Controllers
6060
//
61-
// Controllers (pkg/controller) handle using events (pkg/events) to eventually
62-
// trigger reconcile requests. They may be constructed manually, but are often
61+
// Controllers (pkg/controller) use events (pkg/events) to eventually trigger
62+
// reconcile requests. They may be constructed manually, but are often
6363
// constructed with a Builder (pkg/builder), which eases the wiring of event
6464
// sources (pkg/source), like Kubernetes API object changes, to event handlers
6565
// (pkg/handler), like "enqueue a reconcile request for the object owner".
@@ -75,7 +75,7 @@ limitations under the License.
7575
// and returns a Response or an error indicating whether to requeue for a
7676
// second round of processing.
7777
//
78-
// Clients (and Caches)
78+
// Clients and Caches
7979
//
8080
// Reconcilers use Clients (pkg/client) to access API objects. The default
8181
// client provided by the manager reads from a local shared cache (pkg/cache)
@@ -88,6 +88,12 @@ limitations under the License.
8888
// may retrieve event recorders (pkg/recorder) to emit events using the
8989
// manager.
9090
//
91+
// Schemes
92+
//
93+
// Clients, Caches, and many other things in Kubernetes use Schemes
94+
// (pkg/runtime/scheme) to associate Go types to Kubernetes API Kinds
95+
// (Group-Version-Kinds, to be specific).
96+
//
9197
// Webhooks
9298
//
9399
// Similarly, webhooks (pkg/webhook/admission) may be implemented directly, but
@@ -97,15 +103,16 @@ limitations under the License.
97103
// Logging and Metrics
98104
//
99105
// Logging (pkg/log) in controller-runtime is done via structured logs, using a
100-
// log interface set called logr (https://godoc.org/github.com/go-logr/logr).
101-
// While controller-runtime provides easy setup for using Zap
102-
// (https://go.uber.org/zap, pkg/log/zap), you can provide any implementation
103-
// of logr as the base logger for controller-runtime.
106+
// log set of interfaces called logr
107+
// (https://godoc.org/github.com/go-logr/logr). While controller-runtime
108+
// provides easy setup for using Zap (https://go.uber.org/zap, pkg/log/zap),
109+
// you can provide any implementation of logr as the base logger for
110+
// controller-runtime.
104111
//
105112
// Metrics (pkg/metrics) provided by controller-runtime are registered into a
106-
// controller-runtime-specific Prometheus metrics registery. The manager will
107-
// serve these by default at an HTTP endpoint, and additional metrics may be
108-
// registered to this Registry as normal.
113+
// controller-runtime-specific Prometheus metrics registery. The manager can
114+
// serve these by an HTTP endpoint, and additional metrics may be registered to
115+
// this Registry as normal.
109116
//
110117
// Testing
111118
//

pkg/cache/cache.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ import (
3434

3535
var log = logf.RuntimeLog.WithName("object-cache")
3636

37-
// Cache implements CacheReader by reading objects from a cache populated by InformersMap
37+
// Cache knows how to load Kubernetes objects, fetch informers to request
38+
// to receive events for Kubernetes objects (at a low-level),
39+
// and add indicies to fields on the objects stored in the cache.
3840
type Cache interface {
39-
// Cache implements the client CacheReader
41+
// Cache acts as a client to objects stored in the cache.
4042
client.Reader
4143

42-
// Cache implements InformersMap
44+
// Cache loads informers and adds field indicies.
4345
Informers
4446
}
4547

46-
// Informers knows how to create or fetch informers for different group-version-kinds.
47-
// It's safe to call GetInformer from multiple threads.
48+
// Informers knows how to create or fetch informers for different
49+
// group-version-kinds, and add indicies to those informers. It's safe to call
50+
// GetInformer from multiple threads.
4851
type Informers interface {
4952
// GetInformer fetches or constructs an informer for the given object that corresponds to a single
5053
// API kind and resource.
@@ -61,15 +64,11 @@ type Informers interface {
6164
// WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.
6265
WaitForCacheSync(stop <-chan struct{}) bool
6366

64-
// IndexField adds an index with the given field name on the given object type
65-
// by using the given function to extract the value for that field. If you want
66-
// compatibility with the Kubernetes API server, only return one key, and only use
67-
// fields that the API server supports. Otherwise, you can return multiple keys,
68-
// and "equality" in the field selector means that at least one key matches the value.
69-
IndexField(obj runtime.Object, field string, extractValue client.IndexerFunc) error
67+
// Informers knows how to add indicies to the caches (informers) that it manages.
68+
client.FieldIndexer
7069
}
7170

72-
// Options are the optional arguments for creating a new InformersMap object
71+
// Options are the optional arguments for creating a new set of Informers.
7372
type Options struct {
7473
// Scheme is the scheme to use for mapping objects to GroupVersionKinds
7574
Scheme *runtime.Scheme
@@ -87,7 +86,7 @@ type Options struct {
8786

8887
var defaultResyncTime = 10 * time.Hour
8988

90-
// New initializes and returns a new Cache
89+
// New initializes and returns a new Cache.
9190
func New(config *rest.Config, opts Options) (Cache, error) {
9291
opts, err := defaultOpts(config, opts)
9392
if err != nil {

pkg/cache/doc.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package cache provides object caches that act as caching client.Reader
18+
// instances and help drive Kubernetes-object-based event handlers.
19+
package cache

pkg/client/apiutil/apimachinery.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package apiutil contains utilities for working with raw Kubernetes
18+
// API machinery, such as creating RESTMappers and raw REST clients,
19+
// and extracting the GVK of an object.
1720
package apiutil
1821

1922
import (

pkg/client/config/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package config contains libraries for initializing rest configs for talking to the Kubernetes API
17+
// Package config contains libraries for initializing REST configs for talking to the Kubernetes API
1818
package config

pkg/client/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func ExampleClient_delete() {
199199
_ = c.Delete(context.Background(), u)
200200
}
201201

202-
// This example shows how to set up and consume a field select over a pod's volumes' secretName field.
202+
// This example shows how to set up and consume a field selector over a pod's volumes' secretName field.
203203
func ExampleFieldIndexer_secretName() {
204204
// someIndexer is a FieldIndexer over a Cache
205205
_ = someIndexer.IndexField(&corev1.Pod{}, "spec.volumes.secret.secretName", func(o runtime.Object) []string {

pkg/client/fake/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ var _ client.Client = &fakeClient{}
4747

4848
// NewFakeClient creates a new fake client for testing.
4949
// You can choose to initialize it with a slice of runtime.Object.
50+
// Deprecated: use NewFakeClientWithScheme. You should always be
51+
// passing an explicit Scheme.
5052
func NewFakeClient(initObjs ...runtime.Object) client.Client {
5153
return NewFakeClientWithScheme(scheme.Scheme, initObjs...)
5254
}

pkg/client/fake/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ You can create a fake client with optional objects.
2323
client := NewFakeClient(initObjs...) // initObjs is a slice of runtime.Object
2424
2525
You can invoke the methods defined in the Client interface.
26+
27+
When it doubt, it's almost always better not to use this package and instead use
28+
envtest.Environment with a real client and API server.
2629
*/
2730
package fake

pkg/client/split.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ import (
2323
"k8s.io/apimachinery/pkg/runtime"
2424
)
2525

26-
// DelegatingClient forms an interface Client by composing separate
27-
// reader, writer and statusclient interfaces. This way, you can have an Client that
28-
// reads from a cache and writes to the API server.
26+
// DelegatingClient forms a Client by composing separate reader, writer and
27+
// statusclient interfaces. This way, you can have an Client that reads from a
28+
// cache and writes to the API server.
2929
type DelegatingClient struct {
3030
Reader
3131
Writer
3232
StatusClient
3333
}
3434

35-
// DelegatingReader forms a interface Reader that will cause Get and List
36-
// requests for unstructured types to use the ClientReader while
37-
// requests for any other type of object with use the CacheReader.
35+
// DelegatingReader forms a Reader that will cause Get and List requests for
36+
// unstructured types to use the ClientReader while requests for any other type
37+
// of object with use the CacheReader. This avoids accidentally caching the
38+
// entire cluster in the common case of loading arbitrary unstructured objects
39+
// (e.g. from OwnerReferences).
3840
type DelegatingReader struct {
3941
CacheReader Reader
4042
ClientReader Reader

pkg/controller/controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ type Controller interface {
4545
// Reconciler is called to Reconciler an object by Namespace/Name
4646
reconcile.Reconciler
4747

48-
// Watch takes events provided by a Source and uses the EventHandler to enqueue reconcile.Requests in
49-
// response to the events.
48+
// Watch takes events provided by a Source and uses the EventHandler to
49+
// enqueue reconcile.Requests in response to the events.
5050
//
51-
// Watch may be provided one or more Predicates to filter events before they are given to the EventHandler.
52-
// Events will be passed to the EventHandler iff all provided Predicates evaluate to true.
51+
// Watch may be provided one or more Predicates to filter events before
52+
// they are given to the EventHandler. Events will be passed to the
53+
// EventHandler iff all provided Predicates evaluate to true.
5354
Watch(src source.Source, eventhandler handler.EventHandler, predicates ...predicate.Predicate) error
5455

55-
// Start starts the controller. Start blocks until stop is closed or a controller has an error starting.
56+
// Start starts the controller. Start blocks until stop is closed or a
57+
// controller has an error starting.
5658
Start(stop <-chan struct{}) error
5759
}
5860

0 commit comments

Comments
 (0)