Skip to content

Commit 4fc3d07

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 4fc3d07

File tree

17 files changed

+114
-39
lines changed

17 files changed

+114
-39
lines changed

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/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

pkg/controller/controllertest/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ limitations under the License.
1515
*/
1616

1717
// Package controllertest contains fake informers for testing controllers
18+
// When in doubt, it's almost always better to test against a real API server
19+
// using envtest.Environment.
1820
package controllertest

pkg/envtest/doc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ limitations under the License.
1515
*/
1616

1717
// Package envtest provides libraries for integration testing by starting a local control plane
18+
//
19+
// Control plane binaries (etcd and kube-apiserver) are loaded by default from
20+
// /usr/local/kubebuilder/bin. This can be overridden by setting the
21+
// KUBEBUILDER_ASSETS environment variable, or by directly creating a
22+
// ControlPlane for the Environment to use.
23+
//
24+
// Environment can also be configured to work with an existing cluster, and
25+
// simply load CRDs and provide client configuration.
1826
package envtest

pkg/envtest/printer/ginkgo.go

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

17+
// Package printer contains setup for a friendlier Ginkgo printer that's easier
18+
// to parse by test automation.
1719
package printer
1820

1921
import (

pkg/envtest/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ type Environment struct {
7373
// ControlPlane is the ControlPlane including the apiserver and etcd
7474
ControlPlane integration.ControlPlane
7575

76-
// Config can be used to talk to the apiserver
76+
// Config can be used to talk to the apiserver. It's automatically
77+
// populated if not set using the standard controller-runtime config
78+
// loading.
7779
Config *rest.Config
7880

7981
// CRDs is a list of CRDs to install

pkg/event/doc.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ limitations under the License.
1818
Package event contains the definitions for the Event types produced by source.Sources and transformed into
1919
reconcile.Requests by handler.EventHandler.
2020
21-
The details of how events are produced and transformed into reconcile.Requests are not something most
22-
users should need to use or understand. Instead of working with Events, users should use
23-
source.Sources and handler.EventHandlers with Controller.Watch.
21+
You should rarely need to work with these directly -- instead, use Controller.Watch with
22+
source.Sources and handler.EventHandlers.
23+
24+
Events generally contain both a full runtime.Object that caused the event, as well
25+
as a direct handle to that object's metadata. This saves a lot of typecasting in
26+
code that works with Events.
2427
*/
2528
package event

pkg/handler/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Package handler defines EventHandlers that enqueue reconcile.Requests in respons
1919
observed from Watching Kubernetes APIs. Users should provide a source.Source and handler.EventHandler to
2020
Controller.Watch in order to generate and enqueue reconcile.Request work items.
2121
22+
Generally, following premade event handlers should be sufficient for most use cases:
23+
2224
EventHandlers
2325
2426
EnqueueRequestForObject - Enqueues a reconcile.Request containing the Name and Namespace of the object in the Event. This will

pkg/leaderelection/doc.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ limitations under the License.
1515
*/
1616

1717
/*
18-
Package leaderelection contains a constructors for a leader election resource lock
18+
Package leaderelection contains a constructors for a leader election resource lock.
19+
This is used to ensure that multipe copies of a controller manager can be run with
20+
only one active set of controllers, for active-passive HA.
21+
22+
It uses built-in Kubernetes leader election APIs.
1923
*/
2024
package leaderelection

pkg/log/log.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ limitations under the License.
1616

1717
// Package log contains utilities for fetching a new logger
1818
// when one is not already available.
19-
// Deprecated: use pkg/log
19+
//
20+
// The Log Handle
21+
//
22+
// This package contains a root logr.Logger Log. It may be used to
23+
// get a handle to whatever the root logging implementation is. By
24+
// default, no implementation exists, and the handle returns "promises"
25+
// to loggers. When the implementation is set using SetLogger, these
26+
// "promises" will be converted over to real loggers.
27+
//
28+
// Logr
29+
//
30+
// All logging in controller-runtime is structured, using a set of interfaces
31+
// defined by a package called logr
32+
// (https://godoc.org/github.com/go-logr/logr). The sub-package zap provides
33+
// helpers for setting up logr backed by Zap (go.uber.org/zap).
2034
package log
2135

2236
import (

pkg/manager/manager.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ type Manager interface {
8484
// Options are the arguments for creating a new Manager
8585
type Options struct {
8686
// Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources
87-
// Defaults to the kubernetes/client-go scheme.Scheme
87+
// Defaults to the kubernetes/client-go scheme.Scheme, but it's almost always a good
88+
// idea to pass your own scheme in.
8889
Scheme *runtime.Scheme
8990

9091
// MapperProvider provides the rest mapper used to map go types to Kubernetes APIs
@@ -108,10 +109,12 @@ type Options struct {
108109
// will use for holding the leader lock.
109110
LeaderElectionID string
110111

111-
// Namespace if specified restricts the manager's cache to watch objects in the desired namespace
112-
// Defaults to all namespaces
113-
// Note: If a namespace is specified then controllers can still Watch for a cluster-scoped resource e.g Node
114-
// For namespaced resources the cache will only hold objects from the desired namespace.
112+
// Namespace if specified restricts the manager's cache to watch objects in
113+
// the desired namespace Defaults to all namespaces
114+
//
115+
// Note: If a namespace is specified, controllers can still Watch for a
116+
// cluster-scoped resource (e.g Node). For namespaced resources the cache
117+
// will only hold objects from the desired namespace.
115118
Namespace string
116119

117120
// MetricsBindAddress is the TCP address that the controller should bind to
@@ -143,13 +146,18 @@ type NewCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, er
143146
type NewClientFunc func(cache cache.Cache, config *rest.Config, options client.Options) (client.Client, error)
144147

145148
// Runnable allows a component to be started.
149+
// It's very important that Start blocks until
150+
// it's done running.
146151
type Runnable interface {
147-
// Start starts running the component. The component will stop running when the channel is closed.
148-
// Start blocks until the channel is closed or an error occurs.
152+
// Start starts running the component. The component will stop running
153+
// when the channel is closed. Start blocks until the channel is closed or
154+
// an error occurs.
149155
Start(<-chan struct{}) error
150156
}
151157

152-
// RunnableFunc implements Runnable
158+
// RunnableFunc implements Runnable using a function.
159+
// It's very important that the given function block
160+
// until it's done running.
153161
type RunnableFunc func(<-chan struct{}) error
154162

155163
// Start implements Runnable

0 commit comments

Comments
 (0)