Skip to content

Commit d6a81ab

Browse files
authored
fix: refactor and fix mysql-schema sample and its instructions (#2681)
Signed-off-by: xstefank <[email protected]>
1 parent 03eb78d commit d6a81ab

File tree

5 files changed

+58
-24
lines changed

5 files changed

+58
-24
lines changed

sample-operators/mysql-schema/README.md

+36-9
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use it as is with real databases.
2323
### Try
2424

2525
To try how the operator works you will need the following:
26-
* JDK installed (minimum version 11, tested with 11 and 15)
26+
* JDK installed (minimum version 11, tested with 11, 15, and 23)
2727
* Maven installed (tested with 3.6.3)
28-
* A working Kubernetes cluster (tested with v1.15.9-gke.24)
28+
* A working Kubernetes cluster (tested with v1.15.9-gke.24 and minikube v1.35.0)
2929
* kubectl installed (tested with v1.15.5)
3030
* Docker installed (tested with 19.03.8)
3131
* Container image registry
@@ -59,18 +59,45 @@ you want to use, you can skip this step, but you will have to configure the oper
5959
`kubectl apply -f k8s/mysql-db.yaml`
6060
1. Deploy the CRD:
6161

62-
`kubectl apply -f k8s/crd.yaml`
62+
`kubectl apply -f target/classes/META-INF/fabric8/mysqlschemas.mysql.sample.javaoperatorsdk-v1.yml`
6363

64-
1. Make a copy of `k8s/operator.yaml` and replace ${DOCKER_REGISTRY} and ${OPERATOR_VERSION} to the
65-
right values. You will want to set `OPERATOR_VERSION` to the one used for building the Docker image. `DOCKER_REGISTRY` should
66-
be the same as you set the docker-registry property in your `pom.xml`.
64+
1. Make a copy of `k8s/operator.yaml` and replace `spec.template.spec.containers[0].image` (`$ yq 'select(di == 1).spec.template.spec.containers[0].image' k8s/operator.yaml`) with the operator image that you pushed to your registry. This should be the same as you set the docker-registry
65+
property in your `pom.xml`.
6766
If you look at the environment variables you will notice this is where the access to the MySQL server is configured.
6867
The default values assume the server is running in another Kubernetes namespace (called `mysql`), uses the `root` user
6968
with a not very secure password. In case you want to use a different MySQL server, this is where you configure it.
7069

7170
1. Run `kubectl apply -f copy-of-operator.yaml` to deploy the operator. You can wait for the deployment to succeed using
72-
this command: `kubectl rollout status deployment mysql-schema-operator -w`. `-w` will cause kubectl to continuously monitor
73-
the deployment until you stop it.
71+
this command: `kubectl rollout status deployment -n mysql-schema-operator mysql-schema-operator -w`. `-w` will cause kubectl to continuously monitor the deployment until you stop it.
7472

7573
1. Now you are ready to create some databases! To create a database schema called `mydb` just apply the `k8s/schema.yaml`
76-
file with kubectl: `kubectl apply -f k8s/schema.yaml`. You can modify the database name in the file to create more schemas.
74+
file with kubectl: `kubectl apply -f k8s/schema.yaml`. You can modify the database name in the file to create more schemas. To verify, that the schema is installed you need to expose your `LoadBalancer` `mysql` service and you can use the `mysql`
75+
CLI to run `show schemas;` command. For instance, with minikube, this can be done like this:
76+
77+
```
78+
$ minikube service mysql -n mysql --url
79+
http://192.168.49.2:30317
80+
81+
$ mysql -h 192.168.49.2 -P 30317 --protocol=tcp -u root -ppassword
82+
...
83+
84+
MariaDB [(none)]> show schemas;
85+
+--------------------+
86+
| Database |
87+
+--------------------+
88+
| information_schema |
89+
| mydb |
90+
| mysql |
91+
| performance_schema |
92+
| sys |
93+
+--------------------+
94+
5 rows in set (0.000 sec)
95+
```
96+
97+
Or you can verify it directly with `kubectl` like this:
98+
99+
```
100+
$ kubectl get mysqlschemas
101+
NAME AGE
102+
mydb 102s
103+
```

sample-operators/mysql-schema/k8s/mysql-deployment.yaml renamed to sample-operators/mysql-schema/k8s/mysql-db.yaml

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: mysql
5+
labels:
6+
name: mysql
7+
---
18
apiVersion: apps/v1
29
kind: Deployment
310
metadata:
@@ -23,4 +30,16 @@ spec:
2330
value: password
2431
ports:
2532
- containerPort: 3306
26-
name: mysql
33+
name: mysql
34+
---
35+
apiVersion: v1
36+
kind: Service
37+
metadata:
38+
name: mysql
39+
namespace: mysql
40+
spec:
41+
ports:
42+
- port: 3306
43+
selector:
44+
app: mysql
45+
type: LoadBalancer

sample-operators/mysql-schema/k8s/mysql-service.yaml

-11
This file was deleted.

sample-operators/mysql-schema/k8s/operator.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
serviceAccountName: mysql-schema-operator # specify the ServiceAccount under which's RBAC persmissions the operator will be executed under
2424
containers:
2525
- name: operator
26-
image: mysql-schema-operator
26+
image: mysql-schema-operator # TODO Change this to point to your pushed mysql-schema-operator image
2727
imagePullPolicy: IfNotPresent
2828
ports:
2929
- containerPort: 80

sample-operators/mysql-schema/src/test/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperatorE2E.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class MySQLSchemaOperatorE2E {
4343
infrastructure.add(
4444
new NamespaceBuilder().withNewMetadata().withName(MY_SQL_NS).endMetadata().build());
4545
try {
46-
infrastructure.addAll(client.load(new FileInputStream("k8s/mysql-deployment.yaml")).items());
47-
infrastructure.addAll(client.load(new FileInputStream("k8s/mysql-service.yaml")).items());
46+
infrastructure.addAll(client.load(new FileInputStream("k8s/mysql-db.yaml")).items());
4847
} catch (FileNotFoundException e) {
4948
e.printStackTrace();
5049
}

0 commit comments

Comments
 (0)