Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple namespaces #666

Merged
merged 17 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: vitess-operator-subcontroller
namespace: example
Copy link
Collaborator

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
Collaborator

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
Collaborator

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.

rules:
- apiGroups:
- planetscale.com
resources:
- vitessshards
- vitessshards/status
- vitessshards/finalizers
- vitessbackups
- vitessbackups/status
- vitessbackups/finalizers
- vitessbackupstorages
- vitessbackupstorages/status
- vitessbackupstorages/finalizers
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vitess-operator
rules:
Expand Down
21 changes: 18 additions & 3 deletions deploy/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: vitess-operator
name: vitess-operator-subcontroller
namespace: example
subjects:
- kind: ServiceAccount
name: vitess-operator
- kind: ServiceAccount
name: vitess-operator
namespace: example
roleRef:
kind: Role
name: vitess-operator-subcontroller
apiGroup: rbac.authorization.k8s.io
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: vitess-operator
subjects:
- kind: ServiceAccount
name: vitess-operator
namespace: default
roleRef:
kind: ClusterRole
name: vitess-operator
apiGroup: rbac.authorization.k8s.io
6 changes: 6 additions & 0 deletions deploy/service_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: vitess-operator
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: vitess-operator
namespace: example
2 changes: 1 addition & 1 deletion test/endtoend/backup_restore_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ echo "Make temporary directory for the test"
mkdir -p -m 777 ./vtdataroot/backup
echo "Building the docker image"
docker build -f build/Dockerfile.release -t vitess-operator-pr:latest .
echo "Setting up the kind config"
setupKindConfig
createKindCluster

cd "$PWD/test/endtoend/operator"
killall kubectl
setupKubectlAccessForCI

