-
Notifications
You must be signed in to change notification settings - Fork 740
operator: Add option to act as cluster wide #1777
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cluster-wide?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done :)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this EnvRestoreOperatorServiceName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, bad merge
6065fd2
to
d06117a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flag should be "cluster-wide"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -64,6 +65,10 @@ func New(cfg Config) *Controller { | |||
func (c *Controller) handleClusterEvent(event *Event) error { | |||
clus := event.Object | |||
|
|||
if !c.managed(clus) { | |||
return fmt.Errorf("cluster (%s) isn't managed", clus.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will introduce unnecessary errors/warnings in the log for unmanaged EtcdCluster CRs. Should just ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this func return (ignored bool, err error)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/controller/controller.go
Outdated
@@ -61,28 +62,32 @@ func New(cfg Config) *Controller { | |||
} | |||
} | |||
|
|||
func (c *Controller) handleClusterEvent(event *Event) error { | |||
func (c *Controller) handleClusterEvent(event *Event) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment for the returned value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine this to example-etcd-cluster.yaml
and add a comment for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops my bad, was what I wanted to do
pkg/controller/controller.go
Outdated
@@ -61,28 +62,37 @@ func New(cfg Config) *Controller { | |||
} | |||
} | |||
|
|||
func (c *Controller) handleClusterEvent(event *Event) error { | |||
func (c *Controller) handleClusterEvent(event *Event) (ignored bool, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer explicit return value:
return true, nil
pkg/util/constants/constants.go
Outdated
@@ -30,4 +30,7 @@ const ( | |||
|
|||
EnvOperatorPodName = "MY_POD_NAME" | |||
EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | |||
|
|||
AnnotationScope = "etcd.database.coreos.com/scope" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove AnnotationScope
?
@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
|
||
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably no need to have Limitations
section if it is blank.
cmd/operator/main.go
Outdated
@@ -66,6 +68,7 @@ func init() { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this link :)
pkg/util/constants/constants.go
Outdated
@@ -30,4 +30,7 @@ const ( | |||
|
|||
EnvOperatorPodName = "MY_POD_NAME" | |||
EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | |||
|
|||
AnnotationScope = "etcd.database.coreos.com/scope" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove AnnotationScope
?
pkg/util/constants/constants.go
Outdated
@@ -30,4 +30,7 @@ const ( | |||
|
|||
EnvOperatorPodName = "MY_POD_NAME" | |||
EnvOperatorPodNamespace = "MY_POD_NAMESPACE" | |||
|
|||
AnnotationScope = "etcd.database.coreos.com/scope" | |||
AnnotationClusterWide = "clusterwide" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not use a header?
Add a sentence:
See the example in ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guilhem fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fanminshi hehe was in another batch ;)
pkg/controller/controller.go
Outdated
@@ -61,28 +62,37 @@ func New(cfg Config) *Controller { | |||
} | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returns ignored true if cluster is ignored (not managed) by this instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guilhem fix this?
pkg/controller/controller.go
Outdated
@@ -61,28 +62,37 @@ func New(cfg Config) *Controller { | |||
} | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe no problem :)
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Should be
[example/example-etcd-cluster.yaml](../../example/example-etcd-cluster.yaml)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying with ../../
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: clusterwide
And 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.