Skip to content

Support multiple namespaces#666

Merged
frouioui merged 17 commits intomainfrom
multiple-namespaces
Mar 10, 2025
Merged

Support multiple namespaces#666
frouioui merged 17 commits intomainfrom
multiple-namespaces

Conversation

@frouioui
Copy link
Copy Markdown
Member

@frouioui frouioui commented Feb 28, 2025

Context

Over the last few years, we have received several reports (#236 and #8172) from people saying that the vitess-operator does not support multiple namespaces. Meaning, the operator only works when both the operator pod and the Vitess cluster are in the same K8S namespace.

The vitess-operator, like other Kubernetes operators built with the Operator SDK, uses the built-in WATCH_NAMESPACE environment variable to determine which namespaces to observe and manage. According to the Operator SDK documentation (docs), this variable accepts a comma-separated list of namespaces. Note that this detail is not explicitly documented in the vitess-operator documentation or the example scripts we provide, as this behavior is inherited from how Kubernetes operators work.

We know the operator already sees and manages multiple namespaces thanks to WATCH_NAMESPACE, the rest of the code was also written in a way where every resources inside a VitessCluster inherit the same namespace.

Changes

In order to provide more clarity and better examples to our end-users I have modified the examples we provide. They now contain all the configuration required to run with two namespaces: default and example. Where default hosts the vitess-operator pod, and example the entire Vitess cluster. With this change I am also changing our E2E test scripts to create the example namespace and use -n example as an option to kubectl where applicable.

The changes needed to run with multiple namespaces are the following:

  • The WATCH_NAMESPACE variable that we set in operator.yaml has to contain a comma-separated list of all the namespaces we want to have. (code)

  • The Role named vitess-operator now has to become a ClusterRole in order to not be namespaced and allow the operator to manage resources across the entire K8S cluster. The ServiceAccount named vitess-operator also have to be binded cluster-wide, using a ClusterRoleBinding instead of a RoleBinding.

  • The Vitess backup subcontroller, VitessBackupStorage, creates its own fork of the vitess-operator pod, into a new pod located in the same namespace as the VitessCluster. This new operator process only runs a single reconciling loop, a simplified version of the root operator process, which will watch and manage new backups in the VitessCluster. To achieve this, it needs API access to these resources: VitessShards, VitessBackups and VitessBackupsStorages. New RBAC have to be added allowing access to these resources, along with a new ServiceAccount in the target namespace (same namespace as the VitessCluster). The new RBAC and ServiceAccount then have to be binded using a RoleBinding.

Documentation and vitessio/vitess Changes

To avoid conflict and unnecessary work, once #658 has been merged along with its two follow-up PRs: vitessio/website#1946 and vitessio/vitess#17869 - I will work on creating the follow up PRs on the documentation repository and the vitessio/vitess repository to reflect the changes made in this PR.

Edit: follow ups are available:

Related Issues

…spaces

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@frouioui frouioui changed the title WIP - Support multiple namespaces Support multiple namespaces Feb 28, 2025
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
frouioui added 2 commits March 3, 2025 12:53
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Copy link
Copy Markdown
Contributor

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

frouioui added 2 commits March 6, 2025 16:49
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
kind: Role
metadata:
name: vitess-operator-subcontroller
namespace: example
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this supposed to be in the default namespace?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not the subcontroller if it is meant for backups, but there are tons of places in this PR where vitess-operator is in the example namespace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is just creating metadata both both namespaces. It wasn't obvious from the diff, but at line 25, the namespace is implicitly default.

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@frouioui frouioui merged commit 3b485ec into main Mar 10, 2025
12 checks passed
@frouioui frouioui deleted the multiple-namespaces branch March 10, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vitess-operator not managing/creating clusters in other namespaces

3 participants