This repository has been archived by the owner on Mar 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 740
operator: Add option to act as cluster wide #1777
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4a85ca9
Add option for operator to act as cluster wide
guilhem 06c9fd5
Do not report error when a cluster is ignored
guilhem ba95541
Add clusterwide cluster example
guilhem 38f7637
Use named return values
guilhem 1bc23a1
Mix examples
guilhem 605ef99
Explicit return and doc for handleClusterEvent
guilhem 8ebe2f1
Move constants to k8sutil
guilhem 2b2920b
Remove unused constants
guilhem 18c0731
Remove useless limitation section
guilhem e03e637
Command help rephrasing
guilhem a4f4b06
Clusterwide example
guilhem fd0e59b
handleClusterEvent help
guilhem cc6cd9e
Explicit return values for handleClusterEvent
guilhem 11ce31f
Fix relative link to example file
guilhem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
||
See the example in [example/example-etcd-cluster.yaml](example/example-etcd-cluster.yaml) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,33 @@ func New(cfg Config) *Controller { | |
} | ||
} | ||
|
||
func (c *Controller) handleClusterEvent(event *Event) error { | ||
// handleClusterEvent returns true if cluster is ignored (not managed) by this instance. | ||
func (c *Controller) handleClusterEvent(event *Event) (bool, 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 the returned value? 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. use named values instead (as you previously suggest :) ) |
||
clus := event.Object | ||
|
||
if !c.managed(clus) { | ||
return true, nil | ||
} | ||
|
||
if clus.Status.IsFailed() { | ||
clustersFailed.Inc() | ||
if event.Type == kwatch.Deleted { | ||
delete(c.clusters, clus.Name) | ||
return nil | ||
return false, nil | ||
} | ||
return fmt.Errorf("ignore failed cluster (%s). Please delete its CR", clus.Name) | ||
return false, fmt.Errorf("ignore failed cluster (%s). Please delete its CR", clus.Name) | ||
} | ||
|
||
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) | ||
return false, fmt.Errorf("invalid cluster spec. please fix the following problem with the cluster spec: %v", err) | ||
} | ||
|
||
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) | ||
return false, fmt.Errorf("unsafe state. cluster (%s) was created before but we received event (%s)", clus.Name, event.Type) | ||
} | ||
|
||
nc := cluster.New(c.makeClusterConfig(), clus) | ||
|
@@ -94,21 +100,21 @@ 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) | ||
return false, fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", clus.Name, event.Type) | ||
} | ||
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) | ||
return false, fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", clus.Name, event.Type) | ||
} | ||
c.clusters[clus.Name].Delete() | ||
delete(c.clusters, clus.Name) | ||
clustersDeleted.Inc() | ||
clustersTotal.Dec() | ||
} | ||
return nil | ||
return false, nil | ||
} | ||
|
||
func (c *Controller) makeClusterConfig() cluster.Config { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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.