operator: Add option to act as cluster wide#1777
operator: Add option to act as cluster wide#1777hongchaodeng merged 14 commits intocoreos:masterfrom
Conversation
|
Can one of the admins verify this patch? |
1 similar comment
|
Can one of the admins verify this patch? |
|
JFYI: a docker image exist with this patch |
|
The idea seems fine. But we need to add tests and related documentation to move this forward. |
|
Good to know! :) |
|
Out of curiosity, what is your use case of having a cluster wide etcd operator? Why a per namespace one will not work for you? |
|
I want to save resources (pod/memory/watchers in API) and operations when having a lot of namespaces. |
|
My main concern is were to put configuration:
|
|
@raoofm just want to avoid having to manage many etcdoperators |
ad657e7 to
dde9475
Compare
|
@xiang90 I added some tests and documentation. |
|
@etcd-bot ok to test |
|
I know news are quite huge... |
|
The idea looks good for me. Defer to @hongchaodeng or @fanminshi or @hasbro17 for a actual code review. |
example/deployment-clusterwide.yaml
Outdated
| image: quay.io/coreos/etcd-operator:v0.8.1 | ||
| command: | ||
| - etcd-operator | ||
| - -all-namespaces |
pkg/util/constants/constants.go
Outdated
| EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | ||
| EnvOperatorPodName = "MY_POD_NAME" | ||
| EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | ||
| EnvRestoreOperatorServiceName = "SERVICE_ADDR" |
There was a problem hiding this comment.
remove this EnvRestoreOperatorServiceName
6065fd2 to
d06117a
Compare
hongchaodeng
left a comment
There was a problem hiding this comment.
Sorry for the review delay.
When you have change, please ping me on github.
doc/user/clusterwide.md
Outdated
|
|
||
| ## Install etcd operator | ||
|
|
||
| etcd operator have to run with `-all-namespaces` arg option. |
There was a problem hiding this comment.
flag should be "cluster-wide"?
There was a problem hiding this comment.
I try to be like kubectl option --all-namespaces=false.
But I wasn't really happy with this solution and will change it to cluster-wide :)
doc/user/clusterwide.md
Outdated
|
|
||
| etcd operator have to run with `-all-namespaces` arg option. | ||
|
|
||
| For example you can run: |
There was a problem hiding this comment.
There is no need to mention the command and install guide here.
Just give a reference to the file.
example/deployment-clusterwide.yaml
Outdated
| apiVersion: extensions/v1beta1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: etcd-operator-cluster-wide |
There was a problem hiding this comment.
There is too much duplicate and it is just hard to maintain for every upgrade.
I would recommend to add a comment to existing deployment file: https://github.com/coreos/etcd-operator/blob/master/example/deployment.yaml
pkg/controller/controller.go
Outdated
| clus := event.Object | ||
|
|
||
| if !c.managed(clus) { | ||
| return fmt.Errorf("cluster (%s) isn't managed", clus.Name) |
There was a problem hiding this comment.
This will introduce unnecessary errors/warnings in the log for unmanaged EtcdCluster CRs. Should just ignore it.
There was a problem hiding this comment.
Make this func return (ignored bool, err error) ?
There was a problem hiding this comment.
@hongchaodeng tell me if my last commit is ok for you.
I will rebase if ok.
|
Test failed: |
doc/user/clusterwide.md
Outdated
| kind: "EtcdCluster" | ||
| metadata: | ||
| name: "example-etcd-cluster" | ||
| annotations: |
There was a problem hiding this comment.
Can you add the comment in example file for this annotation instead of here?
We have plans to show the code files in the doc later: #1904
| } | ||
|
|
||
| func (c *Controller) handleClusterEvent(event *Event) error { | ||
| func (c *Controller) handleClusterEvent(event *Event) (bool, error) { |
There was a problem hiding this comment.
add a comment for the returned value?
There was a problem hiding this comment.
use named values instead (as you previously suggest :) )
|
Can you also rebase against master? Your commit is too old. |
|
I don't know what you say😂😂 |
|
Which part you don't understand? |
hongchaodeng
left a comment
There was a problem hiding this comment.
CI failed due to unknown issue:
denied: Access denied.
| name: "example-etcd-cluster" | ||
| # Adding this annotation make this cluster managed by clusterwide operators | ||
| # namespaced operators ignore it | ||
| annotations: |
There was a problem hiding this comment.
Can we combine this to example-etcd-cluster.yaml and add a comment for this?
There was a problem hiding this comment.
oops my bad, was what I wanted to do
pkg/controller/controller.go
Outdated
| } | ||
|
|
||
| func (c *Controller) handleClusterEvent(event *Event) error { | ||
| func (c *Controller) handleClusterEvent(event *Event) (ignored bool, err error) { |
There was a problem hiding this comment.
add a comment for this func what returned values are
pkg/controller/controller.go
Outdated
| clus := event.Object | ||
|
|
||
| if !c.managed(clus) { | ||
| ignored = true |
There was a problem hiding this comment.
Prefer explicit return value:
return true, nil
pkg/util/constants/constants.go
Outdated
| EnvOperatorPodName = "MY_POD_NAME" | ||
| EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | ||
|
|
||
| AnnotationScope = "etcd.database.coreos.com/scope" |
There was a problem hiding this comment.
Can you also move these const into k8sutil:
https://github.com/coreos/etcd-operator/blob/master/pkg/util/k8sutil/k8sutil.go#L46
We want to get rid of this file.
|
@hongchaodeng any news about why tests are failing? |
|
via https://jenkins-etcd-public.prod.coreos.systems/job/etcd-operator/3228/ |
|
@etcd-bot re-test this please reason: build image not found might due to jenkin flake. |
|
@guilhem have you rebase this pr on top of the latest master? |
|
@fanminshi yes :/ |
|
@guilhem test passed. :) |
README.md
Outdated
| See [instructions on clusterwide feature](doc/user/clusterwide.md). | ||
|
|
||
| - The etcd operator only manages the etcd cluster created in the same namespace. Users need to create multiple operators in different namespaces to manage etcd clusters in different namespaces. | ||
| ### Limitations |
There was a problem hiding this comment.
probably no need to have Limitations section if it is blank.
cmd/operator/main.go
Outdated
| flag.BoolVar(&printVersion, "version", false, "Show version and quit") | ||
| flag.BoolVar(&createCRD, "create-crd", true, "The operator will not create the EtcdCluster CRD when this flag is set to false.") | ||
| flag.DurationVar(&gcInterval, "gc-interval", 10*time.Minute, "GC interval") | ||
| flag.BoolVar(&clusterWide, "cluster-wide", false, "The operator will watch clusters in all namespaces") |
There was a problem hiding this comment.
The operator will watch clusters in all namespaces => Enable operator to watch clusters in all namespaces?
Avoid the word Will ref: https://developers.google.com/style/tense
There was a problem hiding this comment.
thanks for this link :)
pkg/util/constants/constants.go
Outdated
| EnvOperatorPodName = "MY_POD_NAME" | ||
| EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | ||
|
|
||
| AnnotationScope = "etcd.database.coreos.com/scope" |
pkg/util/constants/constants.go
Outdated
| EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | ||
|
|
||
| AnnotationScope = "etcd.database.coreos.com/scope" | ||
| AnnotationClusterWide = "clusterwide" |
There was a problem hiding this comment.
remove AnnotationClusterWide?
doc/user/clusterwide.md
Outdated
|
|
||
| More information in [install guide](doc/user/install_guide.md). | ||
|
|
||
| ## [Cluster resource example](example/example-etcd-cluster-clusterwide.yaml) |
There was a problem hiding this comment.
Probably not use a header?
Add a sentence:
See the example in ...
pkg/controller/controller.go
Outdated
| } | ||
|
|
||
| func (c *Controller) handleClusterEvent(event *Event) error { | ||
| // handleClusterEvent returns ignored true if cluster isn't managed by this instance. |
There was a problem hiding this comment.
returns ignored true if cluster is ignored (not managed) by this instance.
pkg/controller/controller.go
Outdated
|
|
||
| func (c *Controller) handleClusterEvent(event *Event) error { | ||
| // handleClusterEvent returns ignored true if cluster isn't managed by this instance. | ||
| func (c *Controller) handleClusterEvent(event *Event) (ignored bool, err error) { |
There was a problem hiding this comment.
Sorry I wasn't clear before.
Prefer ALL returns to be explicit about return values.
handleClusterEvent(event *Event) (bool, error) {
...
return false, nil
...
return false, fmt.Errorf(...)
|
@guilhem Thanks for your patience and persistence. Only a few minor comments. Overall it looks good. |
|
I "think" I fixed your comments :) If all is ok, I will squash all my PR to have something clean ;) |
Thanks again for your patience.
No worries. We will do squash when we merge. |
|
LGTM |
doc/user/clusterwide.md
Outdated
|
|
||
| More information in [install guide](doc/user/install_guide.md). | ||
|
|
||
| See the example in [example/example-etcd-cluster.yaml](example/example-etcd-cluster.yaml) |
There was a problem hiding this comment.
the link in [example/example-etcd-cluster.yaml](example/example-etcd-cluster.yaml) doesn't work. you might want to try ~~~[example/example-etcd-cluster.yaml](../../blob/master/example/example-etcd-cluster.yaml)~~~
edit: use [example/example-etcd-cluster.yaml](../../example/example-etcd-cluster.yaml)
There was a problem hiding this comment.
Right. Should be
[example/example-etcd-cluster.yaml](../../example/example-etcd-cluster.yaml)
There was a problem hiding this comment.
@hongchaodeng ~~~this [example/example-etcd-cluster.yaml](../../example/example-etcd-cluster.yaml) didn't work for me.~~~
edit: use [example/example-etcd-cluster.yaml](../../example/example-etcd-cluster.yaml)
There was a problem hiding this comment.
I'm trying with ../../
There was a problem hiding this comment.
yeah, ../../ is the right approach.
|
lgtm |
|
Last thing you may add is a "BETA" mention in cmd help. But you can do it directly on my own branch, feel free ;) |
|
🎉 👍 Thank you all :) |
for a cluster to be managed widely, user have to add annotation:
etcd.database.coreos.com/scope: clusterwideAnd admin have to run an operator with option
-cluster-wide.Current implementation have a lack of locking if many operators with cluster-wide run on different namespaces.