-
Notifications
You must be signed in to change notification settings - Fork 741
operator: Add option to act as cluster wide #1777
Changes from 4 commits
4a85ca9
06c9fd5
ba95541
38f7637
1bc23a1
605ef99
8ebe2f1
2b2920b
18c0731
e03e637
a4f4b06
fd0e59b
cc6cd9e
11ce31f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,8 @@ var ( | |
printVersion bool | ||
|
||
createCRD bool | ||
|
||
clusterWide bool | ||
) | ||
|
||
func init() { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Avoid the word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for this link :) |
||
flag.Parse() | ||
} | ||
|
||
|
@@ -151,6 +154,7 @@ func newControllerConfig() controller.Config { | |
|
||
cfg := controller.Config{ | ||
Namespace: namespace, | ||
ClusterWide: clusterWide, | ||
ServiceAccount: serviceAccount, | ||
KubeCli: kubecli, | ||
KubeExtCli: k8sutil.MustNewKubeExtClient(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Manage clusters in all namespaces | ||
|
||
Default etcd operator behavior is to only manage etcd clusters created in the same namespace. | ||
It is possible to deploy an etcd operator with special option to manage clusterwide etcd clusters. | ||
|
||
## Install etcd operator | ||
|
||
etcd operator have to run with `-cluster-wide` arg option. | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Probably not use a header?
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @fanminshi hehe was in another batch ;) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: "etcd.database.coreos.com/v1beta2" | ||
kind: "EtcdCluster" | ||
metadata: | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we combine this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops my bad, was what I wanted to do |
||
etcd.database.coreos.com/scope: clusterwide | ||
spec: | ||
size: 3 | ||
version: "3.2.13" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ type Controller struct { | |
|
||
type Config struct { | ||
Namespace string | ||
ClusterWide bool | ||
ServiceAccount string | ||
KubeCli kubernetes.Interface | ||
KubeExtCli apiextensionsclient.Interface | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. add a comment for this func what returned values are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I wasn't clear before.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hehe no problem :) |
||
clus := event.Object | ||
|
||
if !c.managed(clus) { | ||
ignored = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer explicit return value:
|
||
return | ||
} | ||
ignored = false | ||
|
||
if clus.Status.IsFailed() { | ||
clustersFailed.Inc() | ||
if event.Type == kwatch.Deleted { | ||
delete(c.clusters, clus.Name) | ||
return nil | ||
return | ||
} | ||
return fmt.Errorf("ignore failed cluster (%s). Please delete its CR", clus.Name) | ||
err = fmt.Errorf("ignore failed cluster (%s). Please delete its CR", clus.Name) | ||
return | ||
} | ||
|
||
clus.SetDefaults() | ||
|
||
if err := clus.Spec.Validate(); err != nil { | ||
return fmt.Errorf("invalid cluster spec. please fix the following problem with the cluster spec: %v", err) | ||
if e := clus.Spec.Validate(); e != nil { | ||
err = fmt.Errorf("invalid cluster spec. please fix the following problem with the cluster spec: %v", err) | ||
return | ||
} | ||
|
||
switch event.Type { | ||
case kwatch.Added: | ||
if _, ok := c.clusters[clus.Name]; ok { | ||
return fmt.Errorf("unsafe state. cluster (%s) was created before but we received event (%s)", clus.Name, event.Type) | ||
err = fmt.Errorf("unsafe state. cluster (%s) was created before but we received event (%s)", clus.Name, event.Type) | ||
return | ||
} | ||
|
||
nc := cluster.New(c.makeClusterConfig(), clus) | ||
|
@@ -94,21 +104,23 @@ func (c *Controller) handleClusterEvent(event *Event) error { | |
|
||
case kwatch.Modified: | ||
if _, ok := c.clusters[clus.Name]; !ok { | ||
return fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", clus.Name, event.Type) | ||
err = fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", clus.Name, event.Type) | ||
return | ||
} | ||
c.clusters[clus.Name].Update(clus) | ||
clustersModified.Inc() | ||
|
||
case kwatch.Deleted: | ||
if _, ok := c.clusters[clus.Name]; !ok { | ||
return fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", clus.Name, event.Type) | ||
err = fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", clus.Name, event.Type) | ||
return | ||
} | ||
c.clusters[clus.Name].Delete() | ||
delete(c.clusters, clus.Name) | ||
clustersDeleted.Inc() | ||
clustersTotal.Dec() | ||
} | ||
return nil | ||
return | ||
} | ||
|
||
func (c *Controller) makeClusterConfig() cluster.Config { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Can you also move these const into k8sutil: We want to get rid of this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
AnnotationClusterWide = "clusterwide" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
) |
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.