You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -28,48 +28,44 @@ Then, in your controller, you can use [`Conditions`][godoc-conditions] methods t
28
28
29
29
### Adding 3rd Party Resources To Your Operator
30
30
31
-
> **// TODO:** Update the `main.go` code in these sections to use the `init()` func to register the scheme instead of doing it in `main()`.
32
31
33
32
The operator's Manager supports the core Kubernetes resource types as found in the client-go [scheme][scheme_package] package and will also register the schemes of all custom resource types defined in your project.
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`.
49
49
50
50
#### Register with the Manager's scheme
51
51
52
-
Call the `AddToScheme()` function for your 3rd party resource and pass it the Manager's scheme via `mgr.GetScheme()`
53
-
in `cmd/manager/main.go`.
54
-
52
+
Call the `AddToScheme()` function for your 3rd party resource and pass it the Manager's scheme via `mgr.GetScheme()` in `main.go`.
if err := schemeBuilder.AddToScheme(mgr.GetScheme()); err != nil {
97
+
log.Error(err, "")
98
+
os.Exit(1)
99
+
}
104
100
105
-
...
101
+
...
106
102
}
107
103
```
108
104
@@ -115,18 +111,11 @@ func main() {
115
111
116
112
### Metrics
117
113
118
-
> **// TODO:** Update the [metrics doc](https://github.com/operator-framework/operator-sdk/blob/master/website/content/en/docs/golang/metrics/operator-sdk-monitoring.md) since it doesn't match the default scaffolded by kubebuilder anymore.
119
-
120
-
To learn about how metrics work in the Operator SDK read the [metrics section][metrics_doc] of the user documentation.
121
-
122
-
#### Default Metrics exported with 3rd party resource
114
+
To learn about how metrics work in the Operator SDK read the [metrics section][metrics_doc] of the Kubebuilder documentation.
123
115
124
-
> **// TODO:** Remove this section since we're no longer scaffolding main.go to use the SDK's `GenerateAndServeCRMetrics()` util in `pkg/kube-metrics`.
125
116
126
117
### Handle Cleanup on Deletion
127
118
128
-
> **// TODO:** Update finalizer reconcile code for kubebuilder's default reconciler imports and variable names
129
-
130
119
To implement complex deletion logic, you can add a finalizer to your Custom Resource. This will prevent your Custom Resource from being
131
120
deleted until you remove the finalizer (ie, after your cleanup logic has successfully run). For more information, see the
132
121
[official Kubernetes documentation on finalizers](https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#finalizers).
@@ -137,105 +126,104 @@ The following is a snippet from the controller file under `pkg/controller/memcac
reqLogger.Error(err, "Failed to update Memcached with finalizer")
210
+
return err
211
+
}
212
+
return nil
223
213
}
224
214
225
215
func contains(list []string, s string) bool {
226
-
for_, v:=range list {
227
-
if v == s {
228
-
returntrue
229
-
}
230
-
}
231
-
returnfalse
216
+
for _, v := range list {
217
+
if v == s {
218
+
return true
219
+
}
220
+
}
221
+
return false
232
222
}
233
223
```
234
224
235
225
### Leader election
236
226
237
-
> **// TODO:** Update this section to remove `leader-for-life` option? Since it's no longer the default.
238
-
239
227
During the lifecycle of an operator it's possible that there may be more than 1 instance running at any given time e.g when rolling out an upgrade for the operator.
240
228
In such a scenario it is necessary to avoid contention between multiple operator instances via leader election so that only one leader instance handles the reconciliation while the other instances are inactive but ready to take over when the leader steps down.
241
229
@@ -254,18 +242,18 @@ A call to `leader.Become()` will block the operator as it retries until it can b
If the operator is not running inside a cluster `leader.Become()` will simply return without error to skip the leader election since it can't detect the operator's namespace.
@@ -276,19 +264,19 @@ The leader-with-lease approach can be enabled via the [Manager Options][manager_
276
264
277
265
```Go
278
266
import (
279
-
...
280
-
"sigs.k8s.io/controller-runtime/pkg/manager"
267
+
...
268
+
"sigs.k8s.io/controller-runtime/pkg/manager"
281
269
)
282
270
283
271
func main() {
284
-
...
285
-
opts:= manager.Options{
286
272
...
287
-
LeaderElection: true,
288
-
LeaderElectionID: "memcached-operator-lock"
289
-
}
290
-
mgr, err:= manager.New(cfg, opts)
291
-
...
273
+
opts := manager.Options{
274
+
...
275
+
LeaderElection: true,
276
+
LeaderElectionID: "memcached-operator-lock"
277
+
}
278
+
mgr, err := manager.New(cfg, opts)
279
+
...
292
280
}
293
281
```
294
282
@@ -300,9 +288,9 @@ When the operator is not running in a cluster, the Manager will return an error
0 commit comments