Skip to content

K8SPS-131: make router ports configurable #948

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions api/v1alpha1/perconaservermysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ type MySQLRouterSpec struct {

Expose ServiceExpose `json:"expose,omitempty"`

Ports []corev1.ServicePort `json:"ports,omitempty"`

PodSpec `json:",inline"`
}

Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions config/crd/bases/ps.percona.com_perconaservermysqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8496,6 +8496,31 @@ spec:
type: string
type: object
type: object
ports:
items:
properties:
appProtocol:
type: string
name:
type: string
nodePort:
format: int32
type: integer
port:
format: int32
type: integer
protocol:
default: TCP
type: string
targetPort:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
type: array
priorityClassName:
type: string
readinessProbe:
Expand Down
25 changes: 25 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10419,6 +10419,31 @@ spec:
type: string
type: object
type: object
ports:
items:
properties:
appProtocol:
type: string
name:
type: string
nodePort:
format: int32
type: integer
port:
format: int32
type: integer
protocol:
default: TCP
type: string
targetPort:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
type: array
priorityClassName:
type: string
readinessProbe:
Expand Down
29 changes: 28 additions & 1 deletion deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,34 @@ spec:
# - "secret-1"
# - "secret-2"
# initImage: perconalab/percona-server-mysql-operator:main

# ports:
# - name: http
# port: 8443
# targetPort: 0
# - name: rw-default
# port: 3306
# targetPort: 6446
# - name: read-write
# port: 6446
# targetPort: 0
# - name: read-only
# port: 6447
# targetPort: 0
# - name: x-read-write
# port: 6448
# targetPort: 0
# - name: x-read-only
# port: 6449
# targetPort: 0
# - name: x-default
# port: 33060
# targetPort: 0
# - name: rw-admin
# port: 33062
# targetPort: 0
# - name: custom-port
# port: 1111
# targetPort: 6446
size: 3

resources:
Expand Down
25 changes: 25 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10419,6 +10419,31 @@ spec:
type: string
type: object
type: object
ports:
items:
properties:
appProtocol:
type: string
name:
type: string
nodePort:
format: int32
type: integer
port:
format: int32
type: integer
protocol:
default: TCP
type: string
targetPort:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
type: array
priorityClassName:
type: string
readinessProbe:
Expand Down
25 changes: 25 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10419,6 +10419,31 @@ spec:
type: string
type: object
type: object
ports:
items:
properties:
appProtocol:
type: string
name:
type: string
nodePort:
format: int32
type: integer
port:
format: int32
type: integer
protocol:
default: TCP
type: string
targetPort:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
type: array
priorityClassName:
type: string
readinessProbe:
Expand Down
105 changes: 105 additions & 0 deletions e2e-tests/tests/gr-one-pod/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,47 @@ metadata:
name: gr-one-pod-router
spec:
replicas: 1
template:
spec:
containers:
- args:
- mysqlrouter
- -c
- /tmp/router/mysqlrouter.conf
command:
- /opt/percona/router-entrypoint.sh
env:
- name: MYSQL_SERVICE_NAME
value: gr-one-pod-mysql
name: router
ports:
- containerPort: 8443
name: http
protocol: TCP
- containerPort: 6446
name: rw-default
protocol: TCP
- containerPort: 6446
name: read-write
protocol: TCP
- containerPort: 6447
name: read-only
protocol: TCP
- containerPort: 6448
name: x-read-write
protocol: TCP
- containerPort: 6449
name: x-read-only
protocol: TCP
- containerPort: 33060
name: x-default
protocol: TCP
- containerPort: 33062
name: rw-admin
protocol: TCP
- containerPort: 3333
name: custom-port
protocol: TCP
status:
availableReplicas: 1
observedGeneration: 1
Expand Down Expand Up @@ -59,3 +100,67 @@ status:
size: 1
state: ready
state: ready
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/component: router
app.kubernetes.io/instance: gr-one-pod
app.kubernetes.io/managed-by: percona-server-operator
app.kubernetes.io/name: percona-server
app.kubernetes.io/part-of: percona-server
name: gr-one-pod-router
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
port: 8443
protocol: TCP
targetPort: 8443
- name: rw-default
port: 1111
protocol: TCP
targetPort: 6446
- name: read-write
port: 6446
protocol: TCP
targetPort: 6446
- name: read-only
port: 6447
protocol: TCP
targetPort: 6447
- name: x-read-write
port: 6448
protocol: TCP
targetPort: 6448
- name: x-read-only
port: 6449
protocol: TCP
targetPort: 6449
- name: x-default
port: 33060
protocol: TCP
targetPort: 33060
- name: rw-admin
port: 33062
protocol: TCP
targetPort: 33062
- name: custom-port
port: 2222
protocol: TCP
targetPort: 3333
selector:
app.kubernetes.io/component: router
app.kubernetes.io/instance: gr-one-pod
app.kubernetes.io/managed-by: percona-server-operator
app.kubernetes.io/name: percona-server
app.kubernetes.io/part-of: percona-server
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}

