Skip to content

Commit 260164d

Browse files
committed
doc: clean up README and user-guide
1 parent 6d870c9 commit 260164d

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,40 @@
22

33
[![Build Status](https://travis-ci.org/operator-framework/operator-sdk.svg?branch=master)](https://travis-ci.org/operator-framework/operator-sdk)
44

5-
### Project Status: pre-alpha
5+
### Project Status: alpha
66

7-
The project is currently pre-alpha and it is expected that breaking changes to the API will be made in the upcoming releases.
7+
The project is currently alpha. The core APIs provided by the controller-runtime will most likely be unchanged. New features and APIs may still be added in the future.
88

9-
See the [design docs][design_docs] for planned work on upcoming milestones.
9+
See the [proposal docs][proposals_docs] and issues for ongoing or planned work.
1010

1111
## Overview
1212

1313
This project is a component of the [Operator Framework][of-home], an open source toolkit to manage Kubernetes native applications, called Operators, in an effective, automated, and scalable way. Read more in the [introduction blog post][of-blog].
1414

1515
[Operators][operator_link] make it easy to manage complex stateful applications on top of Kubernetes. However writing an operator today can be difficult because of challenges such as using low level APIs, writing boilerplate, and a lack of modularity which leads to duplication.
1616

17-
The Operator SDK is a framework designed to make writing operators easier by providing:
17+
The Operator SDK is a framework that uses the [controller-runtime][controller_runtime] library to make writing operators easier by providing:
1818
- High level APIs and abstractions to write the operational logic more intuitively
1919
- Tools for scaffolding and code generation to bootstrap a new project fast
2020
- Extensions to cover common operator use cases
2121

2222
## Workflow
2323

24-
The SDK provides the following workflow to develop a new operator:
24+
The SDK provides the following workflow to develop a new operator in Go:
2525
1. Create a new operator project using the SDK Command Line Interface(CLI)
2626
2. Define new resource APIs by adding Custom Resource Definitions(CRD)
27-
3. Specify resources to watch using the SDK API
28-
4. Define the operator reconciling logic in a designated handler and use the SDK API to interact with resources
27+
3. Define Controllers to watch and reconcile resources
28+
4. Write the reconciling logic for your Controller using the SDK and controller-runtime APIs
2929
5. Use the SDK CLI to build and generate the operator deployment manifests
3030

31-
At a high level an operator using the SDK processes events for watched resources in a user defined handler and takes actions to reconcile the state of the application.
32-
3331
## Prerequisites
3432

3533
- [dep][dep_tool] version v0.5.0+.
3634
- [git][git_tool]
3735
- [go][go_tool] version v1.10+.
3836
- [docker][docker_tool] version 17.03+.
39-
- [kubectl][kubectl_tool] version v1.10.0+.
40-
- Access to a kubernetes v.1.10.0+ cluster.
37+
- [kubectl][kubectl_tool] version v1.11.0+.
38+
- Access to a kubernetes v.1.11.0+ cluster.
4139

4240
## Quick Start
4341

@@ -104,9 +102,11 @@ $ kubectl delete -f deploy/service_account.yaml
104102
$ kubectl delete -f deploy/crds/app_v1alpha1_appservice_crd.yaml
105103
```
106104

107-
## User Guide
105+
## User Guides
106+
107+
To learn more about the writing an operator in Go, see the [user guide][guide].
108108

109-
To learn more about the operator-sdk, see the [user guide][guide].
109+
The SDK also supports developing an operator using Ansible. See the [Ansible operator user guide][ansible_user_guide].
110110

111111
## Samples
112112

@@ -125,7 +125,7 @@ See [reporting bugs][bug_guide] for details about reporting any issues.
125125
Operator SDK is under Apache 2.0 license. See the [LICENSE][license_file] file for details.
126126

127127
[operator_link]: https://coreos.com/operators/
128-
[design_docs]: ./doc/design
128+
[proposals_docs]: ./doc/proposals
129129
[guide]: ./doc/user-guide.md
130130
[samples]: https://github.com/operator-framework/operator-sdk-samples
131131
[of-home]: https://github.com/operator-framework
@@ -138,3 +138,5 @@ Operator SDK is under Apache 2.0 license. See the [LICENSE][license_file] file f
138138
[go_tool]:https://golang.org/dl/
139139
[docker_tool]:https://docs.docker.com/install/
140140
[kubectl_tool]:https://kubernetes.io/docs/tasks/tools/install-kubectl/
141+
[controller_runtime]: https://github.com/kubernetes-sigs/controller-runtime
142+
[ansible_user_guide]:./ansible/user-guide.md

doc/user-guide.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ how to program an operator in Go.
1111
- [git][git_tool]
1212
- [go][go_tool] version v1.10+.
1313
- [docker][docker_tool] version 17.03+.
14-
- [kubectl][kubectl_tool] version v1.10.0+.
15-
- Access to a kubernetes v.1.10.0+ cluster.
14+
- [kubectl][kubectl_tool] version v1.11.0+.
15+
- Access to a kubernetes v.1.11.0+ cluster.
1616

1717
**Note**: This guide uses [minikube][minikube_tool] version v0.25.0+ as the local kubernetes cluster and quay.io for the public registry.
1818

@@ -48,11 +48,11 @@ $ cd memcached-operator
4848
To learn about the project directory structure, see [project layout][layout_doc] doc.
4949

5050
### Manager
51-
The main program for the operator is the Manager `cmd/manager/main.go`.
51+
The main program for the operator `cmd/manager/main.go` initializes and runs the [Manager][manager_go_doc].
5252

53-
The manager will automatically register the scheme for all custom resources defined under `pkg/apis/...` and run all controllers under `pkg/controller/...`.
53+
The Manager will automatically register the scheme for all custom resources defined under `pkg/apis/...` and run all controllers under `pkg/controller/...`.
5454

55-
The manager can restrict the namespace that all controllers will watch for resources:
55+
The Manager can restrict the namespace that all controllers will watch for resources:
5656
```Go
5757
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
5858
```
@@ -61,7 +61,7 @@ By default this will be the namespace that the operator is running in. To watch
6161
mgr, err := manager.New(cfg, manager.Options{Namespace: ""})
6262
```
6363

64-
**// TODO:** Doc on manager options(Sync period, leader election, registering 3rd party types)
64+
**// TODO:** Doc on leader election
6565

6666
## Add a new Custom Resource Definition
6767

@@ -72,7 +72,9 @@ $ operator-sdk add api --api-version=cache.example.com/v1alpha1 --kind=Memcached
7272
```
7373

7474
This will scaffold the Memcached resource API under `pkg/apis/cache/v1alpha1/...`.
75+
7576
### Define the spec and status
77+
7678
Modify the spec and status of the `Memcached` Custom Resource(CR) at `pkg/apis/cache/v1alpha1/memcached_types.go`:
7779

7880
```Go
@@ -94,24 +96,26 @@ $ operator-sdk generate k8s
9496

9597
## Add a new Controller
9698

97-
Add a new Controller to the project that will watch and reconcile the Memcached resource:
98-
```
99+
Add a new [Controller][controller-go-doc] to the project that will watch and reconcile the Memcached resource:
100+
101+
```sh
99102
$ operator-sdk add controller --api-version=cache.example.com/v1alpha1 --kind=Memcached
100103
```
101-
This will scaffold a new Controller implementation under `pkg/controller/memcached/...`
102104

103-
For this example replace the generated controller file `pkg/controller/memcached/memcached_controller.go` with the example [memcached_controller.go][memcached_controller] implementation.
105+
This will scaffold a new Controller implementation under `pkg/controller/memcached/...`.
106+
107+
For this example replace the generated Controller file `pkg/controller/memcached/memcached_controller.go` with the example [memcached_controller.go][memcached_controller] implementation.
104108

105-
The example controller executes the following reconciliation logic for each `Memcached` CR:
109+
The example Controller executes the following reconciliation logic for each `Memcached` CR:
106110
- Create a memcached Deployment if it doesn't exist
107111
- Ensure that the Deployment size is the same as specified by the `Memcached` CR spec
108112
- Update the `Memcached` CR status with the names of the memcached pods
109113

110-
The next two subsections explain how the controller watches resources and how the reconcile loop is triggered. Skip to the [Build](#build-and-run-the-operator) section to see how to build and run the operator.
114+
The next two subsections explain how the Controller watches resources and how the reconcile loop is triggered. Skip to the [Build](#build-and-run-the-operator) section to see how to build and run the operator.
111115

112116
### Resources watched by the Controller
113117

114-
Inspect the controller implementation at `pkg/controller/memcached/memcached_controller.go` to see how the controller watches resources.
118+
Inspect the Controller implementation at `pkg/controller/memcached/memcached_controller.go` to see how the Controller watches resources.
115119

116120
The first watch is for the Memcached type as the primary resource. For each Add/Update/Delete event the reconcile loop will be sent a reconcile `Request` (a namespace/name key) for that Memcached object:
117121

@@ -135,7 +139,7 @@ err := c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequest
135139

136140
### Reconcile loop
137141

138-
Every controller has a Reconciler object with a `Reconcile()` method that implements the reconcile loop. The reconcile loop is passed the `Request` argument which is a Namespace/Name key used to lookup the primary resource object, Memcached, from the cache:
142+
Every Controller has a Reconciler object with a `Reconcile()` method that implements the reconcile loop. The reconcile loop is passed the [Request][request-go-doc] argument which is a Namespace/Name key used to lookup the primary resource object, Memcached, from the cache:
139143

140144
```Go
141145
func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Result, error) {
@@ -146,7 +150,8 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res
146150
}
147151
```
148152

149-
Based on the return value of `Reconcile()` the reconcile `Request` may be requeued and the loop may be triggered again:
153+
Based on the return values, [Result][result_go_doc] and error, the `Request` may be requeued and the reconcile loop may be triggered again:
154+
150155
```Go
151156
// Reconcile successful - don't requeue
152157
return reconcile.Result{}, nil
@@ -164,6 +169,8 @@ import "time"
164169
return reconcile.Result{RequeueAfter: time.Second*5}, nil
165170
```
166171

172+
**Note:** Returning `Result` with `RequeueAfter` set is how you can periodically reconcile a CR.
173+
167174
For a guide on Reconcilers, Clients, and interacting with resource Events, see the [Client API doc][doc_client_api].
168175

169176
## Build and run the operator
@@ -325,7 +332,9 @@ $ kubectl delete -f deploy/service_account.yaml
325332
```
326333

327334
## Advanced Topics
335+
328336
### Adding 3rd Party Resources To Your Operator
337+
329338
By default the operator's Manager will register all custom resource types defined in your project under `pkg/apis` with its scheme.
330339
```Go
331340
import (
@@ -340,7 +349,8 @@ if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
340349

341350
To add a 3rd party resource to an operator, you must add it to the Manager's scheme. By creating an `AddToScheme` method or reusing one you can easily add a resource to your scheme. An [example][deployments_register] shows that you define a function and then use the [runtime][runtime_package] package to create a `SchemeBuilder`.
342351

343-
#### Register with the manager's scheme
352+
#### Register with the Manager's scheme
353+
344354
Call the `AddToScheme()` function for your 3rd party resource and pass it the Manager's scheme via `mgr.GetScheme()`.
345355

346356
Example:
@@ -372,4 +382,7 @@ func main() {
372382
[deployments_register]: https://github.com/kubernetes/api/blob/master/apps/v1/register.go#L41
373383
[doc_client_api]:./user/client.md
374384
[runtime_package]: https://godoc.org/k8s.io/apimachinery/pkg/runtime
375-
[osdk_add_to_scheme]: https://github.com/operator-framework/operator-sdk/blob/4179b6ac459b2b0cb04ab3a1b438c280bd28d1a5/pkg/util/k8sutil/k8sutil.go#L67
385+
[manager_go_doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/manager#Manager
386+
[controller-go-doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg#hdr-Controller
387+
[request-go-doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/reconcile#Request
388+
[result_go_doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/reconcile#Result

0 commit comments

Comments
 (0)