diff --git a/deploy/role.yaml b/deploy/role.yaml index 239fc0f15..933ae8493 100644 --- a/deploy/role.yaml +++ b/deploy/role.yaml @@ -1,5 +1,26 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role +metadata: + name: vitess-operator-subcontroller + 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: diff --git a/deploy/role_binding.yaml b/deploy/role_binding.yaml index 88ecc53a2..1c8eede75 100644 --- a/deploy/role_binding.yaml +++ b/deploy/role_binding.yaml @@ -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 diff --git a/deploy/service_account.yaml b/deploy/service_account.yaml index e2c0d8212..431b357b2 100644 --- a/deploy/service_account.yaml +++ b/deploy/service_account.yaml @@ -2,3 +2,9 @@ apiVersion: v1 kind: ServiceAccount metadata: name: vitess-operator +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: vitess-operator + namespace: example \ No newline at end of file diff --git a/test/endtoend/backup_restore_test.sh b/test/endtoend/backup_restore_test.sh index 92d567fe6..c7398ca41 100755 --- a/test/endtoend/backup_restore_test.sh +++ b/test/endtoend/backup_restore_test.sh @@ -81,7 +81,6 @@ 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 @@ -89,6 +88,7 @@ cd "$PWD/test/endtoend/operator" killall kubectl setupKubectlAccessForCI +createExampleNamespace get_started "operator-latest.yaml" "101_initial_cluster_backup.yaml" verifyVtGateVersion "22.0.0" checkSemiSyncSetup diff --git a/test/endtoend/backup_schedule_test.sh b/test/endtoend/backup_schedule_test.sh index 233932899..fafece512 100755 --- a/test/endtoend/backup_schedule_test.sh +++ b/test/endtoend/backup_schedule_test.sh @@ -22,7 +22,7 @@ function verifyListBackupsOutputWithSchedule() { for i in {1..600} ; 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 3 ]]; then echo -e "Check for Jobs' pods" @@ -51,6 +51,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 diff --git a/test/endtoend/hpa_test.sh b/test/endtoend/hpa_test.sh index 4b2e79d54..61ca1eb2d 100755 --- a/test/endtoend/hpa_test.sh +++ b/test/endtoend/hpa_test.sh @@ -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 @@ -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" @@ -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 diff --git a/test/endtoend/operator/101_initial_cluster.yaml b/test/endtoend/operator/101_initial_cluster.yaml index e0a34ed19..e38a40fdb 100644 --- a/test/endtoend/operator/101_initial_cluster.yaml +++ b/test/endtoend/operator/101_initial_cluster.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup @@ -103,6 +104,7 @@ apiVersion: v1 kind: Secret metadata: name: example-cluster-config + namespace: example type: Opaque stringData: users.json: | diff --git a/test/endtoend/operator/101_initial_cluster_autoscale.yaml b/test/endtoend/operator/101_initial_cluster_autoscale.yaml index 08e19c2db..0547a8099 100644 --- a/test/endtoend/operator/101_initial_cluster_autoscale.yaml +++ b/test/endtoend/operator/101_initial_cluster_autoscale.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: images: vtctld: vitess/lite:latest @@ -96,6 +97,7 @@ apiVersion: v1 kind: Secret metadata: name: example-cluster-config + namespace: example type: Opaque stringData: users.json: | diff --git a/test/endtoend/operator/101_initial_cluster_backup.yaml b/test/endtoend/operator/101_initial_cluster_backup.yaml index 9c673128a..a4a04de5f 100644 --- a/test/endtoend/operator/101_initial_cluster_backup.yaml +++ b/test/endtoend/operator/101_initial_cluster_backup.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup @@ -21,7 +22,7 @@ spec: vtorc: vitess/lite:latest vtbackup: vitess/lite:latest mysqld: - mysql80Compatible: mysql:8.0.40 + mysql80Compatible: vitess/lite:latest mysqldExporter: prom/mysqld-exporter:v0.14.0 cells: - name: zone1 @@ -78,7 +79,6 @@ spec: vttablet: extraFlags: db_charset: utf8mb4 - wait_for_backup_interval: "0" resources: limits: memory: 512Mi @@ -104,6 +104,7 @@ apiVersion: v1 kind: Secret metadata: name: example-cluster-config + namespace: example type: Opaque stringData: users.json: | diff --git a/test/endtoend/operator/101_initial_cluster_backup_schedule.yaml b/test/endtoend/operator/101_initial_cluster_backup_schedule.yaml index b6379901a..c2cc833a4 100644 --- a/test/endtoend/operator/101_initial_cluster_backup_schedule.yaml +++ b/test/endtoend/operator/101_initial_cluster_backup_schedule.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup @@ -109,7 +110,6 @@ spec: vttablet: extraFlags: db_charset: utf8mb4 - wait_for_backup_interval: "0" resources: limits: memory: 1024Mi @@ -135,6 +135,7 @@ apiVersion: v1 kind: Secret metadata: name: example-cluster-config + namespace: example type: Opaque stringData: users.json: | diff --git a/test/endtoend/operator/101_initial_cluster_unmanaged_tablet.yaml b/test/endtoend/operator/101_initial_cluster_unmanaged_tablet.yaml index 38910e015..cb7f3ad40 100644 --- a/test/endtoend/operator/101_initial_cluster_unmanaged_tablet.yaml +++ b/test/endtoend/operator/101_initial_cluster_unmanaged_tablet.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: images: vtctld: vitess/lite:latest @@ -94,6 +95,7 @@ apiVersion: v1 kind: Secret metadata: name: example-cluster-config + namespace: example type: Opaque stringData: users.json: | @@ -210,6 +212,7 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pv-claim + namespace: example spec: accessModes: - ReadWriteOnce @@ -221,6 +224,7 @@ apiVersion: v1 kind: Service metadata: name: mysql + namespace: example labels: app: mysql spec: @@ -234,6 +238,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: mysql + namespace: example spec: replicas: 1 selector: diff --git a/test/endtoend/operator/101_initial_cluster_vtorc_vtadmin.yaml b/test/endtoend/operator/101_initial_cluster_vtorc_vtadmin.yaml index 8c803f007..8ccf17331 100644 --- a/test/endtoend/operator/101_initial_cluster_vtorc_vtadmin.yaml +++ b/test/endtoend/operator/101_initial_cluster_vtorc_vtadmin.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: images: vtctld: vitess/lite:latest @@ -111,6 +112,7 @@ apiVersion: v1 kind: Secret metadata: name: example-cluster-config + namespace: example type: Opaque stringData: users.json: | diff --git a/test/endtoend/operator/102_keyspace_teardown.yaml b/test/endtoend/operator/102_keyspace_teardown.yaml index e9dbcab76..199808619 100644 --- a/test/endtoend/operator/102_keyspace_teardown.yaml +++ b/test/endtoend/operator/102_keyspace_teardown.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup diff --git a/test/endtoend/operator/201_customer_tablets.yaml b/test/endtoend/operator/201_customer_tablets.yaml index c0565c7d9..f27a74a0a 100644 --- a/test/endtoend/operator/201_customer_tablets.yaml +++ b/test/endtoend/operator/201_customer_tablets.yaml @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup diff --git a/test/endtoend/operator/302_new_shards.yaml b/test/endtoend/operator/302_new_shards.yaml index 2808349b8..cdf99b945 100644 --- a/test/endtoend/operator/302_new_shards.yaml +++ b/test/endtoend/operator/302_new_shards.yaml @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup diff --git a/test/endtoend/operator/306_down_shard_0.yaml b/test/endtoend/operator/306_down_shard_0.yaml index 2cfcf5bd2..a871df4ac 100644 --- a/test/endtoend/operator/306_down_shard_0.yaml +++ b/test/endtoend/operator/306_down_shard_0.yaml @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup diff --git a/test/endtoend/operator/401_scheduled_backups.yaml b/test/endtoend/operator/401_scheduled_backups.yaml index 221ab22ba..83c615659 100644 --- a/test/endtoend/operator/401_scheduled_backups.yaml +++ b/test/endtoend/operator/401_scheduled_backups.yaml @@ -2,6 +2,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup diff --git a/test/endtoend/operator/cluster_autoscale.yaml b/test/endtoend/operator/cluster_autoscale.yaml index e36618964..d11353ed8 100644 --- a/test/endtoend/operator/cluster_autoscale.yaml +++ b/test/endtoend/operator/cluster_autoscale.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: images: vtctld: vitess/lite:latest diff --git a/test/endtoend/operator/cluster_upgrade.yaml b/test/endtoend/operator/cluster_upgrade.yaml index cb0216e65..a035881d3 100644 --- a/test/endtoend/operator/cluster_upgrade.yaml +++ b/test/endtoend/operator/cluster_upgrade.yaml @@ -6,6 +6,7 @@ apiVersion: planetscale.com/v2 kind: VitessCluster metadata: name: example + namespace: example spec: backup: engine: xtrabackup diff --git a/test/endtoend/operator/operator-latest.yaml b/test/endtoend/operator/operator-latest.yaml index 1c2795cdc..6829af8d2 100644 --- a/test/endtoend/operator/operator-latest.yaml +++ b/test/endtoend/operator/operator-latest.yaml @@ -7540,11 +7540,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: @@ -7634,14 +7661,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) @@ -7681,9 +7723,7 @@ spec: - vitess-operator env: - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace + value: "default,example" - name: POD_NAME valueFrom: fieldRef: diff --git a/test/endtoend/operator/operator.yaml b/test/endtoend/operator/operator.yaml index c913195a1..a482d69cc 100644 --- a/test/endtoend/operator/operator.yaml +++ b/test/endtoend/operator/operator.yaml @@ -6841,11 +6841,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: @@ -6925,18 +6952,39 @@ rules: - jobs verbs: - '*' + - apiGroups: + - autoscaling + resources: + - horizontalpodautoscalers + verbs: + - '*' --- 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) @@ -6976,9 +7024,7 @@ spec: - vitess-operator env: - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace + value: "default,example" - name: POD_NAME valueFrom: fieldRef: diff --git a/test/endtoend/operator/pf.sh b/test/endtoend/operator/pf.sh index 7e68135fd..a15c50849 100755 --- a/test/endtoend/operator/pf.sh +++ b/test/endtoend/operator/pf.sh @@ -1,8 +1,8 @@ #!/bin/sh -kubectl port-forward --address localhost "$(kubectl get service --selector="planetscale.com/component=vtctld" -o name | head -n1)" 15000 15999 & +kubectl port-forward -n example --address localhost "$(kubectl get service -n example --selector="planetscale.com/component=vtctld" -o name | head -n1)" 15000 15999 & process_id1=$! -kubectl port-forward --address localhost "$(kubectl get service --selector="planetscale.com/component=vtgate,!planetscale.com/cell" -o name | head -n1)" 15306:3306 & +kubectl port-forward -n example --address localhost "$(kubectl get service -n example --selector="planetscale.com/component=vtgate,!planetscale.com/cell" -o name | head -n1)" 15306:3306 & process_id2=$! sleep 2 echo "You may point your browser to http://localhost:15000, use the following aliases as shortcuts:" diff --git a/test/endtoend/operator/pf_vtadmin.sh b/test/endtoend/operator/pf_vtadmin.sh index 5af7a4296..e9e949cbb 100755 --- a/test/endtoend/operator/pf_vtadmin.sh +++ b/test/endtoend/operator/pf_vtadmin.sh @@ -1,10 +1,10 @@ #!/bin/sh -kubectl port-forward --address localhost "$(kubectl get service --selector="planetscale.com/component=vtctld" -o name | head -n1)" 15000 15999 & +kubectl port-forward -n example --address localhost "$(kubectl get service -n example --selector="planetscale.com/component=vtctld" -o name | head -n1)" 15000 15999 & process_id1=$! -kubectl port-forward --address localhost "$(kubectl get service --selector="planetscale.com/component=vtgate,!planetscale.com/cell" -o name | head -n1)" 15306:3306 & +kubectl port-forward -n example --address localhost "$(kubectl get service -n example --selector="planetscale.com/component=vtgate,!planetscale.com/cell" -o name | head -n1)" 15306:3306 & process_id2=$! -kubectl port-forward --address localhost "$(kubectl get service --selector="planetscale.com/component=vtadmin" -o name | head -n1)" 14000:15000 14001:15001 & +kubectl port-forward -n example --address localhost "$(kubectl get service -n example --selector="planetscale.com/component=vtadmin" -o name | head -n1)" 14000:15000 14001:15001 & process_id3=$! sleep 2 echo "You may point your browser to http://localhost:15000, use the following aliases as shortcuts:" diff --git a/test/endtoend/unmanaged_tablet_test.sh b/test/endtoend/unmanaged_tablet_test.sh index 89ca66888..f9931d08d 100755 --- a/test/endtoend/unmanaged_tablet_test.sh +++ b/test/endtoend/unmanaged_tablet_test.sh @@ -98,6 +98,8 @@ cd "$PWD/test/endtoend/operator" killall kubectl setupKubectlAccessForCI +createExampleNamespace + # Check Unmanaged tablet is running properly get_started_unmanaged diff --git a/test/endtoend/upgrade_test.sh b/test/endtoend/upgrade_test.sh index 4aca2c50b..987bd304d 100755 --- a/test/endtoend/upgrade_test.sh +++ b/test/endtoend/upgrade_test.sh @@ -190,14 +190,14 @@ function scheduledBackups() { checkVitessBackupScheduleStatusWithTimeout "example-vbsc-customer(.*)" docker exec -it $(docker container ls --format '{{.Names}}' | grep kind) chmod o+rwx -R /backup > /dev/null - initialCommerceBackups=$(kubectl get vtb --no-headers | grep "commerce-x-x" | wc -l) - initialCustomerFirstShardBackups=$(kubectl get vtb --no-headers | grep "customer-x-80" | wc -l) - initialCustomerSecondShardBackups=$(kubectl get vtb --no-headers | grep "customer-80-x" | wc -l) + initialCommerceBackups=$(kubectl get vtb -n example --no-headers | grep "commerce-x-x" | wc -l) + initialCustomerFirstShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-x-80" | wc -l) + initialCustomerSecondShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-80-x" | wc -l) for i in {1..60} ; do - commerceBackups=$(kubectl get vtb --no-headers | grep "commerce-x-x" | wc -l) - customerFirstShardBackups=$(kubectl get vtb --no-headers | grep "customer-x-80" | wc -l) - customerSecondShardBackups=$(kubectl get vtb --no-headers | grep "customer-80-x" | wc -l) + commerceBackups=$(kubectl get vtb -n example --no-headers | grep "commerce-x-x" | wc -l) + customerFirstShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-x-80" | wc -l) + customerSecondShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-80-x" | wc -l) if [[ "${customerFirstShardBackups}" -ge $(( initialCustomerFirstShardBackups + 2 )) && "${customerSecondShardBackups}" -ge $(( initialCustomerSecondShardBackups + 2 )) && "${commerceBackups}" -ge $(( initialCommerceBackups + 2 )) ]]; then echo "Found all backups" @@ -281,6 +281,7 @@ cd "$PWD/test/endtoend/operator" killall kubectl setupKubectlAccessForCI +createExampleNamespace get_started "operator.yaml" "101_initial_cluster.yaml" verifyVtGateVersion "21.0.0" checkSemiSyncSetup diff --git a/test/endtoend/utils.sh b/test/endtoend/utils.sh index 9701e50f9..822ef0532 100644 --- a/test/endtoend/utils.sh +++ b/test/endtoend/utils.sh @@ -10,7 +10,7 @@ alias mysql="mysql -h 127.0.0.1 -P 15306 -u user" BUILDKITE_BUILD_ID=${BUILDKITE_BUILD_ID:-"0"} function checkSemiSyncSetup() { - for vttablet in $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "vttablet") ; do + for vttablet in $(kubectl get pods -n example --no-headers -o custom-columns=":metadata.name" | grep "vttablet") ; do echo "Checking semi-sync in $vttablet" checkSemiSyncWithRetry "$vttablet" done @@ -19,7 +19,7 @@ function checkSemiSyncSetup() { function checkSemiSyncWithRetry() { vttablet=$1 for i in {1..600} ; do - kubectl exec "$vttablet" -c mysqld -- mysql -S "/vt/socket/mysql.sock" -u root -e "show variables like 'rpl_semi_sync_%_enabled'" | grep "ON" + kubectl exec -n example "$vttablet" -c mysqld -- mysql -S "/vt/socket/mysql.sock" -u root -e "show variables like 'rpl_semi_sync_%_enabled'" | grep "ON" if [[ $? -eq 0 ]]; then return fi @@ -55,28 +55,28 @@ function runSQLWithRetry() { } function printMysqlErrorFiles() { - for vttablet in $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "vttablet") ; do + for vttablet in $(kubectl get pods -n example --no-headers -o custom-columns=":metadata.name" | grep "vttablet") ; do echo "Finding error.log file in $vttablet" - kubectl logs "$vttablet" -c mysqld - kubectl logs "$vttablet" -c vttablet + kubectl logs -n example "$vttablet" -c mysqld + kubectl logs -n example "$vttablet" -c vttablet done } function printBackupLogFiles() { - for vtbackup in $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "vtbackup") ; do + for vtbackup in $(kubectl get pods -n example --no-headers -o custom-columns=":metadata.name" | grep "vtbackup") ; do echo "Printing logs of $vtbackup" - kubectl logs "$vtbackup" + kubectl logs -n example "$vtbackup" echo "Description of $vtbackup" - kubectl describe pod "$vtbackup" + kubectl describe pod -n example "$vtbackup" echo "User in $vtbackup" - kubectl exec "$vtbackup" -- whoami + kubectl exec -n example "$vtbackup" -- whoami done } function removeBackupFiles() { - for vttablet in $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "vttablet") ; do + for vttablet in $(kubectl get pods -n example --no-headers -o custom-columns=":metadata.name" | grep "vttablet") ; do echo "Removing backup files using $vttablet" - kubectl exec "$vttablet" -c vttablet -- rm -rf /vt/backups/example + kubectl exec -n example "$vttablet" -c vttablet -- rm -rf /vt/backups/example return 0 done } @@ -85,7 +85,7 @@ function removeBackupFiles() { # $1: keyspace-shard for which the backup needs to be taken function takeBackup() { keyspaceShard=$1 - initialBackupCount=$(kubectl get vtb --no-headers | wc -l) + initialBackupCount=$(kubectl get vtb -n example --no-headers | wc -l) finalBackupCount=$((initialBackupCount+1)) # Issue the BackupShard command to vtctldclient. @@ -104,7 +104,7 @@ function verifyListBackupsOutput() { for i in {1..30} ; 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) out=$(vtctldclient GetBackups "$keyspaceShard" | wc -l) echo "$out" | grep "$backupCount" > /dev/null 2>&1 if [[ $? -eq 0 ]]; then @@ -139,7 +139,7 @@ function checkPodStatusWithTimeout() { # We use this for loop instead of `kubectl wait` because we don't have access to the full pod name # and `kubectl wait` does not support regex to match resource name. for i in {1..1200} ; do - out=$(kubectl get pods) + out=$(kubectl get pods -A) echo "$out" | grep -E "$regex" | wc -l | grep "$nb" > /dev/null 2>&1 if [[ $? -eq 0 ]]; then echo "$regex found" @@ -161,7 +161,7 @@ function checkPodExistWithTimeout() { # We use this for loop instead of `kubectl wait` because we don't have access to the full pod name # and `kubectl wait` does not support regex to match resource name. for i in {1..1200} ; do - out=$(kubectl get pods) + out=$(kubectl get pods -A) echo "$out" | grep -E "$regex" > /dev/null 2>&1 if [[ $? -eq 0 ]]; then echo "$regex found" @@ -182,7 +182,7 @@ function checkPodExistWithTimeout() { function ensurePodResourcesSet() { regex=$1 - baseCmd='kubectl get pods -o custom-columns="NAME:metadata.name,CONTAINERS:spec.containers[*].name,RESOURCE:spec.containers[*].resources' + baseCmd='kubectl get pods -A -o custom-columns="NAME:metadata.name,CONTAINERS:spec.containers[*].name,RESOURCE:spec.containers[*].resources' # We don't check for .limits.cpu because it is usually unset for resource in '.limits.memory"' '.requests.cpu"' '.requests.memory"' ; do @@ -211,8 +211,8 @@ function insertWithRetry() { function verifyVtGateVersion() { version=$1 - podName=$(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "vtgate") - data=$(kubectl logs "$podName" | head) + podName=$(kubectl get pods -n example --no-headers -o custom-columns=":metadata.name" | grep "vtgate") + data=$(kubectl logs -n example "$podName" | head) echo "$data" | grep "$version" > /dev/null 2>&1 if [[ $? -ne 0 ]]; then echo -e "The vtgate version is incorrect, expected: $version, got:\n$data" @@ -270,10 +270,10 @@ function verifyCustomSidecarDBName() { selector="app=mysql" fi local pods pod - pods=$(kubectl get pods --no-headers --selector="${selector}" -o custom-columns=":metadata.name") + pods=$(kubectl get pods -n example --no-headers --selector="${selector}" -o custom-columns=":metadata.name") for pod in $(echo "${pods}"); do local sdb - sdb=$(eval "kubectl exec ${pod} ${container} -- ${mysqlCMD}") + sdb=$(eval "kubectl exec -n example ${pod} ${container} -- ${mysqlCMD}") if [[ "${sdb}" != "${db_name}" ]]; then echo "Custom sidecar DB name ${db_name} not being used in ${pod} pod" exit 1 @@ -343,6 +343,7 @@ function setupKubectlAccessForCI() { } function setupKindConfig() { + echo "Setting up the kind config" if [[ "$BUILDKITE_BUILD_ID" != "0" ]]; then # The script is being run from buildkite, so we can't mount the current # working directory to kind. The current directory in the docker is workdir @@ -364,6 +365,11 @@ function createKindCluster() { kind load docker-image vitess-operator-pr:latest --name kind-${BUILDKITE_BUILD_ID} } +function createExampleNamespace() { + echo "Creating the example namespace" + kubectl create namespace example +} + # get_started: # $1: operator file to use # $2: initial config file to use @@ -450,7 +456,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 diff --git a/test/endtoend/vtorc_vtadmin_test.sh b/test/endtoend/vtorc_vtadmin_test.sh index fd1d51ece..0c02d5ae7 100755 --- a/test/endtoend/vtorc_vtadmin_test.sh +++ b/test/endtoend/vtorc_vtadmin_test.sh @@ -241,6 +241,7 @@ cd "$PWD/test/endtoend/operator" killall kubectl setupKubectlAccessForCI +createExampleNamespace get_started_vtorc_vtadmin verifyVtGateVersion "22.0.0" checkSemiSyncSetup diff --git a/test/integration/framework/main.go b/test/integration/framework/main.go index 162eb72df..38553aa3f 100644 --- a/test/integration/framework/main.go +++ b/test/integration/framework/main.go @@ -152,6 +152,10 @@ func testMain(tests func() int) error { return fmt.Errorf("cannot create default ServiceAccount: %v\n%s", err, out) } + if out, err := execKubectl("create", "namespace", "example"); err != nil { + return fmt.Errorf("cannot create the example namespace: %v\n%s", err, out) + } + // Install vitess-operator base files, but not the Deployment itself. files := []string{ "service_account.yaml", @@ -189,7 +193,7 @@ func testMain(tests func() int) error { // Set env vars that vitess-operator expects, to simulate the values // provided in deploy/operator.yaml. - os.Setenv("WATCH_NAMESPACE", "default") + os.Setenv("WATCH_NAMESPACE", "default,example") os.Setenv("POD_NAME", "vitess-operator") os.Setenv("PS_OPERATOR_POD_NAMESPACE", "default") os.Setenv("PS_OPERATOR_POD_NAME", "vitess-operator")