5 changes: 5 additions & 0 deletions e2e-tests/tests/gr-one-pod/01-create-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ commands:
| yq eval ".spec.mysql.size=1" - \
| yq eval ".spec.proxy.haproxy.enabled=false" - \
| yq eval ".spec.proxy.router.size=1" - \
| yq eval '.spec.proxy.router.ports[0].name="rw-default"' - \
| yq eval ".spec.proxy.router.ports[0].port=1111" - \
| yq eval '.spec.proxy.router.ports[1].name="custom-port"' - \
| yq eval ".spec.proxy.router.ports[1].port=2222" - \
| yq eval ".spec.proxy.router.ports[1].targetPort=3333" - \
| yq eval ".spec.orchestrator.enabled=false" - \
| yq eval '.spec.backup.storages.minio.type="s3"' - \
| yq eval '.spec.backup.storages.minio.s3.bucket="operator-testing"' - \
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/gr-one-pod/02-write-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ commands:

run_mysql \
"CREATE DATABASE IF NOT EXISTS myDB; CREATE TABLE IF NOT EXISTS myDB.myTable (id int PRIMARY KEY)" \
"-h $(get_router_service $(get_cluster_name)) -uroot -proot_password"
"-h $(get_router_service $(get_cluster_name)) -P1111 -uroot -proot_password"

run_mysql \
"INSERT myDB.myTable (id) VALUES (100500)" \
"-h $(get_router_service $(get_cluster_name)) -uroot -proot_password"
"-h $(get_router_service $(get_cluster_name)) -P1111 -uroot -proot_password"
4 changes: 2 additions & 2 deletions e2e-tests/tests/gr-one-pod/04-delete-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ commands:

run_mysql \
"TRUNCATE TABLE myDB.myTable" \
"-h $(get_router_service $(get_cluster_name)) -uroot -proot_password"
"-h $(get_router_service $(get_cluster_name)) -P1111 -uroot -proot_password"

data=$(run_mysql "SELECT * FROM myDB.myTable" "-h $(get_router_service $(get_cluster_name)) -uroot -proot_password")
data=$(run_mysql "SELECT * FROM myDB.myTable" "-h $(get_router_service $(get_cluster_name)) -P1111 -uroot -proot_password")
kubectl create configmap -n "${NAMESPACE}" 04-delete-data-minio --from-literal=data="${data}"
2 changes: 1 addition & 1 deletion e2e-tests/tests/gr-one-pod/06-read-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ commands:

wait_cluster_consistency_gr "${test_name}" "1" "1"

data=$(run_mysql "SELECT * FROM myDB.myTable" "-h $(get_router_service $(get_cluster_name)) -uroot -proot_password")
data=$(run_mysql "SELECT * FROM myDB.myTable" "-h $(get_router_service $(get_cluster_name)) -P1111 -uroot -proot_password")
kubectl create configmap -n "${NAMESPACE}" 06-read-data-minio --from-literal=data="${data}"
timeout: 120
Loading
Loading