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
Currently controllers that use `controller-runtime` need to configure the `ctrl.Manager` by using flags or hard coding values into the initialization methods. Core Kubernetes has started to move away from using flags as a mechanism for configuring components and standardized along the pattern of [`ComponentConfig` or Versioned Component Configuration Files](https://docs.google.com/document/d/1FdaEJUEh091qf5B98HM6_8MS764iXrxxigNIdwHYW9c/edit). This proposal is to bring `ComponentConfig` patterns into `controller-runtime` to allow controller authors to make `go` types backed by apimachinery to unmarshal and configure the `ctrl.Manager` reducing the flags and allowing code based tools to easily configure controllers instead of requiring them to mutate CLI args.
34
+
Currently controllers that use `controller-runtime` need to configure the `ctrl.Manager` by using flags or hardcoding values into the initialization methods. Core Kubernetes has started to move away from using flags as a mechanism for configuring components and standardized along the pattern of [`ComponentConfig` or Versioned Component Configuration Files](https://docs.google.com/document/d/1FdaEJUEh091qf5B98HM6_8MS764iXrxxigNIdwHYW9c/edit). This proposal is to bring `ComponentConfig` patterns into `controller-runtime` to allow controller authors to make `go` types backed by `apimachinery` to unmarshal and configure the `ctrl.Manager` reducing the flags and allowing code based tools to easily configure controllers instead of requiring them to mutate CLI args.
32
35
33
36
34
37
## Motivation
35
38
36
39
This change is important because:
37
40
- it will help make it easier for controllers to be configured by other machine processes
38
-
- it will reduce the upfront flags required to start a controller
41
+
- it will reduce the required flags required to start a controller
39
42
- allow for more configuration types which flags don't natively support
40
43
- allow using and upgrading older configurations avoiding breaking changes in flags
41
44
42
45
### Links to Open Issues
43
46
44
-
-[Provide a ComponentConfig to tweak the Manager](https://github.com/kubernetes-sigs/controller-runtime/issues/518)
45
-
-[Reduce command line flag boilerplate](https://github.com/kubernetes-sigs/controller-runtime/issues/207)
46
-
-[Implement ComponentConfig by default & stop using (most) flags](https://github.com/kubernetes-sigs/kubebuilder/issues/722)
47
+
-[#518Provide a ComponentConfig to tweak the Manager](https://github.com/kubernetes-sigs/controller-runtime/issues/518)
48
+
-[#207Reduce command line flag boilerplate](https://github.com/kubernetes-sigs/controller-runtime/issues/207)
49
+
-[#722Implement ComponentConfig by default & stop using (most) flags](https://github.com/kubernetes-sigs/kubebuilder/issues/722)
47
50
48
51
### Goals
49
52
50
53
- Provide an interface for pulling configuration data out of exposed `ComponentConfig` types (see below for implementation)
51
54
- Provide a new `ctrl.NewFromComponentConfig()` function for initializing a manager
55
+
- Provide a `DefaultControllerConfig` to make the switch easier
52
56
53
57
### Non-Goals/Future Work
54
58
55
59
-`kubebuilder` implementation and design in another PR
56
60
- Changing the default `controller-runtime` implementation
To enable `controller-runtime` to have a default `ComponentConfig` struct which can be used instead of requiring each controller or extension to build it's own `ComponentConfig` type, we can create a `DefaultControllerConfiguration` type which can exist in `pkg/api/v1alpha1/types.go`. This will allow the controller authors to use this before needing to implement their own type with additional configs.
This would allow a controller author to use this struct with any config that supports the json/yaml structure. For example a controller author could define their `Kind` as `FoobarControllerConfiguration` and have it defined as the following.
166
+
167
+
```yaml
168
+
# config.yaml
169
+
apiVersion: somedomain.io/v1alpha1
170
+
kind: FoobarControllerConfiguration
171
+
spec:
172
+
port: 9443
173
+
metricsBindAddress: ":8080"
174
+
leaderElection:
175
+
leaderElect: false
176
+
```
177
+
178
+
Given the following config and `DefaultControllerConfiguration` we'd be able to initialize the controller using the following.
The above example uses `config.yaml` which is the name of the file to load the configuration bytes from and uses `codecs` to pass in the specific serializers, eg `serializer.NewCodecFactory(scheme)`. This will allow the configuration to be unmarshalled into the `runtime.Object` type and passed into the
194
+
`ctrl.NewManagerFromComponentConfig()`as a `ManagerConfiguration` interface.
195
+
196
+
##### Caveats
197
+
198
+
> ⚠️ Using `DecodeComponentConfigFileInto` does not support the overrides for flags, this is something that is left up to the controller author since they could be using many different flagging interfaces. eg [`flag`](https://golang.org/pkg/flag/), [`pflag`](https://godoc.org/github.com/spf13/pflag), [`flagnum`](https://godoc.org/github.com/luci/luci-go/common/flag/flagenum) and `controller-runtime` should be agnostic to the CLI implementation.
199
+
200
+
#### Kubebuilder Scaffolding Example
201
+
114
202
Within a separate design (link once created) this will require controller authors to generate a type that implements the `ManagerConfiguration` interface. The following is a sample of what this looks like:
@@ -194,29 +273,29 @@ func (in *ControllerNameConfiguration) GetCertDir() string {}
194
273
195
274
Besides the implementation of the `ComponentConfig` The controller author as it stands would also need to implement the unmarshalling of the `ConfigMap` into the `ComponentConfig`, for this `controller-runtime` could expose helper methods to load a file from disk, unmarshal to the struct and pass the pointer into the `NewFromComponentConfig()` to return the `ctrl.Manager`
196
275
197
-
###User Stories
276
+
## User Stories
198
277
199
-
####Controller Author with `controller-runtime`
278
+
### Controller Author with `controller-runtime`
200
279
201
280
- Implement `ComponentConfig` type
202
281
- Implement `ManagerConfiguration` interface for `ComponentConfig` object
203
282
- Set up `ConfigMap` unmarshalling into `ComponentConfig` type
204
283
- Initialize `ctrl.Manager` with `NewFromComponentConfig`
205
284
- Build custom controller as usual
206
285
207
-
####Controller Author with `kubebuilder` (tbd proposal for `kubebuilder`)
286
+
### Controller Author with `kubebuilder` (tbd proposal for `kubebuilder`)
208
287
209
288
- Initialize `kubebuilder` project using `--component-config-name=XYZConfiguration`
210
289
- Build custom controller as usual
211
290
212
-
####Controller User without modifications to config
291
+
### Controller User without modifications to config
213
292
214
293
_Provided that the controller provides manifests_
215
294
216
295
- Apply the controller to the cluster
217
296
- Deploy custom resources
218
297
219
-
####Controller User with modifications to config
298
+
### Controller User with modifications to config
220
299
221
300
-_Following from previous example without changes_
222
301
- Create a new `ConfigMap` for changes
@@ -225,19 +304,19 @@ _Provided that the controller provides manifests_
225
304
- Deploy custom resources
226
305
227
306
228
-
###Risks and Mitigations
307
+
## Risks and Mitigations
229
308
230
309
- Given that this isn't changing the core Manager initialization for `controller-runtime` it's fairly low risk
231
-
- If the underlaying `ctrl.Options{}`
232
310
233
311
## Alternatives
234
312
235
-
*`NewFromComponentConfig()` could load the object from disk and hydrate the `ComponentConfig` type
313
+
*`NewFromComponentConfig()` could load the object from disk based on the file name and hydrate the `ComponentConfig` type.
236
314
237
315
## Implementation History
238
316
239
317
-[x] 02/19/2020: Proposed idea in an issue or [community meeting]
240
318
-[x] 02/24/2020: Proposal submitted to `controller-runtime`
319
+
-[x] 03/02/2020: Updated with default `DefaultControllerConfiguration`
0 commit comments