Skip to content

Commit a984491

Browse files
authored
doc: clean up README and user-guide (#661)
1 parent 5a9f7d1 commit a984491

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,44 @@
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 which means that there are still new features and APIs planned that will be added in the future. Due to this breaking changes may still happen.
88

9-
See the [design docs][design_docs] for planned work on upcoming milestones.
9+
**Note:** The core APIs provided by the [controller-runtime][controller_runtime] will most likely stay unchanged however the expectation is that any breaking changes should be relatively minor and easier to handle than the changes from SDK `v0.0.7` to `v0.1.0`.
10+
11+
See the [proposal docs][proposals_docs] and issues for ongoing or planned work.
1012

1113
## Overview
1214

1315
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].
1416

1517
[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.
1618

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

2224
## Workflow
2325

24-
The SDK provides the following workflow to develop a new operator:
26+
The SDK provides workflows to develop operators in Go or Ansible.
27+
28+
The following workflow is for a new Go operator:
2529
1. Create a new operator project using the SDK Command Line Interface(CLI)
2630
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
31+
3. Define Controllers to watch and reconcile resources
32+
4. Write the reconciling logic for your Controller using the SDK and controller-runtime APIs
2933
5. Use the SDK CLI to build and generate the operator deployment manifests
3034

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-
3335
## Prerequisites
3436

3537
- [dep][dep_tool] version v0.5.0+.
3638
- [git][git_tool]
3739
- [go][go_tool] version v1.10+.
3840
- [docker][docker_tool] version 17.03+.
39-
- [kubectl][kubectl_tool] version v1.10.0+.
40-
- Access to a kubernetes v.1.10.0+ cluster.
41+
- [kubectl][kubectl_tool] version v1.11.0+.
42+
- Access to a kubernetes v.1.11.0+ cluster.
4143

4244
## Quick Start
4345

@@ -104,9 +106,11 @@ $ kubectl delete -f deploy/service_account.yaml
104106
$ kubectl delete -f deploy/crds/app_v1alpha1_appservice_crd.yaml
105107
```
106108

107-
## User Guide
109+
## User Guides
110+
111+
To learn more about the writing an operator in Go, see the [user guide][guide].
108112

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

111115
## Samples
112116

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

127131
[operator_link]: https://coreos.com/operators/
128-
[design_docs]: ./doc/design
132+
[proposals_docs]: ./doc/proposals
129133
[guide]: ./doc/user-guide.md
130134
[samples]: https://github.com/operator-framework/operator-sdk-samples
131135
[of-home]: https://github.com/operator-framework
@@ -138,3 +142,5 @@ Operator SDK is under Apache 2.0 license. See the [LICENSE][license_file] file f
138142
[go_tool]:https://golang.org/dl/
139143
[docker_tool]:https://docs.docker.com/install/
140144
[kubectl_tool]:https://kubernetes.io/docs/tasks/tools/install-kubectl/
145+
[controller_runtime]: https://github.com/kubernetes-sigs/controller-runtime
146+
[ansible_user_guide]:./ansible/user-guide.md

doc/user-guide.md

Lines changed: 30 additions & 19 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,18 +61,18 @@ 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)
65-
6664
## Add a new Custom Resource Definition
6765

68-
Add a new Custom Resource Defintion(CRD) API called Memcached, with APIVersion `cache.example.com/v1apha1` and Kind `Memcached`.
66+
Add a new Custom Resource Definition(CRD) API called Memcached, with APIVersion `cache.example.com/v1apha1` and Kind `Memcached`.
6967

7068
```sh
7169
$ operator-sdk add api --api-version=cache.example.com/v1alpha1 --kind=Memcached
7270
```
7371

7472
This will scaffold the Memcached resource API under `pkg/apis/cache/v1alpha1/...`.
73+
7574
### Define the spec and status
75+
7676
Modify the spec and status of the `Memcached` Custom Resource(CR) at `pkg/apis/cache/v1alpha1/memcached_types.go`:
7777

7878
```Go
@@ -94,24 +94,26 @@ $ operator-sdk generate k8s
9494

9595
## Add a new Controller
9696

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

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

105-
The example controller executes the following reconciliation logic for each `Memcached` CR:
105+
For this example replace the generated Controller file `pkg/controller/memcached/memcached_controller.go` with the example [`memcached_controller.go`][memcached_controller] implementation.
106+
107+
The example Controller executes the following reconciliation logic for each `Memcached` CR:
106108
- Create a memcached Deployment if it doesn't exist
107109
- Ensure that the Deployment size is the same as specified by the `Memcached` CR spec
108110
- Update the `Memcached` CR status with the names of the memcached pods
109111

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.
112+
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.
111113

112114
### Resources watched by the Controller
113115

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

116118
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:
117119

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

136138
### Reconcile loop
137139

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:
140+
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:
139141

140142
```Go
141143
func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Result, error) {
@@ -146,7 +148,8 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res
146148
}
147149
```
148150

149-
Based on the return value of `Reconcile()` the reconcile `Request` may be requeued and the loop may be triggered again:
151+
Based on the return values, [`Result`][result_go_doc] and error, the `Request` may be requeued and the reconcile loop may be triggered again:
152+
150153
```Go
151154
// Reconcile successful - don't requeue
152155
return reconcile.Result{}, nil
@@ -164,6 +167,8 @@ import "time"
164167
return reconcile.Result{RequeueAfter: time.Second*5}, nil
165168
```
166169

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

169174
## Build and run the operator
@@ -325,7 +330,9 @@ $ kubectl delete -f deploy/service_account.yaml
325330
```
326331

327332
## Advanced Topics
333+
328334
### Adding 3rd Party Resources To Your Operator
335+
329336
By default the operator's Manager will register all custom resource types defined in your project under `pkg/apis` with its scheme.
330337
```Go
331338
import (
@@ -340,7 +347,8 @@ if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
340347

341348
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`.
342349

343-
#### Register with the manager's scheme
350+
#### Register with the Manager's scheme
351+
344352
Call the `AddToScheme()` function for your 3rd party resource and pass it the Manager's scheme via `mgr.GetScheme()`.
345353

346354
Example:
@@ -372,4 +380,7 @@ func main() {
372380
[deployments_register]: https://github.com/kubernetes/api/blob/master/apps/v1/register.go#L41
373381
[doc_client_api]:./user/client.md
374382
[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
383+
[manager_go_doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/manager#Manager
384+
[controller-go-doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg#hdr-Controller
385+
[request-go-doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/reconcile#Request
386+
[result_go_doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/reconcile#Result

0 commit comments

Comments
 (0)