This is an automated email from the ASF dual-hosted git repository. duanzhengqiang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git
commit 919e24616d2510b6a241c8cfdfa61209dc3d5fd4 Author: windghoul <[email protected]> AuthorDate: Wed Jul 20 11:03:08 2022 +0800 feat(helm): add helm to install shardingsphere-operator && shardingsphere-proxy cluster --- .gitignore | 6 +- CODE_OF_CONDUCT.md | 11 +- README.md | 1 + .../shardingsphere-cluster}/.helmignore | 0 charts/shardingsphere-cluster/Chart.yaml | 33 ++++++ .../templates/shardingsphere_v1alpha1_proxy.yaml | 37 +++++++ .../shardingsphere_v1alpha1_proxyconfig.yaml | 23 ++++ charts/shardingsphere-cluster/values.yaml | 118 +++++++++++++++++++++ .../shardingsphere-operator/.helmignore | 0 charts/shardingsphere-operator/Chart.yaml | 29 +++++ .../crds/shardingsphere.sphere-ex.com_proxies.yaml | 6 +- .../shardingsphere.sphere-ex.com_proxyconfigs.yaml | 12 ++- .../templates/deployment.yaml | 24 ++++- .../shardingsphere-operator/templates/rbac.yaml | 68 ++++++------ .../webhook/admission-webhook-apiservice.yaml | 30 ++++++ .../webhook/admission-webhook-configuration.yaml | 69 ++++++++++++ .../webhook/admission-webhook-service.yaml | 28 +++++ charts/shardingsphere-operator/values.yaml | 37 +++++++ doc/quickStart.md | 19 ++-- .../api/v1alpha1/serverconfig.go | 16 +-- shardingsphere-operator/build/Dockerfile | 14 +-- .../charts/shardingsphere-operator/Chart.yaml | 24 ----- .../webhook/admission-webhook-apiservice.yaml | 13 --- .../webhook/admission-webhook-configuration.yaml | 52 --------- .../webhook/admission-webhook-service.yaml | 12 --- .../charts/shardingsphere-operator/values.yaml | 33 ------ .../samples/shardingsphere_v1alpha1_proxy.yaml | 20 ---- .../shardingsphere_v1alpha1_proxyconfig.yaml | 25 ----- 28 files changed, 516 insertions(+), 244 deletions(-) diff --git a/.gitignore b/.gitignore index 1607d59..0e05dcd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ *.dll *.so *.dylib -bin +**/bin testbin/* # Test binary, build with `go test -c` @@ -24,3 +24,7 @@ testbin/* *.swo *~ shardingsphere-operator/build/certs/ +shardingsphere-operator/config/ +charts/shardingsphere-cluster/charts/ +charts/shardingsphere-operator/charts/ +**/Chart.lock diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index c2edd5e..7f1d40b 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,6 +1,7 @@ # Contributor Code of Conduct ## Our Standards + Examples of behavior that contributes to a positive environment include: Demonstrating empathy and kindness toward other people @@ -15,7 +16,13 @@ Trolling, insulting or derogatory comments, and personal or political attacks Public or private harassment Publishing others' private information, such as a physical or email address, without their explicit permission Other conduct which could reasonably be considered inappropriate in a professional setting -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, +issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project +maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this +project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the +project team. ## Attribution -This Code of Conduct is adapted from the CNCF available at this page https://github.com/cncf/foundation/blob/main/code-of-conduct.md \ No newline at end of file + +This Code of Conduct is adapted from the CNCF available at this +page https://github.com/cncf/foundation/blob/main/code-of-conduct.md \ No newline at end of file diff --git a/README.md b/README.md index f839fc3..a6a0ecd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # shardingsphere-operator ## quick start + [quick start](./doc/quickStart.md) \ No newline at end of file diff --git a/shardingsphere-operator/charts/shardingsphere-operator/.helmignore b/charts/shardingsphere-cluster/.helmignore similarity index 100% copy from shardingsphere-operator/charts/shardingsphere-operator/.helmignore copy to charts/shardingsphere-cluster/.helmignore diff --git a/charts/shardingsphere-cluster/Chart.yaml b/charts/shardingsphere-cluster/Chart.yaml new file mode 100644 index 0000000..9fbc4cd --- /dev/null +++ b/charts/shardingsphere-cluster/Chart.yaml @@ -0,0 +1,33 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +apiVersion: v2 +name: shardingsphere-cluster +description: A Helm chart for ShardingSphere-Cluster +dependencies: + - condition: zookeeper.enabled + name: zookeeper + repository: https://charts.bitnami.com/bitnami + version: 9.x.x + - name: common + repository: https://charts.bitnami.com/bitnami + tags: + - bitnami-common + version: 1.x.x +type: application +version: 0.1.0 +appVersion: "5.1.2" diff --git a/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxy.yaml b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxy.yaml new file mode 100644 index 0000000..d9956a8 --- /dev/null +++ b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxy.yaml @@ -0,0 +1,37 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +apiVersion: shardingsphere.sphere-ex.com/v1alpha1 +kind: Proxy +metadata: + name: proxy-sample +spec: + version: {{ .Values.proxyVersion | default .Chart.AppVersion }} + serviceType: + type: {{ .Values.service.type }} + {{- if .Values.replicaCount }} + replicas: {{ .Values.replicaCount }} + {{- end}} + proxyConfigName: {{ printf "%s-configuration" (include "common.names.fullname" .) | quote}} + port: {{ .Values.startPort }} + {{- if .Values.mySQLDriver.version }} + mySQLDriver: + version: {{ .Values.mySQLDriver.version| quote}} + {{- end }} + {{- if .Values.resources }} + resources: {{- toYaml .Values.resources | nindent 4 }} + {{- end }} diff --git a/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxyconfig.yaml b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxyconfig.yaml new file mode 100644 index 0000000..118a631 --- /dev/null +++ b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxyconfig.yaml @@ -0,0 +1,23 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +apiVersion: shardingsphere.sphere-ex.com/v1alpha1 +kind: ProxyConfig +metadata: + name: {{ printf "%s-configuration" (include "common.names.fullname" .) }} +spec: + {{- include "common.tplvalues.render" (dict "value" .Values.serverConfig "context" $) | nindent 2 }} \ No newline at end of file diff --git a/charts/shardingsphere-cluster/values.yaml b/charts/shardingsphere-cluster/values.yaml new file mode 100644 index 0000000..29d14f6 --- /dev/null +++ b/charts/shardingsphere-cluster/values.yaml @@ -0,0 +1,118 @@ + + +# @section DBPlusEngine-Proxy cluster parameters +## @param replicaCount DBPlusEngine-Proxy 集群启动副本数,注意:在开启 automaticScaling 后,这个参数将不再生效 +## +replicaCount: "3" +proxyVersion: "5.1.2" +## @param automaticScaling.enable DBPlusEngine-Proxy 集群是否开启自动扩缩容 +## @param automaticScaling.scaleUpWindows DBPlusEngine-Proxy 自动扩容稳定窗口 +## @param automaticScaling.scaleDownWindows DBPlusEngine-Proxy 自动缩容稳定窗口 +## @param automaticScaling.target DBPlusEngine-Proxy 自动扩缩容阈值,数值为百分比,注意:现阶段暂时只支持 cpu 为指标进行扩缩容 +## @param automaticScaling.maxInstance DBPlusEngine-Proxy 最大扩容副本数 +## @param automaticScaling.minInstance DBPlusEngine-Proxy 最小启动副本数,缩容不会小于这个副本数 +## +automaticScaling: + enable: false + scaleUpWindows: 30 + scaleDownWindows: 30 + target: 20 + maxInstance: 4 + minInstance: 1 +## @param resources DBPlusEngine-Proxy 启动需求资源,在开启automaticScaling 后,以 request 的资源乘以 target 的百分比为触发扩缩容动作的实际使用率 +## e.g: +## resources: +## limits: +## cpu: 2 +## requests: +## cpu: 2 +## +resources: + limits: + cpu: '2' + requests: + cpu: '1' +## @param service.type DBPlusEngine-Proxy 对外暴露方式 +## @param service.port DBPlusEngine-Proxy 对外暴露端口 +## +service: + type: ClusterIP + port: 3307 +## @param startPort DBPlusEngine-Proxy 启动端口 +## +startPort: 3307 +## @param mySQLDriver.version DBPlusEngine-Proxy mysql 驱动版本,如果为空,将不下载驱动 +## +mySQLDriver: + version: "5.1.47" +## @section DBPlusEngine-Proxy ServerConfiguration parameters +## NOTE: If you use the sub-charts to deploy Zookeeper, the server-lists field must be "{{ printf \"%s-zookeeper.%s:2181\" .Release.Name .Release.Namespace }}", +## otherwise please fill in the correct zookeeper address +## The server.yaml is auto-generated based on this parameter. +## If it is empty, the server.yaml is also empty. +## ref: https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/yaml-config/mode/ +## ref: https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/builtin-algorithm/metadata-repository/ +## +serverConfig: + ## @section Compute-Node DBPlusEngine-Proxy ServerConfiguration authority parameters + ## NOTE: It is used to set up initial user to login compute node, and authority data of storage node. + ## @param serverConfig.authority.privilege.type authority provider for storage node, the default value is ALL_PERMITTED + ## @param serverConfig.authority.users[0].password Password for compute node. + ## @param serverConfig.authority.users[0].user Username,authorized host for compute node. Format: <username>@<hostname> hostname is % or empty string means do not care about authorized host + ## + authority: + privilege: + type: ALL_PRIVILEGES_PERMITTED + users: + - password: root + user: root@% + ## @section Compute-Node DBPlusEngine-Proxy ServerConfiguration mode Configuration parameters + ## @param serverConfig.mode.type Type of mode configuration. Now only support Cluster mode + ## @param serverConfig.mode.repository.props.namespace Namespace of registry center + ## @param serverConfig.mode.repository.props.server-lists Server lists of registry center + ## @param serverConfig.mode.repository.props.maxRetries Max retries of client connection + ## @param serverConfig.mode.repository.props.operationTimeoutMilliseconds Milliseconds of operation timeout + ## @param serverConfig.mode.repository.props.retryIntervalMilliseconds Milliseconds of retry interval + ## @param serverConfig.mode.repository.props.timeToLiveSeconds Seconds of ephemeral data live + ## @param serverConfig.mode.repository.type Type of persist repository. Now only support ZooKeeper + ## @param serverConfig.mode.overwrite Whether overwrite persistent configuration with local configuration + ## + mode: + overwrite: true + repository: + props: + maxRetries: 3 + namespace: governance_ds + operationTimeoutMilliseconds: 5000 + retryIntervalMilliseconds: 500 + server-lists: "{{ printf \"%s-zookeeper.%s:2181\" .Release.Name .Release.Namespace }}" + timeToLiveSeconds: 600 + type: ZooKeeper + type: Cluster + props: + proxy-frontend-database-protocol-type: MySQL +## @section ZooKeeper chart parameters + +## ZooKeeper chart configuration +## https://github.com/bitnami/charts/blob/master/bitnami/zookeeper/values.yaml +## +zookeeper: + ## @param zookeeper.enabled Switch to enable or disable the ZooKeeper helm chart + ## + enabled: true + ## @param zookeeper.replicaCount Number of ZooKeeper nodes + ## + replicaCount: 3 + ## ZooKeeper Persistence parameters + ## ref: https://kubernetes.io/docs/user-guide/persistent-volumes/ + ## @param zookeeper.persistence.enabled Enable persistence on ZooKeeper using PVC(s) + ## @param zookeeper.persistence.storageClass Persistent Volume storage class + ## @param zookeeper.persistence.accessModes Persistent Volume access modes + ## @param zookeeper.persistence.size Persistent Volume size + ## + persistence: + enabled: false + storageClass: "" + accessModes: + - ReadWriteOnce + size: 8Gi diff --git a/shardingsphere-operator/charts/shardingsphere-operator/.helmignore b/charts/shardingsphere-operator/.helmignore similarity index 100% rename from shardingsphere-operator/charts/shardingsphere-operator/.helmignore rename to charts/shardingsphere-operator/.helmignore diff --git a/charts/shardingsphere-operator/Chart.yaml b/charts/shardingsphere-operator/Chart.yaml new file mode 100644 index 0000000..7e60e9a --- /dev/null +++ b/charts/shardingsphere-operator/Chart.yaml @@ -0,0 +1,29 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +apiVersion: v2 +name: shardingsphere-operator +description: A Helm chart for ShardingSphere-Operator +type: application +version: 0.1.0 +appVersion: "0.1.0" +dependencies: + - name: common + repository: https://charts.bitnami.com/bitnami + tags: + - bitnami-common + version: 1.x.x diff --git a/shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml similarity index 99% rename from shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml rename to charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml index 8f6ad38..a759332 100644 --- a/shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml +++ b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml @@ -605,10 +605,10 @@ spec: served: true storage: true subresources: - status: {} + status: { } status: acceptedNames: kind: "" plural: "" - conditions: [] - storedVersions: [] + conditions: [ ] + storedVersions: [ ] diff --git a/shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml similarity index 96% rename from shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml rename to charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml index 8a1626c..e81bafd 100644 --- a/shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml +++ b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml @@ -77,7 +77,7 @@ spec: properties: overwrite: description: Whether overwrite persistent configuration with local - configuration. If it is false, it will not upload the local configuration + configuration If it is false, it will not upload the local configuration to ZooKeeper. If it is true, it will upload the local configuration to ZooKeeper and overwrite the original configuration of ZooKeeper. type: boolean @@ -154,6 +154,8 @@ spec: it does not share thread pool even different data source in same JVM. type: integer + proxy-backend-driver-type: + type: string proxy-backend-executor-suitable: description: 'Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of @@ -168,6 +170,8 @@ spec: value is -1, which means set the minimum value for different JDBC drivers. type: integer + proxy-frontend-database-protocol-type: + type: string proxy-frontend-executor-size: description: Proxy frontend Netty executor size. The default value is 0, which means let Netty decide. @@ -189,10 +193,10 @@ spec: served: true storage: true subresources: - status: {} + status: { } status: acceptedNames: kind: "" plural: "" - conditions: [] - storedVersions: [] + conditions: [ ] + storedVersions: [ ] diff --git a/shardingsphere-operator/charts/shardingsphere-operator/templates/deployment.yaml b/charts/shardingsphere-operator/templates/deployment.yaml similarity index 60% rename from shardingsphere-operator/charts/shardingsphere-operator/templates/deployment.yaml rename to charts/shardingsphere-operator/templates/deployment.yaml index 668e22a..7e7bde3 100644 --- a/shardingsphere-operator/charts/shardingsphere-operator/templates/deployment.yaml +++ b/charts/shardingsphere-operator/templates/deployment.yaml @@ -1,10 +1,26 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + apiVersion: apps/v1 kind: Deployment metadata: labels: app: shardingsphere-operator - name: shardingsphere-operator-manager - namespace: {{ .Release.Namespace }} + name: {{ template "common.names.fullname" . }} spec: replicas: {{ .Values.replicaCount }} selector: @@ -17,7 +33,7 @@ spec: spec: containers: - args: - - --health-probe-bind-address=:{{ .Values.health.healthProbePort }} + - --health-probe-bind-address=: {{ .Values.health.healthProbePort }} - --leader-elect command: - /manager @@ -47,4 +63,4 @@ spec: imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ .Values.serviceAccount.name }} + serviceAccountName: {{ template "common.names.fullname" . }} diff --git a/shardingsphere-operator/charts/shardingsphere-operator/templates/rbac.yaml b/charts/shardingsphere-operator/templates/rbac.yaml similarity index 69% rename from shardingsphere-operator/charts/shardingsphere-operator/templates/rbac.yaml rename to charts/shardingsphere-operator/templates/rbac.yaml index 28be47f..4ae62d9 100644 --- a/shardingsphere-operator/charts/shardingsphere-operator/templates/rbac.yaml +++ b/charts/shardingsphere-operator/templates/rbac.yaml @@ -1,15 +1,30 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + --- apiVersion: v1 kind: ServiceAccount metadata: - name: {{ .Values.serviceAccount.name }} - namespace: {{ .Release.Namespace }} + name: {{ template "common.names.fullname" . }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - name: shardingsphere-operator-leader-election-role - namespace: {{ .Release.Namespace }} + name: {{ template "common.names.fullname" . }} rules: - apiGroups: - "" @@ -46,7 +61,7 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: shardingsphere-operator-role + name: {{ template "common.names.fullname" . }} rules: - apiGroups: - "" @@ -152,12 +167,18 @@ rules: - get - patch - update ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: shardingsphere-operator-proxy-role -rules: + - apiGroups: + - autoscaling + resources: + - horizontalpodautoscalers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - authentication.k8s.io resources: @@ -174,39 +195,26 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - name: shardingsphere-operator-leader-election-rolebinding + name: {{ template "common.names.fullname" . }} namespace: {{ .Release.Namespace }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role - name: shardingsphere-operator-leader-election-role -subjects: - - kind: ServiceAccount - name: {{ .Values.serviceAccount.name }} - namespace: {{ .Release.Namespace }} ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: rename-manager-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: shardingsphere-operator-role + name: {{ template "common.names.fullname" . }} subjects: - kind: ServiceAccount - name: {{ .Values.serviceAccount.name }} + name: {{ template "common.names.fullname" . }} namespace: {{ .Release.Namespace }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: rename-proxy-rolebinding + name: {{ template "common.names.fullname" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: shardingsphere-operator-proxy-role + name: {{ template "common.names.fullname" . }} subjects: - kind: ServiceAccount - name: {{ .Values.serviceAccount.name }} + name: {{ template "common.names.fullname" . }} namespace: {{ .Release.Namespace }} diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml b/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml new file mode 100644 index 0000000..7300c05 --- /dev/null +++ b/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml @@ -0,0 +1,30 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +apiVersion: apiregistration.k8s.io/v1 +kind: APIService +metadata: + name: v1alpha1.admission.shardingsphere.sphere-ex.com +spec: + insecureSkipTLSVerify: true + group: admission.shardingsphere.sphere-ex.com + groupPriorityMinimum: 1000 + versionPriority: 5 + service: + name: {{ template "common.names.fullname" . }} + namespace: {{ .Release.Namespace }} + version: v1alpha1 diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml b/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml new file mode 100644 index 0000000..085cc9d --- /dev/null +++ b/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml @@ -0,0 +1,69 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: MutatingWebhookConfiguration +metadata: + name: shardingsphere-mutating-webhook-configuration +webhooks: + - admissionReviewVersions: + - v1 + clientConfig: + service: + name: kubernetes + namespace: default + path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/mutate-shardingsphere-sphere-ex-com-v1alpha1-proxy + failurePolicy: Fail + name: mproxy.shardingsphere.sphere-ex.com + rules: + - apiGroups: + - shardingsphere.sphere-ex.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - proxies + sideEffects: None +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingWebhookConfiguration +metadata: + name: shardingsphere-validating-webhook-configuration +webhooks: + - admissionReviewVersions: + - v1 + clientConfig: + service: + name: kubernetes + namespace: default + path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/validate-shardingsphere-sphere-ex-com-v1alpha1-proxy + failurePolicy: Fail + name: vproxy.shardingsphere.sphere-ex.com + rules: + - apiGroups: + - shardingsphere.sphere-ex.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - proxies + sideEffects: None diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml b/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml new file mode 100644 index 0000000..2995c50 --- /dev/null +++ b/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml @@ -0,0 +1,28 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +apiVersion: v1 +kind: Service +metadata: + name: {{ template "common.names.fullname" . }} +spec: + ports: + - port: 443 + protocol: TCP + targetPort: "webhook" + selector: + app: shardingsphere-operator diff --git a/charts/shardingsphere-operator/values.yaml b/charts/shardingsphere-operator/values.yaml new file mode 100644 index 0000000..9b5ad5b --- /dev/null +++ b/charts/shardingsphere-operator/values.yaml @@ -0,0 +1,37 @@ +## +## Copyright © 2022,Beijing Sifei Software Technology Co., LTD. +## All Rights Reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +replicaCount: 2 + +image: + repository: "uhub.service.ucloud.cn/sphere-ex/proxy-operator" + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "0.0.1" +imagePullSecrets: + - name: uhub +service: + type: ClusterIP + port: 80 +resources: + requests: + cpu: 100m + memory: 128Mi +webhook: + port: 9443 +health: + healthProbePort: 8081 \ No newline at end of file diff --git a/doc/quickStart.md b/doc/quickStart.md index dd12505..f29f309 100644 --- a/doc/quickStart.md +++ b/doc/quickStart.md @@ -1,6 +1,7 @@ # ShardingSphere-Operator 简明使用手册 ## 配置 + **Proxy.shardingsphere.sphere-ex.com/v1alpha1** ```yaml @@ -56,8 +57,8 @@ spec: overwrite: true ``` - <span id="001">**values.yaml**</span> + ```yaml # Default values for proxy-operator. # This is a YAML-formatted file. @@ -70,14 +71,14 @@ image: pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "0.0.1" -imagePullSecrets: [] +imagePullSecrets: [ ] service: type: ClusterIP port: 80 resources: - requests: - cpu: 100m - memory: 128Mi + requests: + cpu: 100m + memory: 128Mi webhook: serviceName: shardingsphere-operator-admission-webhook port: 9443 @@ -87,15 +88,17 @@ serviceAccount: name: shardingsphere-operator ``` +## 安装 ShardingSphere-Operator -## 安装 ShardingSphere-Operator -按照[values.yaml](#001)中的配置完成对 charts/shardingsphere-operator/values.yaml +按照[values.yaml](#001)中的配置完成对 charts/shardingsphere-operator/values.yaml + +执行 -执行 ```shell kubectl create ns shardingsphere-operator helm install shardingsphere-operator shardingsphere-operator -n shardingsphere-operator ``` + ## 安装 ShardingSphere-Proxy ```shell diff --git a/shardingsphere-operator/api/v1alpha1/serverconfig.go b/shardingsphere-operator/api/v1alpha1/serverconfig.go index 7431dc0..7cd7484 100644 --- a/shardingsphere-operator/api/v1alpha1/serverconfig.go +++ b/shardingsphere-operator/api/v1alpha1/serverconfig.go @@ -42,22 +42,26 @@ type Auth struct { type Props struct { // The max thread size of worker group to execute SQL. One ShardingSphereDataSource will use a independent thread pool, it does not share thread pool even different data source in same JVM. // +optional - KernelExecutorSize int `json:"kernel-executor-size,omitempty" yaml:"kernel-executor-size"` + KernelExecutorSize int `json:"kernel-executor-size,omitempty" yaml:"kernel-executor-size,omitempty"` // Whether validate table meta data consistency when application startup or updated. // +optional - CheckTableMetadataEnabled bool `json:"check-table-metadata-enabled,omitempty" yaml:"check-table-metadata-enabled"` + CheckTableMetadataEnabled bool `json:"check-table-metadata-enabled,omitempty" yaml:"check-table-metadata-enabled,omitempty"` // Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy. The default value is -1, which means set the minimum value for different JDBC drivers. // +optional - ProxyBackendQueryFetchSize int `json:"proxy-backend-query-fetch-size,omitempty" yaml:"proxy-backend-query-fetch-size"` + ProxyBackendQueryFetchSize int `json:"proxy-backend-query-fetch-size,omitempty" yaml:"proxy-backend-query-fetch-size,omitempty"` // Whether validate duplicate table when application startup or updated. // +optional - CheckDuplicateTableEnabled bool `json:"check-duplicate-table-enabled,omitempty" yaml:"check-duplicate-table-enabled"` + CheckDuplicateTableEnabled bool `json:"check-duplicate-table-enabled,omitempty" yaml:"check-duplicate-table-enabled,omitempty"` // Proxy frontend Netty executor size. The default value is 0, which means let Netty decide. // +optional - ProxyFrontendExecutorSize int `json:"proxy-frontend-executor-size,omitempty" yaml:"proxy-frontend-executor-size"` + ProxyFrontendExecutorSize int `json:"proxy-frontend-executor-size,omitempty" yaml:"proxy-frontend-executor-size,omitempty"` // Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution and block other clients if client connections are more than proxy-frontend-executor-size, especially executing slow SQL. // +optional - ProxyBackendExecutorSuitable string `json:"proxy-backend-executor-suitable,omitempty" yaml:"proxy-backend-executor-suitable"` + ProxyBackendExecutorSuitable string `json:"proxy-backend-executor-suitable,omitempty" yaml:"proxy-backend-executor-suitable,omitempty"` + // +optional + ProxyBackendDriverType string `json:"proxy-backend-driver-type,omitempty" yaml:"proxy-backend-driver-type,omitempty"` + // +optional + ProxyFrontendDatabaseProtocolType string `json:"proxy-frontend-database-protocol-type" yaml:"proxy-frontend-database-protocol-type,omitempty"` } type ClusterProps struct { diff --git a/shardingsphere-operator/build/Dockerfile b/shardingsphere-operator/build/Dockerfile index 7f97318..3fbb2b7 100644 --- a/shardingsphere-operator/build/Dockerfile +++ b/shardingsphere-operator/build/Dockerfile @@ -4,18 +4,18 @@ FROM golang:1.17 as builder WORKDIR /workspace # Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum +COPY shardingsphere-operator/go.mod go.mod +COPY shardingsphere-operator/go.sum go.sum # cache deps before building and copying source so that we don't need to re-download as much # and so that source changes don't invalidate our downloaded layer ENV GOPROXY=https://proxy.golang.com.cn RUN go mod download # Copy the go source -COPY main.go main.go -COPY api api/ -COPY pkg pkg/ - +COPY shardingsphere-operator/main.go main.go +COPY shardingsphere-operator/api api/ +COPY shardingsphere-operator/pkg pkg/ +RUN mkdir -p certs && cd certs && openssl req -new -SHA256 -newkey rsa:2048 -nodes -keyout tls.key -out tls.csr -subj "/C=CN/ST=beijing/L=beijing/O=/OU=/" && openssl x509 -req -sha256 -days 365 -in tls.csr -signkey tls.key -out tls.crt # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -gcflags "-N -l" -a -o manager main.go @@ -25,6 +25,6 @@ FROM alpine:3.15.4 WORKDIR / COPY --from=builder /workspace/manager . USER root -COPY build/certs /etc/operator/certs +COPY --from=builder /workspace/certs /etc/operator/certs ENTRYPOINT ["/manager"] diff --git a/shardingsphere-operator/charts/shardingsphere-operator/Chart.yaml b/shardingsphere-operator/charts/shardingsphere-operator/Chart.yaml deleted file mode 100644 index cc8989f..0000000 --- a/shardingsphere-operator/charts/shardingsphere-operator/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: shardingsphere-operator -description: A Helm chart for ShardingSphere-Operator - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. -# It is recommended to use it with quotes. -appVersion: "5.1.2" diff --git a/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml deleted file mode 100644 index ab3eb5b..0000000 --- a/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: apiregistration.k8s.io/v1 -kind: APIService -metadata: - name: v1alpha1.admission.shardingsphere.sphere-ex.com -spec: - insecureSkipTLSVerify: true - group: admission.shardingsphere.sphere-ex.com - groupPriorityMinimum: 1000 - versionPriority: 5 - service: - name: {{ .Values.webhook.serviceName }} - namespace: {{ .Release.Namespace }} - version: v1alpha1 diff --git a/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml deleted file mode 100644 index 9d1b08e..0000000 --- a/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -apiVersion: admissionregistration.k8s.io/v1 -kind: MutatingWebhookConfiguration -metadata: - name: shardingsphere-mutating-webhook-configuration -webhooks: -- admissionReviewVersions: - - v1 - clientConfig: - service: - name: kubernetes - namespace: default - path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/mutate-shardingsphere-sphere-ex-com-v1alpha1-proxy - failurePolicy: Fail - name: mproxy.shardingsphere.sphere-ex.com - rules: - - apiGroups: - - shardingsphere.sphere-ex.com - apiVersions: - - v1alpha1 - operations: - - CREATE - - UPDATE - resources: - - proxies - sideEffects: None ---- -apiVersion: admissionregistration.k8s.io/v1 -kind: ValidatingWebhookConfiguration -metadata: - name: shardingsphere-validating-webhook-configuration -webhooks: -- admissionReviewVersions: - - v1 - clientConfig: - service: - name: kubernetes - namespace: default - path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/validate-shardingsphere-sphere-ex-com-v1alpha1-proxy - failurePolicy: Fail - name: vproxy.shardingsphere.sphere-ex.com - rules: - - apiGroups: - - shardingsphere.sphere-ex.com - apiVersions: - - v1alpha1 - operations: - - CREATE - - UPDATE - resources: - - proxies - sideEffects: None diff --git a/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml deleted file mode 100644 index 5e30ef3..0000000 --- a/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ .Values.webhook.serviceName }} - namespace: {{ .Release.Namespace }} -spec: - ports: - - port: 443 - protocol: TCP - targetPort: "webhook" - selector: - app: shardingsphere-operator diff --git a/shardingsphere-operator/charts/shardingsphere-operator/values.yaml b/shardingsphere-operator/charts/shardingsphere-operator/values.yaml deleted file mode 100644 index ecc2cc2..0000000 --- a/shardingsphere-operator/charts/shardingsphere-operator/values.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Default values for proxy-operator. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -# There is now a special directory called crds that you can create in your chart to hold your CRDs. -# Some caveats (and explanations) -# There is no support at this time for upgrading or deleting CRDs using Helm. -# This was an explicit decision after much community discussion due to the danger for unintentional data loss. -# Furthermore, there is currently no community consensus around how to handle CRDs and their lifecycle. -# As this evolves, Helm will add support for those use cases. -replicaCount: 2 - -image: - repository: "shardingsphere-operator" - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "0.0.1" -imagePullSecrets: [] -service: - type: ClusterIP - port: 80 -resources: - requests: - cpu: 100m - memory: 128Mi -webhook: - serviceName: shardingsphere-operator-admission-webhook - port: 9443 -health: - healthProbePort: 8081 - -serviceAccount: - name: shardingsphere-operator \ No newline at end of file diff --git a/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxy.yaml b/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxy.yaml deleted file mode 100644 index c0df351..0000000 --- a/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxy.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: shardingsphere.sphere-ex.com/v1alpha1 -kind: Proxy -metadata: - name: proxy-sample -spec: - version: "5.1.2" - serviceType: - type: ClusterIP - replicas: 1 - proxyConfigName: "proxyconfig-sample" - port: 3307 - mySQLDriver: - version: "5.1.47" - resources: - limits: - cpu: "2" - memory: "2Gi" - requests: - cpu: "0.2" - memory: "1.6Gi" diff --git a/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml b/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml deleted file mode 100644 index d06acf7..0000000 --- a/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: shardingsphere.sphere-ex.com/v1alpha1 -kind: ProxyConfig -metadata: - name: proxyconfig-sample -spec: - authority: - users: - - user: root@% - password: root - - user: sphere@% - password: sphere - privilege: - type: ALL_PRIVILEGES_PERMITTED - mode: - type: Cluster - repository: - type: ZooKeeper - props: - namespace: "governance_ds" - server-lists: "zookeeper.default:2181" - retryIntervalMilliseconds: 500 - timeToLiveSeconds: 600 - maxRetries: 3 - operationTimeoutMilliseconds: 5000 - overwrite: false \ No newline at end of file