createExampleNamespace
get_started "operator-latest.yaml" "101_initial_cluster_backup.yaml"
verifyVtGateVersion "22.0.0"
checkSemiSyncSetup
Expand Down
5 changes: 3 additions & 2 deletions test/endtoend/backup_schedule_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function checkVitessBackupScheduleStatusWithTimeout() {
regex=$1

for i in {1..1200} ; do
if [[ $(kubectl get VitessBackupSchedule | grep -E "${regex}" | wc -l) -eq 1 ]]; then
if [[ $(kubectl get VitessBackupSchedule -n example | grep -E "${regex}" | wc -l) -eq 1 ]]; then
echo "$regex found"
return
fi
Expand All @@ -37,7 +37,7 @@ function verifyListBackupsOutputWithSchedule() {
for i in {1..6} ; do
# Ensure that we can view the backup files from the host.
docker exec -it $(docker container ls --format '{{.Names}}' | grep kind) chmod o+rwx -R /backup > /dev/null
backupCount=$(kubectl get vtb --no-headers | wc -l)
backupCount=$(kubectl get vtb -n example --no-headers | wc -l)
echo "Found ${backupCount} backups"
if [[ "${backupCount}" -ge 7 ]]; then
break
Expand Down Expand Up @@ -68,6 +68,7 @@ cd "$PWD/test/endtoend/operator"
killall kubectl
setupKubectlAccessForCI

createExampleNamespace
get_started "operator-latest.yaml" "101_initial_cluster_backup_schedule.yaml"
verifyVtGateVersion "22.0.0"
checkSemiSyncSetup
Expand Down
5 changes: 3 additions & 2 deletions test/endtoend/hpa_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source ./test/endtoend/utils.sh

function verifyHpaCount() {
expectedCount=$1
count=$(kubectl get hpa --no-headers | wc -l)
count=$(kubectl get hpa -n example --no-headers | wc -l)
if [[ "$count" -eq "$expectedCount" ]]; then
echo "HorizontalPodAutoscaler count is $count"
return 0
Expand All @@ -17,7 +17,7 @@ function verifyHpaCount() {
function verifyHpaWithTimeout() {
regex=$1
for i in {1..600} ; do
out=$(kubectl get hpa --no-headers)
out=$(kubectl get hpa -n example --no-headers)
echo "$out" | grep -E "$regex" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "HorizontalPodAutoscaler $regex found"
Expand All @@ -41,6 +41,7 @@ cd "$PWD/test/endtoend/operator"
killall kubectl
setupKubectlAccessForCI

createExampleNamespace
get_started "operator-latest.yaml" "101_initial_cluster_autoscale.yaml"
verifyVtGateVersion "22.0.0"
checkSemiSyncSetup
Expand Down
2 changes: 2 additions & 0 deletions test/endtoend/operator/101_initial_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:v21.0.0
Expand Down Expand Up @@ -96,6 +97,7 @@ apiVersion: v1
kind: Secret
metadata:
name: example-cluster-config
namespace: example
type: Opaque
stringData:
users.json: |
Expand Down
2 changes: 2 additions & 0 deletions test/endtoend/operator/101_initial_cluster_autoscale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down Expand Up @@ -96,6 +97,7 @@ apiVersion: v1
kind: Secret
metadata:
name: example-cluster-config
namespace: example
type: Opaque
stringData:
users.json: |
Expand Down
2 changes: 2 additions & 0 deletions test/endtoend/operator/101_initial_cluster_backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
backup:
engine: xtrabackup
Expand Down Expand Up @@ -104,6 +105,7 @@ apiVersion: v1
kind: Secret
metadata:
name: example-cluster-config
namespace: example
type: Opaque
stringData:
users.json: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
backup:
engine: xtrabackup
Expand Down Expand Up @@ -135,6 +136,7 @@ apiVersion: v1
kind: Secret
metadata:
name: example-cluster-config
namespace: example
type: Opaque
stringData:
users.json: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down Expand Up @@ -94,6 +95,7 @@ apiVersion: v1
kind: Secret
metadata:
name: example-cluster-config
namespace: example
type: Opaque
stringData:
users.json: |
Expand Down Expand Up @@ -210,6 +212,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
namespace: example
spec:
accessModes:
- ReadWriteOnce
Expand All @@ -221,6 +224,7 @@ apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: example
labels:
app: mysql
spec:
Expand All @@ -234,6 +238,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: example
spec:
replicas: 1
selector:
Expand Down
2 changes: 2 additions & 0 deletions test/endtoend/operator/101_initial_cluster_vtorc_vtadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down Expand Up @@ -111,6 +112,7 @@ apiVersion: v1
kind: Secret
metadata:
name: example-cluster-config
namespace: example
type: Opaque
stringData:
users.json: |
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/102_keyspace_teardown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
backup:
engine: xtrabackup
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/201_customer_tablets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/302_new_shards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/306_down_shard_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/cluster_autoscale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/cluster_upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2
kind: VitessCluster
metadata:
name: example
namespace: example
spec:
images:
vtctld: vitess/lite:latest
Expand Down
48 changes: 44 additions & 4 deletions test/endtoend/operator/operator-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7537,11 +7537,38 @@ spec:
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: vitess-operator
namespace: example
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: vitess-operator
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: vitess-operator-backup-storage
namespace: example
rules:
- apiGroups:
- planetscale.com
resources:
- vitessshards
- vitessshards/status
- vitessshards/finalizers
- vitessbackups
- vitessbackups/status
- vitessbackups/finalizers
- vitessbackupstorages
- vitessbackupstorages/status
- vitessbackupstorages/finalizers
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vitess-operator
rules:
Expand Down Expand Up @@ -7631,14 +7658,29 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: vitess-operator
name: vitess-operator-backup-storage
namespace: example
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: vitess-operator-backup-storage
subjects:
- kind: ServiceAccount
name: vitess-operator
namespace: example
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: vitess-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: vitess-operator
subjects:
- kind: ServiceAccount
name: vitess-operator
namespace: default
---
apiVersion: scheduling.k8s.io/v1
description: Vitess components (vttablet, vtgate, vtctld, etcd)
Expand Down Expand Up @@ -7678,9 +7720,7 @@ spec:
- vitess-operator
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
value: "default,example"
- name: POD_NAME
valueFrom:
fieldRef:
Expand Down
Loading