提交 ced06717 编写于 作者: W wangzelin.wzl

init push

上级
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files which are not go type
!**/*.go
!**/*.mod
!**/*.sum
# Mac OS X
.DS_Store
# IDE
.idea
*.out
*.swp
*.swo
*~
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
# lib & package
.vendor/
.glide/
# Test binary
*.test
cover.out
testbin/*
# Kubernetes Generated files - skip generated files, except for vendored files
# !vendor/**/zz_generated.*
# Build the manager binary
FROM golang:1.16 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY . .
# Build
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://mirrors.aliyun.com/goproxy/ go build -a -o manager main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM openanolis/anolisos:8.4-x86_64
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
ENTRYPOINT ["/manager"]
Mulan Permissive Software License,Version 2
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
January 2020 http://license.coscl.org.cn/MulanPSL2
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
0. Definition
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
Contribution means the copyrightable work licensed by a particular Contributor under this License.
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
Legal Entity means the entity making a Contribution and all its Affiliates.
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
1. Grant of Copyright License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
2. Grant of Patent License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
3. No Trademark License
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
4. Distribution Restriction
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
5. Disclaimer of Warranty and Limitation of Liability
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
6. Language
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
END OF THE TERMS AND CONDITIONS
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
VERSION := $(shell git rev-parse --short HEAD)
# Image URL to use all building/pushing image targets
IMG ?= oceanbase/obce-operator:v0.0.1
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
all: build
##@ General
# The help target prints out all targets with their descriptions organized beneath their categories.
# The categories are represented by '##@' and the target descriptions by '##'.
# The awk commands is responsible for reading the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help.
# Then, if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Generate
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
go mod tidy
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate-client: ## Generate kube-client.
sh hack/update-codegen.sh
fmt: ## Run go fmt against code.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
generate-all: manifests kustomize generate fmt vet ## Generate all, include controller & client.
##@ Build
local-build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} .
docker-push: ## Push docker image with the manager.
docker push ${IMG}
##@ Deployment
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
##@ Export
export-crd: manifests kustomize ## Export CDR yaml.
$(KUSTOMIZE) build config/crd > deploy/crd.yaml
export-operator: manifests kustomize docker-build docker-push ## Export operator yaml.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > deploy/operator.yaml
##@ Debug
run-local: install ## Run for debug.
go run ./main.go
run-remote: docker-build docker-push deploy ## Run on cluster.
domain: oceanbase.com
layout:
- go.kubebuilder.io/v3
multigroup: true
projectName: ob-operator
repo: github.com/oceanbase/ob-operator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: oceanbase.com
group: cloud
kind: StatefulApp
path: github.com/oceanbase/ob-operator/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: oceanbase.com
group: cloud
kind: OBCluster
path: github.com/oceanbase/ob-operator/apis/cloud/v1
version: v1
- api:
crdVersion: v1
namespaced: true
domain: oceanbase.com
group: cloud
kind: RootService
path: github.com/oceanbase/ob-operator/apis/cloud/v1
version: v1
- api:
crdVersion: v1
namespaced: true
domain: oceanbase.com
group: cloud
kind: OBZone
path: github.com/oceanbase/ob-operator/apis/cloud/v1
version: v1
version: "3"
# ob-operator
ob-operator 可以让 OceanBase 以容器的方式,无缝运行在公有云或私有部署的 Kubernetes 集群上。
ob-operator 现已支持 OceanBase 集群的创建、删除,完整的节点生命周期管理,并通过 Service 的形式暴露给用户使用。后续会支持租户管理、ob-proxy 管理、多 Kubernetes 集群等功能。
目前支持通过 YAML、Kustomize 来部署 ob-operator。后续会支持 Helm 形式部署。
![01](docs/img/01.png)
## 环境依赖
构建 ob-operator 需要 Go 1.16 版本及以上。
运行 ob-operator 需要 Kubernetes 1.16 版本及以上。
尚未支持多 Kubernetes 版本,后续会支持。
## 支持的 OceanBase 版本
后续会不断支持新的 OceanBase 社区版本。
暂不支持 3.1.2 之前的旧的 OceanBase 版本。目前仅对 OceanBase 社区版 3.1.2 进行了测试。
## 开始体验
### 使用 YAML 部署 ob-operator
1. 部署 CRD 相关文件。
```yaml
kubectl apply -f ./deploy/crd.yaml
```
2. 部署 ob-operator 相关文件。
注意配置 `--cluster-name` 启动参数,推荐与 Kubernetes 集群名称保持一致。
```yaml
kubectl apply -f ./deploy/operator.yaml
```
3. 配置节点 label。
需要将 Kubernetes 节点打 label,label 需要与 obcluster.yaml 中 `nodeSelector` 配置相匹配。
ob-operator 会将 Pod 调度到具有相应 label 的节点上。
推荐配置 label 的 key 为 `topology.kubernetes.io/zone`
```yaml
kubectl label node nodename topology.kubernetes.io/zone=zonename
```
4. 部署 OceanBase 集群。
```yaml
kubectl apply -f ./deploy/obcluster.yaml
```
5. 集群部署成功后可以使用 Service 的 ClusterIP 连接 OceanBase 集群。
## 文档
参考 [ob-operator 文档](docs/hello-cn.md)
## 获取帮助
如果您在使用 ob-operator 时遇到任何问题,欢迎通过以下方式寻求帮助:
- [GitHub Issue](https://github.com/oceanbase/ob-operator/issues)
- [官方网站](https://open.oceanbase.com/)
## 许可证
ob-operator 使用 [MulanPSL - 2.0](http://license.coscl.org.cn/MulanPSL2) 许可证。
您可以免费复制及使用源代码。当您修改或分发源代码时,请遵守木兰协议。
# ob-operator
ob-operator 可以让 OceanBase 以容器的方式,无缝运行在公有云或私有部署的 Kubernetes 集群上。
ob-operator 现已支持 OceanBase 集群的创建、删除,完整的节点生命周期管理,并通过 Service 的形式暴露给用户使用。后续会支持租户管理、ob-proxy 管理、多 Kubernetes 集群等功能。
目前支持通过 YAML、Kustomize 来部署 ob-operator。后续会支持 Helm 形式部署。
![01](docs/img/01.png)
## 环境依赖
构建 ob-operator 需要 Go 1.16 版本及以上。
运行 ob-operator 需要 Kubernetes 1.16 版本及以上。
尚未支持多 Kubernetes 版本,后续会支持。
## 支持的 OceanBase 版本
后续会不断支持新的 OceanBase 社区版本。
暂不支持 3.1.2 之前的旧的 OceanBase 版本。目前仅对 OceanBase 社区版 3.1.2 进行了测试。
## 开始体验
### 使用 YAML 部署 ob-operator
1. 部署 CRD 相关文件。
```yaml
kubectl apply -f ./deploy/crd.yaml
```
2. 部署 ob-operator 相关文件。
注意配置 `--cluster-name` 启动参数,推荐与 Kubernetes 集群名称保持一致。
```yaml
kubectl apply -f ./deploy/operator.yaml
```
3. 配置节点 label。
需要将 Kubernetes 节点打 label,label 需要与 obcluster.yaml 中 `nodeSelector` 配置相匹配。
ob-operator 会将 Pod 调度到具有相应 label 的节点上。
推荐配置 label 的 key 为 `topology.kubernetes.io/zone`
```yaml
kubectl label node nodename topology.kubernetes.io/zone=zonename
```
4. 部署 OceanBase 集群。
```yaml
kubectl apply -f ./deploy/obcluster.yaml
```
5. 集群部署成功后可以使用 Service 的 ClusterIP 连接 OceanBase 集群。
## 文档
参考 [ob-operator 文档](docs/hello-cn.md)
## 获取帮助
如果您在使用 ob-operator 时遇到任何问题,欢迎通过以下方式寻求帮助:
- [GitHub Issue](https://github.com/oceanbase/ob-operator/issues)
- [官方网站](https://open.oceanbase.com/)
## 许可证
ob-operator 使用 [MulanPSL - 2.0](http://license.coscl.org.cn/MulanPSL2) 许可证。
您可以免费复制及使用源代码。当您修改或分发源代码时,请遵守木兰协议。
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package apis
import (
"k8s.io/apimachinery/pkg/runtime"
)
// AddToSchemes may be used to add all resources defined in the project to a Scheme
var AddToSchemes runtime.SchemeBuilder
// AddToScheme adds all Resources to the Scheme
func AddToScheme(s *runtime.Scheme) error {
return AddToSchemes.AddToScheme(s)
}
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
// +groupName=cloud.oceanbase.com
package v1
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
// Package v1 contains API Schema definitions for the cloud v1 API group
// +kubebuilder:object:generate=true
// +groupName=cloud.oceanbase.com
package v1
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)
var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "cloud.oceanbase.com", Version: "v1"}
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package v1
import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// OBClusterSpec defines the desired state of OBCluster
type OBClusterSpec struct {
Version string `json:"version"`
// +kubebuilder:validation:Minimum=1
ClusterID int `json:"clusterID"`
Topology []Cluster `json:"topology"`
Resources ResourcesSpec `json:"resources"`
}
type Cluster struct {
Cluster string `json:"cluster"`
Zone []Subset `json:"zone"`
}
type ResourcesSpec struct {
CPU resource.Quantity `json:"cpu"`
Memory resource.Quantity `json:"memory"`
Storage []StorageSpec `json:"storage"`
}
type StorageSpec struct {
Name string `json:"name"`
StorageClassName string `json:"storageClassName"`
Size resource.Quantity `json:"size"`
}
// OBClusterStatus defines the observed state of OBCluster
type OBClusterStatus struct {
Status string `json:"status"`
Topology []ClusterStatus `json:"topology"`
}
type ClusterStatus struct {
Cluster string `json:"cluster"`
ClusterStatus string `json:"clusterStatus"`
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
Zone []ZoneStatus `json:"zone"`
}
type ZoneStatus struct {
Name string `json:"name"`
Region string `json:"region"`
ZoneStatus string `json:"zoneStatus"`
ExpectedReplicas int32 `json:"expectedReplicas"`
AvailableReplicas int32 `json:"availableReplicas"`
}
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// OBCluster is the Schema for the obclusters API
type OBCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec OBClusterSpec `json:"spec"`
Status OBClusterStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// OBClusterList contains a list of OBCluster
type OBClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []OBCluster `json:"items"`
}
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// OBZoneSpec defines the desired state of OBZone
type OBZoneSpec struct {
Topology []Cluster `json:"topology"`
}
// OBZoneStatus defines the observed state of OBZone
type OBZoneStatus struct {
Topology []ClusterOBZoneStatus `json:"topology"`
}
type ClusterOBZoneStatus struct {
Cluster string `json:"cluster"`
Zone []OBZoneInfo `json:"zone"`
}
type OBZoneInfo struct {
Name string `json:"name"`
Nodes []OBNode `json:"nodes"`
}
type OBNode struct {
ServerIP string `json:"serverIP"`
Status string `json:"status"`
}
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// OBZone is the Schema for the obzones API
type OBZone struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec OBZoneSpec `json:"spec,omitempty"`
Status OBZoneStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// OBZoneList contains a list of OBZone
type OBZoneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []OBZone `json:"items"`
}
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package v1
import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = GroupVersion
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
func init() {
SchemeBuilder.Register(&StatefulApp{}, &StatefulAppList{}, &OBCluster{}, &OBClusterList{}, &RootService{}, &RootServiceList{}, &OBZone{}, &OBZoneList{})
}
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// RootServiceSpec defines the desired state of RootService
type RootServiceSpec struct {
Topology []Cluster `json:"topology"`
}
// RootServiceStatus defines the observed state of RootService
type RootServiceStatus struct {
Topology []ClusterRootServiceStatus `json:"topology"`
}
type ClusterRootServiceStatus struct {
Cluster string `json:"cluster"`
Zone []ZoneRootServiceStatus `json:"zoneRootService"`
}
type ZoneRootServiceStatus struct {
Name string `json:"name"`
ServerIP string `json:"serverIP"`
Role int `json:"role"`
Status string `json:"status"`
}
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// RootService is the Schema for the rootservices API
type RootService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RootServiceSpec `json:"spec,omitempty"`
Status RootServiceStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// RootServiceList contains a list of RootService
type RootServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RootService `json:"items"`
}
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package v1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// StatefulAppSpec defines the desired state of StatefulApp
type StatefulAppSpec struct {
Cluster string `json:"cluster"`
Subsets []Subset `json:"subsets"`
PodTemplate corev1.PodSpec `json:"podTemplate"`
StorageTemplates []StorageTemplate `json:"storageTemplates"`
}
type Subset struct {
Name string `json:"name"`
Region string `json:"region,omitempty"`
NodeSelector map[string]string `json:"nodeSelector"`
// +kubebuilder:validation:Minimum=1
Replicas int32 `json:"replicas"`
}
type StorageTemplate struct {
Name string `json:"name"`
PVC corev1.PersistentVolumeClaimSpec `json:"pvc"`
}
// StatefulAppStatus defines the observed state of StatefulApp
type StatefulAppStatus struct {
Cluster string `json:"cluster"`
ClusterStatus string `json:"clusterStatus"`
Subsets []SubsetStatus `json:"subsets"`
}
type SubsetStatus struct {
Name string `json:"name"`
Region string `json:"region,omitempty"`
ExpectedReplicas int32 `json:"expectedReplicas"`
AvailableReplicas int32 `json:"availableReplicas"`
Pods []PodStatus `json:"pods"`
}
type PodStatus struct {
Name string `json:"name"`
Index int `json:"index"`
PodPhase corev1.PodPhase `json:"podPhase"`
PodIP string `json:"podIP"`
NodeIP string `json:"nodeIP"`
PVCs []PVCStatus `json:"pvcs,omitempty"`
}
type PVCStatus struct {
Name string `json:"name"`
Phase corev1.PersistentVolumePhase `json:"phase"`
}
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// StatefulApp is the Schema for the statefulapps API
type StatefulApp struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec StatefulAppSpec `json:"spec"`
Status StatefulAppStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// StatefulAppList contains a list of StatefulApp
type StatefulAppList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []StatefulApp `json:"items"`
}
此差异已折叠。
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package main
import (
"github.com/oceanbase/ob-operator/pkg/cable/observer"
"github.com/oceanbase/ob-operator/pkg/cable/provider"
"github.com/oceanbase/ob-operator/pkg/util"
)
func main() {
util.FuncList = make([]func(), 0)
observer.Paused = false
provider.InitForK8s()
util.SignalHandler(util.FuncList)
select {}
}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: obclusters.cloud.oceanbase.com
spec:
group: cloud.oceanbase.com
names:
kind: OBCluster
listKind: OBClusterList
plural: obclusters
singular: obcluster
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: OBCluster is the Schema for the obclusters API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: OBClusterSpec defines the desired state of OBCluster
properties:
clusterID:
minimum: 1
type: integer
resources:
properties:
cpu:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
memory:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storage:
items:
properties:
name:
type: string
size:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
type: string
required:
- name
- size
- storageClassName
type: object
type: array
required:
- cpu
- memory
- storage
type: object
topology:
items:
properties:
cluster:
type: string
zone:
items:
properties:
name:
type: string
nodeSelector:
additionalProperties:
type: string
type: object
region:
type: string
replicas:
format: int32
minimum: 1
type: integer
required:
- name
- nodeSelector
- replicas
type: object
type: array
required:
- cluster
- zone
type: object
type: array
version:
type: string
required:
- clusterID
- resources
- topology
- version
type: object
status:
description: OBClusterStatus defines the observed state of OBCluster
properties:
status:
type: string
topology:
items:
properties:
cluster:
type: string
clusterStatus:
type: string
lastTransitionTime:
format: date-time
type: string
zone:
items:
properties:
availableReplicas:
format: int32
type: integer
expectedReplicas:
format: int32
type: integer
name:
type: string
region:
type: string
zoneStatus:
type: string
required:
- availableReplicas
- expectedReplicas
- name
- region
- zoneStatus
type: object
type: array
required:
- cluster
- clusterStatus
- lastTransitionTime
- zone
type: object
type: array
required:
- status
- topology
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: obzones.cloud.oceanbase.com
spec:
group: cloud.oceanbase.com
names:
kind: OBZone
listKind: OBZoneList
plural: obzones
singular: obzone
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: OBZone is the Schema for the obzones API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: OBZoneSpec defines the desired state of OBZone
properties:
topology:
items:
properties:
cluster:
type: string
zone:
items:
properties:
name:
type: string
nodeSelector:
additionalProperties:
type: string
type: object
region:
type: string
replicas:
format: int32
minimum: 1
type: integer
required:
- name
- nodeSelector
- replicas
type: object
type: array
required:
- cluster
- zone
type: object
type: array
required:
- topology
type: object
status:
description: OBZoneStatus defines the observed state of OBZone
properties:
topology:
items:
properties:
cluster:
type: string
zone:
items:
properties:
name:
type: string
nodes:
items:
properties:
serverIP:
type: string
status:
type: string
required:
- serverIP
- status
type: object
type: array
required:
- name
- nodes
type: object
type: array
required:
- cluster
- zone
type: object
type: array
required:
- topology
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: rootservices.cloud.oceanbase.com
spec:
group: cloud.oceanbase.com
names:
kind: RootService
listKind: RootServiceList
plural: rootservices
singular: rootservice
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: RootService is the Schema for the rootservices API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: RootServiceSpec defines the desired state of RootService
properties:
topology:
items:
properties:
cluster:
type: string
zone:
items:
properties:
name:
type: string
nodeSelector:
additionalProperties:
type: string
type: object
region:
type: string
replicas:
format: int32
minimum: 1
type: integer
required:
- name
- nodeSelector
- replicas
type: object
type: array
required:
- cluster
- zone
type: object
type: array
required:
- topology
type: object
status:
description: RootServiceStatus defines the observed state of RootService
properties:
topology:
items:
properties:
cluster:
type: string
zoneRootService:
items:
properties:
name:
type: string
role:
type: integer
serverIP:
type: string
status:
type: string
required:
- name
- role
- serverIP
- status
type: object
type: array
required:
- cluster
- zoneRootService
type: object
type: array
required:
- topology
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
此差异已折叠。
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/cloud.oceanbase.com_statefulapps.yaml
- bases/cloud.oceanbase.com_obclusters.yaml
- bases/cloud.oceanbase.com_rootservices.yaml
- bases/cloud.oceanbase.com_obzones.yaml
#+kubebuilder:scaffold:crdkustomizeresource
patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_statefulapps.yaml
#- patches/webhook_in_obclusters.yaml
#- patches/webhook_in_rootservices.yaml
#- patches/webhook_in_obzones.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_statefulapps.yaml
#- patches/cainjection_in_obclusters.yaml
#- patches/cainjection_in_rootservices.yaml
#- patches/cainjection_in_obzones.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name
namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false
varReference:
- path: metadata/annotations
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: obclusters.cloud.oceanbase.com
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: obzones.cloud.oceanbase.com
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: rootservices.cloud.oceanbase.com
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: statefulapps.cloud.oceanbase.com
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: obclusters.cloud.oceanbase.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: obzones.cloud.oceanbase.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: rootservices.cloud.oceanbase.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: statefulapps.cloud.oceanbase.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
# Adds namespace to all resources.
namespace: oceanbase-system
# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: ob-operator-
# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
bases:
# - ../crd
- ../rbac
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml
# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- manager_webhook_patch.yaml
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
# 'CERTMANAGER' needs to be enabled to use ca injection
#- webhookcainjection_patch.yaml
# the following config is for teaching kustomize how to do var substitution
vars:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
# objref:
# kind: Certificate
# group: cert-manager.io
# version: v1
# name: serving-cert # this name should match the one in certificate.yaml
# fieldref:
# fieldpath: metadata.namespace
#- name: CERTIFICATE_NAME
# objref:
# kind: Certificate
# group: cert-manager.io
# version: v1
# name: serving-cert # this name should match the one in certificate.yaml
#- name: SERVICE_NAMESPACE # namespace of the service
# objref:
# kind: Service
# version: v1
# name: webhook-service
# fieldref:
# fieldpath: metadata.namespace
#- name: SERVICE_NAME
# objref:
# kind: Service
# version: v1
# name: webhook-service
# This patch inject a sidecar container which is a HTTP proxy for the
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: kube-rbac-proxy
image: oceanbase/obce-operator:kube-rbac-proxy-v0.8.0
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=10"
ports:
- containerPort: 8443
name: https
- name: manager
args:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--config=controller_manager_config.yaml"
volumeMounts:
- name: manager-config
mountPath: /controller_manager_config.yaml
subPath: controller_manager_config.yaml
volumes:
- name: manager-config
configMap:
name: manager-config
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :8081
metrics:
bindAddress: 127.0.0.1:8080
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: ee2dec96.oceanbase.com
resources:
- manager.yaml
generatorOptions:
disableNameSuffixHash: true
configMapGenerator:
- files:
- controller_manager_config.yaml
name: manager-config
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: oceanbase/obce-operator
newTag: v0.0.1
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: oceanbase-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
labels:
control-plane: controller-manager
spec:
selector:
matchLabels:
control-plane: controller-manager
replicas: 1
template:
metadata:
labels:
control-plane: controller-manager
spec:
securityContext:
runAsNonRoot: true
containers:
- command:
- /manager
args:
- --leader-elect
image: controller:latest
imagePullPolicy: Always
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 1
memory: 1Gi
requests:
cpu: 1
memory: 1Gi
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
control-plane: controller-manager
name: controller-manager-metrics-monitor
namespace: system
spec:
endpoints:
- path: /metrics
port: https
scheme: https
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
control-plane: controller-manager
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: metrics-reader
rules:
- nonResourceURLs:
- "/metrics"
verbs:
- get
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: proxy-role
rules:
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: proxy-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: proxy-role
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
apiVersion: v1
kind: Service
metadata:
labels:
control-plane: controller-manager
name: controller-manager-metrics-service
namespace: system
spec:
ports:
- name: https
port: 8443
targetPort: https
selector:
control-plane: controller-manager
resources:
# All RBAC will be applied under this service account in
# the deployment namespace. You may comment out this resource
# if your manager will use a service account that exists at
# runtime. Be sure to update RoleBinding and ClusterRoleBinding
# subjects if changing service account names.
- service_account.yaml
- role.yaml
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
- auth_proxy_service.yaml
- auth_proxy_role.yaml
- auth_proxy_role_binding.yaml
- auth_proxy_client_clusterrole.yaml
# permissions to do leader election.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: leader-election-role
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: leader-election-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: leader-election-role
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
# permissions for end users to edit obclusters.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: obcluster-editor-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters/status
verbs:
- get
# permissions for end users to view obclusters.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: obcluster-viewer-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters
verbs:
- get
- list
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters/status
verbs:
- get
# permissions for end users to edit obzones.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: obzone-editor-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- obzones
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- obzones/status
verbs:
- get
# permissions for end users to view obzones.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: obzone-viewer-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- obzones
verbs:
- get
- list
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- obzones/status
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters/finalizers
verbs:
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters/status
verbs:
- get
- patch
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/finalizers
verbs:
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/sfinalizers
verbs:
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- persistentvolumeclaims/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- persistentvolumes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- persistentvolumes/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- pods/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- pods/status
verbs:
- get
- patch
- update
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
# permissions for end users to edit rootservices.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: rootservice-editor-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- rootservices
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- rootservices/status
verbs:
- get
# permissions for end users to view rootservices.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: rootservice-viewer-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- rootservices
verbs:
- get
- list
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- rootservices/status
verbs:
- get
apiVersion: v1
kind: ServiceAccount
metadata:
name: controller-manager
namespace: system
# permissions for end users to edit statefulapps.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: statefulapp-editor-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/status
verbs:
- get
# permissions for end users to view statefulapps.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: statefulapp-viewer-role
rules:
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps
verbs:
- get
- list
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/status
verbs:
- get
apiVersion: cloud.oceanbase.com/v1
kind: OBCluster
metadata:
namespace: ob
name: ob-test
spec:
version: v3.1.2-10000392021123010 # OB 版本
clusterID: 1
topology: # 拓扑分布
- cluster: cn
zone:
- name: zone1
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
resources: # OB 所需要的资源
cpu: 7
memory: 60Gi
storage:
- name: log
storageClassName: "local-path"
size: 50Gi
- name: data
storageClassName: "local-path"
size: 50Gi
status:
status: Ready
topology:
- cluster: cn
clusterStatus: Ready
lastTransitionTime: "2021-12-08T07:07:55Z"
zone:
- name: zone1
region: region1
zoneStatus: Ready
expectedReplicas: 1
availableReplicas: 1
- name: zone2
region: region1
zoneStatus: Ready
expectedReplicas: 1
availableReplicas: 1
- name: zone3
region: region1
zoneStatus: Ready
expectedReplicas: 1
availableReplicas: 1
apiVersion: cloud.oceanbase.com/v1
kind: OBZone
metadata:
labels:
app: ob-test
name: obzone-ob-test
namespace: ob
spec:
topology:
- cluster: cn
zone:
- name: zone1
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
status:
topology:
- cluster: cn
zone:
- name: zone1
nodes:
- serverIP: 10.10.10.1
status: active
- name: zone2
nodes:
- serverIP: 10.10.10.2
status: active
- name: zone3
nodes:
- serverIP: 10.10.10.3
status: active
apiVersion: cloud.oceanbase.com/v1
kind: RootService
metadata:
labels:
app: ob-test
name: rs-ob-test
namespace: ob
spec:
topology:
- cluster: cn
zone:
- name: zone1
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
status:
topology:
- cluster: cn
zone:
- name: zone1
role: 1
serverIP: 10.10.10.1
status: active
- name: zone2
role: 2
serverIP: 10.10.10.2
status: active
- name: zone3
role: 2
serverIP: 10.10.10.3
status: active
apiVersion: cloud.oceanbase.com/v1
kind: StatefulApp
metadata:
namespace: ob
name: sapp
spec:
cluster: cn # Operator 监控的集群名称,启动的时候需要指定
subsets:
- name: zone1
nodeSelector: # 强制匹配到某个 Zone
topology.kubernetes.io/zone: zone1
replicas: 2
- name: zone2
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
podTemplate: # Pod 自身资源的描述
containers:
- name: observer
image: nginx
resources:
requests:
cpu: "1"
memory: "2Gi"
volumeMounts:
- name: log
mountPath: /home/admin/oceanbase/log
- name: data
mountPath: /home/admin/oceanbase/store
volumes:
- name: log
persistentVolumeClaim:
claimName: log
- name: data
persistentVolumeClaim:
claimName: data
storageTemplates: # 对 Pod 所依赖的存储的描述
- name: log
pvc:
accessModes:
- ReadWriteOnce
storageClassName: "local-path"
resources:
requests:
storage: 1Gi
- name: data
pvc:
accessModes:
- ReadWriteOnce
storageClassName: "local-path"
resources:
requests:
storage: 1Gi
status:
cluster: cn
clusterStatus: Ready
subsets:
- name: zone1
expectedReplicas: 3
availableReplicas: 1
pods:
- name: sapp-1
index: 0
podPhase: Running
podIP: 10.10.10.1
nodeIP: 1.1.1.1
pvcs:
- name: sapp-cn-zone1-0-data-store
phase: Bound
此差异已折叠。
apiVersion: cloud.oceanbase.com/v1
kind: OBCluster
metadata:
namespace: ob
name: ob-test
spec:
version: v3.1.2-10000392021123010
clusterID: 1
topology:
- cluster: cn
zone:
- name: zone1
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
resources:
cpu: 2
memory: 10Gi
storage:
- name: data-file
storageClassName: "local-path"
size: 50Gi
- name: data-log
storageClassName: "local-path"
size: 50Gi
- name: log
storageClassName: "local-path"
size: 30Gi
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: oceanbase-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ob-operator-controller-manager
namespace: oceanbase-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ob-operator-leader-election-role
namespace: oceanbase-system
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: ob-operator-manager-role
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters/finalizers
verbs:
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- obclusters/status
verbs:
- get
- patch
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/finalizers
verbs:
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/sfinalizers
verbs:
- update
- apiGroups:
- cloud.oceanbase.com
resources:
- statefulapps/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- persistentvolumeclaims/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- persistentvolumes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- persistentvolumes/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- pods/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- pods/status
verbs:
- get
- patch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ob-operator-metrics-reader
rules:
- nonResourceURLs:
- /metrics
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ob-operator-proxy-role
rules:
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ob-operator-leader-election-rolebinding
namespace: oceanbase-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ob-operator-leader-election-role
subjects:
- kind: ServiceAccount
name: ob-operator-controller-manager
namespace: oceanbase-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: ob-operator-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ob-operator-manager-role
subjects:
- kind: ServiceAccount
name: ob-operator-controller-manager
namespace: oceanbase-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: ob-operator-proxy-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ob-operator-proxy-role
subjects:
- kind: ServiceAccount
name: ob-operator-controller-manager
namespace: oceanbase-system
---
apiVersion: v1
data:
controller_manager_config.yaml: |
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :8081
metrics:
bindAddress: 127.0.0.1:8080
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: ee2dec96.oceanbase.com
kind: ConfigMap
metadata:
name: ob-operator-manager-config
namespace: oceanbase-system
---
apiVersion: v1
kind: Service
metadata:
labels:
control-plane: controller-manager
name: ob-operator-controller-manager-metrics-service
namespace: oceanbase-system
spec:
ports:
- name: https
port: 8443
targetPort: https
selector:
control-plane: controller-manager
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: controller-manager
name: ob-operator-controller-manager
namespace: oceanbase-system
spec:
replicas: 1
selector:
matchLabels:
control-plane: controller-manager
template:
metadata:
labels:
control-plane: controller-manager
spec:
containers:
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
- --logtostderr=true
- --v=10
image: oceanbase/obce-operator:kube-rbac-proxy-v0.8.0
name: kube-rbac-proxy
ports:
- containerPort: 8443
name: https
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
command:
- /manager
image: oceanbase/obce-operator:v0.0.1
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
name: manager
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 1
memory: 1Gi
requests:
cpu: 1
memory: 1Gi
securityContext:
allowPrivilegeEscalation: false
securityContext:
runAsNonRoot: true
serviceAccountName: ob-operator-controller-manager
terminationGracePeriodSeconds: 10
# 架构设计
ob-operator 与其他 operator 一样,旨在让 OceanBase 以容器的方式,无缝运行在 Kubernetes 集群上。
现阶段的 ob-operator 是一个孵化版,即为一个具备基础功能的框架,后续还需不断的迭代与完善。
ob-operator 现已支持 OceanBase 集群的创建、删除,完整的节点生命周期管理,并通过 Service 的形式暴露给用户使用。
后续会支持租户管理、ob-proxy 管理、多 Kubernetes 集群等功能。
目前支持通过 YAML、Kustomize 来部署 ob-operator。
后续会支持 Helm 形式部署。
## 基础概念
![01](img/02.png)
OceanBase 具有很好的高可用能力。
OceanBase 集群由多个 Zone 和多台 OBServer 构成。
OceanBase 集群的唯一标识是集群名称和集群 ID。
![01](img/03.png)
一个 OceanBase 集群,由若干个 Zone 组成。
Zone 是可用区(Availability Zone)的简写。
Zone 本身是一个逻辑概念,一般是同一机房的一组机器的组合。
物理层面来讲一个 Zone 通常等价于一个机房、一个数据中心或一个 IDC。
为保障更高级别的数据安全性和服务可用性, 一个 OceanBase 集群通常会分布在同城的 3 个机房中,同一份数据的三个副本分别分布在 3 个机房中(即三个 Zone 中)。
OceanBase 数据库支持数据跨地域(Region)部署,且不同 Region 的距离通常较远,从而满足地域级容灾的需求。一个 Region 可以包含一个或者多个 Zone。
Kubernetes 场景下需要对不同的节点打 label,以标识不同的 Zone 和 Region。
现阶段 ob-operator 已支持多 Zone 部署,尚不支持多 Region 部署。
## 分层架构
![01](img/01.png)
整个项目分三块:StatefulApp Controller、OBServer Controller 和 Operator Orchestrator。
StatefulApp Controller 负责 Pod、PVC、PV 的维护。
OBServer Controller 负责 OBServer 的维护。
Operator Orchestrator 负责在多个 Kubernetes 之间管理 ob-operator(该模块尚未实现)。
由于 OBServer 的注册信息与通信地址以 IP 为主,所以 Kubernetes 资源层基于 Simple Pod 封装自定义 CRD 实现。
StatefulApp Controller 是一个类似 StatefulSet 的管控工具,但与 StatefulSet 略有区别:
- StatefulApp 为每个 Pod 维护了一个有粘性的 ID。
- 每个 Pod 有自己独立的存储,相互不共享。
- StatefulApp 支持 Pod 间配置异构。
- StatefulApp 的部署、更新是有序的,同 StatefulSet 一样。
- StatefulApp 支持对指定 Pod 做操作。
- StatefulApp 不支持基于 serviceName 的通信。
![01](img/04.png)
每个 Pod 会映射为一个 OBServer。
目前一个 Pod 中只包含一个 OBServer 容器,后续会以 Sidecar 的形式支持日志与监控容器。
OBServer 容器中会有一个很轻量的 Agent,负责与 OBServer Controller 交互、执行运维操作、维护 OBServer 进程。
![01](img/05.png)
OB Operator 会创建三种 CRD:OBCluster、OBRootService 和 OBServer。OBZone、OBRootService 为 OBCluster 的子资源。
OBCluster:
对 OceanBase 集群的定义,以整体的状态管理,全局视角,不涉及细节。用户需要自己定义 OBCluster 的配置。
```yaml
apiVersion: cloud.oceanbase.com/v1
kind: OBCluster
metadata:
namespace: oceanbase
name: ob-test
spec:
version: 3.1.1-4
clusterID: 1
topology:
- cluster: cn
zone:
- name: zone1
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: region1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
resources:
cpu: 2
memory: 10Gi
storage:
- name: data-file
storageClassName: "local-path"
size: 50Gi
- name: data-log
storageClassName: "local-path"
size: 50Gi
- name: log
storageClassName: "local-path"
size: 30Gi
status:
status: Ready
topology:
- cluster: cn
clusterStatus: Ready
lastTransitionTime: "2021-12-01T07:07:55Z"
zone:
- name: zone1
region: region1
zoneStatus: Ready
expectedReplicas: 1
availableReplicas: 1
- name: zone2
region: region1
zoneStatus: Ready
expectedReplicas: 1
availableReplicas: 1
- name: zone3
region: region1
zoneStatus: Ready
expectedReplicas: 1
availableReplicas: 1
```
OBZone:
Zone 维度 OBServer 的状态。用户可以通过 OBZone 来查看 OceanBase 集群中 OBServer 的状态。用户不需要创建,ob-operator 会自动维护并定期更新。
```yaml
apiVersion: cloud.oceanbase.com/v1
kind: OBZone
metadata:
namespace: oceanbase
name: obzone-ob-test
labels:
app: ob-test
spec:
topology:
- cluster: cn
zone:
- name: zone1
nodeSelector:
topology.kubernetes.io/zone: zone1
region: region1
replicas: 1
- name: zone2
nodeSelector:
topology.kubernetes.io/zone: zone2
region: region1
replicas: 1
- name: zone3
nodeSelector:
topology.kubernetes.io/zone: zone3
region: region1
replicas: 1
status:
topology:
- cluster: cn
zone:
- name: zone1
nodes:
- serverIP: 10.10.10.1
status: active
- name: zone2
nodes:
- serverIP: 10.10.10.2
status: active
- name: zone3
nodes:
- serverIP: 10.10.10.3
status: active
```
RootService:
集群维度 RootService 的分布情况、单个 RootService 的健康状态。用户可以通过 RootService 来查看 OceanBase 集群中 RootService 的状态。用户不需要创建,ob-operator 会自动维护并定期更新。
```yaml
apiVersion: cloud.oceanbase.com/v1
kind: RootService
metadata:
namespace: oceanbase
name: rs-ob-test
labels:
app: ob-test
spec:
topology:
- cluster: cn
zone:
- name: zone1
nodeSelector:
topology.kubernetes.io/zone: zone1
region: region1
replicas: 1
- name: zone2
nodeSelector:
topology.kubernetes.io/zone: zone2
region: region1
replicas: 1
- name: zone3
nodeSelector:
topology.kubernetes.io/zone: zone3
region: region1
replicas: 1
status:
topology:
- cluster: cn
zone:
- name: zone1
role: 1
serverIP: 10.10.10.1
status: active
- name: zone2
role: 2
serverIP: 10.10.10.2
status: active
- name: zone3
role: 2
serverIP: 10.10.10.3
status: active
```
# 自定义配置
## 部署 CRD
```yaml
kubectl apply -f ./deploy/crd.yaml
```
## 部署 ob-operator
您需要根据您的配置修改 `operator.yaml`
您需要添加启动参数 `--cluster-name`,该参数需要与 obcluster 中的 `cluster` 配置一致。
该配置的含义:ob-operator 只会处理 `cluster` 的值与自身启动参数 `--cluster-name` 的值相同的 CRD。
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: controller-manager
name: ob-operator-controller-manager
namespace: oceanbase-system
spec:
replicas: 1
selector:
matchLabels:
control-plane: controller-manager
template:
metadata:
labels:
control-plane: controller-manager
spec:
containers:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
- --cluster-name=cn
command:
- /manager
image: ob-operator:latest
imagePullPolicy: Always
name: manager
```
## 配置节点 label
需要将 Kubernetes 节点打 label,label 需要与 obcluster.yaml 中 `nodeSelector` 配置相匹配。ob-operator 会将 Pod 调度到具有相应 label 的节点上。
推荐配置 label 的 key 为 `topology.kubernetes.io/zone`。不同 Zone 推荐配置不同的 label 以做容灾。
```yaml
kubectl label node nodename topology.kubernetes.io/zone=zonename
```
## 部署 OceanBase 集群
`obcluster.yaml` 中需要用户根据自己的配置做一些修改。
```yaml
apiVersion: cloud.oceanbase.com/v1
kind: OBCluster
metadata:
namespace: oceanbase
name: ob-test
spec:
version: 3.1.1-4
clusterID: 1
topology:
- cluster: cn
zone:
- name: zone1
region: regio1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: regio1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: regio1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
resources:
cpu: 2
memory: 10Gi
storage:
- name: data-file
storageClassName: "local-path"
size: 50Gi
- name: data-log
storageClassName: "local-path"
size: 50Gi
- name: log
storageClassName: "local-path"
size: 30Gi
```
- `version` OceanBase 集群的版本。
- `cluster` 需要按需配置,如果需要在该 Kubernetes 集群中部署 OceanBase 集群,请将 `cluster` 配置为与 ob-operator 启动参数 `--cluster-name` 相同的配置。
- `cpu` 配置建议为大于 2 的整数,小于 2 会引发系统异常。
- `memory` 配置建议为大于 10Gi 的整数,小于 10Gi 会引发系统异常。
- `storage``data-file` 部分为 OBServer 系统配置项 `datafile_size` 的大小,建议为 `memory` 的 3 倍以上。`storageClassName` 用户可以自行按需配置。
- `storage``data-log` 部分为 OBServer 系统配置项 `data_dir` 的大小,建议为 `memory` 的 5 倍以上。`storageClassName` 用户可以自行按需配置。
- `storage``log` 部分为 OBServer 系统日志的大小,建议为 30Gi 以上。`storageClassName` 用户可以自行按需配置。
`nodeSelector` 的数据结构:
```go
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`
```
# 如何参与开发
## 代码目录结构
```yaml
.
├── Dockerfile
├── LEGAL.md
├── LICENSE
├── LICENSE.Apache
├── LICENSE.MIT
├── Makefile
├── PROJECT
├── README-CN.md
├── README.md
├── apis // CRD 定义
├── cmd
├── config // kustomize 相关配置与生成文件
├── deploy // 部署服务所使用的的文件
├── docs // 文档
├── go.mod
├── go.sum
├── hack
├── main.go
├── pkg
│ ├── cable // 守护进程逻辑
│ ├── config
│ ├── controllers
│ │ ├── observer // observer controller 逻辑
│ │ │ └── cable // 与 Agent 进程交互的部分
│ │ └── statefulapp // statefulapp controller 逻辑
│ ├── infrastructure
│ │ ├── kube
│ │ └── ob
│ ├── kubeclient
│ └── util
├── scripts
│ └── observer
└── test
└── e2e
```
# 文档
- [架构设计](arch-cn.md)
- [配置 OceanBase 集群](deploy-cn.md)
- [参与开发](develop-cn.md)
此差异已折叠。
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
\ No newline at end of file
//go:build tools
// +build tools
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
// 建立 tools.go 来依赖 code-generator
// 因为在没有代码使用 code-generator 时,go module 默认不依赖此包
package tools
import _ "k8s.io/code-generator"
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# get code-generator
K8S_VERSION=v0.22.1
go get k8s.io/code-generator@$K8S_VERSION
go get k8s.io/client-go@$K8S_VERSION
go get k8s.io/apimachinery@$K8S_VERSION
go get sigs.k8s.io/controller-runtime@v0.10.0
go mod vendor
chmod +x vendor/k8s.io/code-generator/generate-groups.sh
# corresponding to go mod init <module>
MODULE=github.com/oceanbase/ob-operator
# client package
OUTPUT_PKG=pkg/kubeclient
# api package
APIS_PKG=apis
# group-version
GROUP_VERSION=cloud:v1
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
rm -rf ${OUTPUT_PKG}/clientset
rm -rf ${OUTPUT_PKG}/listers
rm -rf ${OUTPUT_PKG}/informers
bash "${CODEGEN_PKG}"/generate-groups.sh "client,lister,informer" \
${MODULE}/${OUTPUT_PKG} \
${MODULE}/${APIS_PKG} \
${GROUP_VERSION} \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt
rm -rf vendor/
此差异已折叠。
此差异已折叠。
/*
Copyright (c) 2021 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package observer
const (
ProcessObserver = "observer"
)
var OBStarted bool
var Paused bool
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册