Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.0.0 #801

Merged
merged 19 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
.git
bin
testbin
vendor
vendor
test
1 change: 1 addition & 0 deletions .github/workflows/code_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
run: |
make manifests
make generate
git checkout config/webhook/manifests.yaml

- name: Check crd
run: d="$(git status -s)" && if [ -n "$d" ]; then echo "check-crd error:" ; echo "$d"; exit 1; fi
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ COPY utils/ utils/
COPY mysqluser/ mysqluser/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -oPg manager cmd/manager/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager cmd/manager/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
7 changes: 6 additions & 1 deletion Dockerfile.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ COPY sidecar/ sidecar/
COPY utils/ utils/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/sidecar cmd/sidecar/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -a -o bin/sidecar cmd/sidecar/main.go

# Build mysql checker for mysql conatiner
COPY cmd/mysql/main.go cmd/mysql/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -a -o bin/mysqlchecker cmd/mysql/main.go

###############################################################################
# Docker image for Sidecar
Expand Down Expand Up @@ -52,4 +56,5 @@ RUN set -ex; \

WORKDIR /
COPY --from=builder /workspace/bin/sidecar /usr/local/bin/sidecar
COPY --from=builder /workspace/bin/mysqlchecker /mnt/mysqlchecker
ENTRYPOINT ["sidecar"]
89 changes: 54 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Image URL to use all building/pushing image targets
FROM_VERSION ?=v2.2.1
CHART_VERSION ?=2.2.1
CHART_TOVERSION ?=2.3.0
TO_VERSION ?=v2.3.0
FROM_VERSION ?=v2.3.0
CHART_VERSION ?=2.3.0
CHART_TOVERSION ?=3.0.0-alpha
TO_VERSION ?=v3.0.0-alpha
TAG ?=v3.0.0-alpha
IMGPREFIX ?=radondb/
MYSQL_IMAGE_57 ?=5.7.39
MYSQL_IMAGE_80 ?=8.0.26
MYSQL_IMAGE_57_TAG ?=$(IMGPREFIX)percona-server:$(MYSQL_IMAGE_57)
MYSQL_IMAGE_80_TAG ?=$(IMGPREFIX)percona-server:$(MYSQL_IMAGE_80)
IMG ?= $(IMGPREFIX)mysql-operator:latest
SIDECAR57_IMG ?= $(IMGPREFIX)mysql57-sidecar:latest
SIDECAR80_IMG ?= $(IMGPREFIX)mysql80-sidecar:latest
XENON_IMG ?= $(IMGPREFIX)xenon:latest
GO_PORXY ?= off
IMG ?= $(IMGPREFIX)mysql-operator:$(TAG)
SIDECAR57_IMG ?= $(IMGPREFIX)mysql57-sidecar:$(TAG)
SIDECAR80_IMG ?= $(IMGPREFIX)mysql80-sidecar:$(TAG)
XENON_IMG ?= $(IMGPREFIX)xenon:$(TAG)
GO_PROXY ?= off
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"

UNAME := $(shell uname)
SEDFLAG := -i
ifeq ($(UNAME), Darwin)
SEDFLAG := -i ""
endif
ifeq ($(UNAME), Solaris)
# do something Solaris-y
endif
# 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
Expand Down Expand Up @@ -53,10 +57,11 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

update-crd: ## Synchronize the generated YAML files to operator Chart after make manifests.
make manifests
cp config/crd/bases/* charts/mysql-operator/crds/
##make manifests
@echo "should modify by manaual for mysqlclster and mysqlbackup"
cp config/crd/bases/mysql.radondb.com_mysqlusers.yaml charts/mysql-operator/crds/

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
generate: controller-gen generate-go-conversions ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

fmt: ## Run go fmt against code.
Expand All @@ -65,6 +70,15 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

CONVERSION_GEN := $(shell pwd)/bin/conversion-gen
CODE_GENERATOR_VERSION := $(shell awk '/k8s.io\/client-go/ {print substr($$2, 2)}' go.mod)
conversion-gen: ## Donwload conversion-gen locally if necessary.
$(call go-get-tool,$(CONVERSION_GEN),k8s.io/code-generator/cmd/conversion-gen@v$(CODE_GENERATOR_VERSION))
generate-go-conversions: conversion-gen $(CONVERSION_GEN) ## Generate conversions go code
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta1 \
--output-file-base=zz_generated.conversion --output-base=. \
--go-header-file=./hack/boilerplate.go.txt
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: manifests generate fmt vet ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
Expand All @@ -82,22 +96,20 @@ run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/manager/main.go

docker-build: test ## Build docker image with the manager.
docker buildx build --build-arg GO_PROXY=${GO_PORXY} -t ${IMG} .
docker buildx build -f Dockerfile.sidecar --build-arg GO_PROXY=${GO_PORXY} -t ${SIDECAR57_IMG} .
docker buildx build -f build/xenon/Dockerfile --build-arg GO_PROXY=${GO_PORXY} -t ${XENON_IMG} .
docker buildx build --build-arg XTRABACKUP_PKG=percona-xtrabackup-80 --build-arg GO_PROXY=${GO_PORXY} -f Dockerfile.sidecar -t ${SIDECAR80_IMG} .
docker buildx build --build-arg "MYSQL_IMAGE=${MYSQL_IMAGE_57}" --build-arg GO_PROXY=${GO_PORXY} -f build/mysql/Dockerfile -t ${MYSQL_IMAGE_57_TAG} .
docker buildx build --build-arg "MYSQL_IMAGE=${MYSQL_IMAGE_80}" --build-arg GO_PROXY=${GO_PORXY} -f build/mysql/Dockerfile -t ${MYSQL_IMAGE_80_TAG} .
docker-build-mysql57: test ## Build docker image with the manager.
docker buildx build --build-arg "MYSQL_IMAGE=${MYSQL_IMAGE_57}" --build-arg GO_PROXY=${GO_PORXY} -f build/mysql/Dockerfile -t ${MYSQL_IMAGE_57_TAG} .
DOCKER_BUILDKIT=1 docker build --build-arg GO_PROXY=${GO_PROXY} -t ${IMG} .
DOCKER_BUILDKIT=1 docker build -f Dockerfile.sidecar --build-arg GO_PROXY=${GO_PROXY} -t ${SIDECAR57_IMG} .
DOCKER_BUILDKIT=1 docker build -f Dockerfile.sidecar --build-arg GO_PROXY=${GO_PROXY} -t ${SIDECAR80_IMG} .
DOCKER_BUILDKIT=1 docker build -f build/xenon/Dockerfile --build-arg GO_PROXY=${GO_PROXY} -t ${XENON_IMG} .
DOCKER_BUILDKIT=1 docker build --build-arg XTRABACKUP_PKG=percona-xtrabackup-80 --build-arg GO_PROXY=${GO_PROXY} -f Dockerfile.sidecar -t ${SIDECAR80_IMG} .
docker-push: ## Push docker image with the manager.
docker push ${IMG}
docker push ${SIDECAR_IMG}
docker push ${SIDECAR57_IMG}
docker push ${SIDECAR80_IMG}
docker push ${XENON_IMG}

##@ Deployment

install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
install: 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.
Expand Down Expand Up @@ -141,13 +153,20 @@ todo:
@grep -Irnw './' -e 'TODO:'|grep -v grep

updateVersion:
find ./ -type f -name "*.go" -o -name "*.yaml" -exec sed -i "s/mysql57-sidecar:$(FROM_VERSION)/mysql57-sidecar:$(TO_VERSION)/g" {} \;
find ./ -type f -name "*.go" -o -name "*.yaml" -exec sed -i "s/xenon:$(FROM_VERSION)/xenon:$(TO_VERSION)/g" {} \;
find ./ -type f -name "*.go" -o -name "*.yaml" -exec sed -i "s/mysql-operator:$(FROM_VERSION)/mysql-operator:$(TO_VERSION)/g" {} \;
find ./ -type f -name "*.go" -o -name "*.yaml" -exec sed -i "s/mysql80-sidecar:$(FROM_VERSION)/mysql80-sidecar:$(TO_VERSION)/g" {} \;
find ./ -type f -name "*.go" -o -name "*.yaml" -exec sed -i "s/mysql-operator-$(FROM_VERSION)/mysql-operator-$(TO_VERSION)/g" {} \;
find ./ -type f -name "*.go" -o -name "*.yaml" -exec sed -i "s/\"$(FROM_VERSION)\"/\"$(TO_VERSION)\"/g" {} \;
find ./* -type f -name "*.go" -o -name "*.yaml" -exec sed $(SEDFLAG) "s/mysql57-sidecar:$(FROM_VERSION)/mysql57-sidecar:$(TO_VERSION)/g" {} \;
find ./* -type f -name "*.go" -o -name "*.yaml" -exec sed $(SEDFLAG) "s/xenon:$(FROM_VERSION)/xenon:$(TO_VERSION)/g" {} \;
find ./* -type f -name "*.go" -o -name "*.yaml" -exec sed $(SEDFLAG) "s/mysql-operator:$(FROM_VERSION)/mysql-operator:$(TO_VERSION)/g" {} \;
find ./* -type f -name "*.go" -o -name "*.yaml" -exec sed $(SEDFLAG) "s/mysql80-sidecar:$(FROM_VERSION)/mysql80-sidecar:$(TO_VERSION)/g" {} \;
find ./* -type f -name "*.go" -o -name "*.yaml" -exec sed $(SEDFLAG) "s/mysql-operator-$(FROM_VERSION)/mysql-operator-$(TO_VERSION)/g" {} \;
find ./* -type f -name "*.go" -o -name "*.yaml" -exec sed $(SEDFLAG) "s/\"$(FROM_VERSION)\"/\"$(TO_VERSION)\"/g" {} \;
# sed -i "18s/$(CHART_VERSION)/$(CHART_TOVERSION)/" charts/mysql-operator/charts/Chart.yaml
find ./charts -type f -name "*.yaml" -exec sed -i "s/$(CHART_VERSION)/$(CHART_TOVERSION)/g" {} \;
find ./config -type f -name "*.yaml" -exec sed -i "s/$(CHART_VERSION)/$(CHART_TOVERSION)/g" {} \;
find ./charts/* -type f -name "*.yaml" -exec sed $(SEDFLAG) "s/$(CHART_VERSION)/$(CHART_TOVERSION)/g" {} \;
find ./config/* -type f -name "*.yaml" -exec sed $(SEDFLAG) "s/$(CHART_VERSION)/$(CHART_TOVERSION)/g" {} \;

CRD_TO_MARKDOWN := $(shell pwd)/bin/crd-to-markdown
CRD_TO_MARKDOWN_VERSION = 0.0.3
crd-to-markdown: ## Download crd-to-markdown locally if necessary.
$(call go-get-tool,$(CRD_TO_MARKDOWN),github.com/clamoriniere/crd-to-markdown@v$(CRD_TO_MARKDOWN_VERSION))
apidoc: crd-to-markdown $(wildcard api/*/*_types.go)
$(CRD_TO_MARKDOWN) --links docs/links.csv -f api/v1beta1/mysqlcluster_types.go -n MySQLCluster > docs/crd_mysqlcluster_v1beta1.md

16 changes: 16 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resources:
path: github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
validation: true
webhookVersion: v1
- controller: true
Expand Down Expand Up @@ -47,4 +48,19 @@ resources:
kind: MysqlUser
path: github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1
version: v1alpha1
- domain: radondb.com
group: mysql
kind: MysqlCluster
version: v1beta1
- api:
crdVersion: v1
namespaced: true
domain: radondb.com
group: mysql
kind: Backup
path: github.com/radondb/radondb-mysql-kubernetes/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
version: "3"
2 changes: 1 addition & 1 deletion api/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type BackupSpec struct {

// To specify the image that will be used for sidecar container.
// +optional
// +kubebuilder:default:="radondb/mysql57-sidecar:v2.3.0"
// +kubebuilder:default:="radondb/mysql57-sidecar:v3.0.0-alpha"
Image string `json:"image"`

// HostName represents the host for which to take backup
Expand Down
17 changes: 17 additions & 0 deletions api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2021 RadonDB.

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.
*/

package v1alpha1
20 changes: 20 additions & 0 deletions api/v1alpha1/mysqlcluster_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2021 RadonDB.

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.
*/

package v1alpha1

func (*MysqlCluster) Hub() {}
func (*Backup) Hub() {}
50 changes: 45 additions & 5 deletions api/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ type MysqlClusterSpec struct {
// +kubebuilder:validation:Enum=0;1;2;3;5
// +kubebuilder:default:=3
Replicas *int32 `json:"replicas,omitempty"`

// Readonlys Info.
// +optional
ReadOnlys *ReadOnlyType `json:"readonlys,omitempty"`
// The number of pods from that set that must still be available after the
// eviction, even in the absence of the evicted pod
// +optional
Expand All @@ -48,7 +50,7 @@ type MysqlClusterSpec struct {

// XenonOpts is the options of xenon container.
// +optional
// +kubebuilder:default:={image: "radondb/xenon:v2.3.0", admitDefeatHearbeatCount: 5, electionTimeout: 10000, resources: {limits: {cpu: "100m", memory: "256Mi"}, requests: {cpu: "50m", memory: "128Mi"}}}
// +kubebuilder:default:={image: "radondb/xenon:v3.0.0-alpha", admitDefeatHearbeatCount: 5, electionTimeout: 10000, resources: {limits: {cpu: "100m", memory: "256Mi"}, requests: {cpu: "50m", memory: "128Mi"}}}
XenonOpts XenonOpts `json:"xenonOpts,omitempty"`

// MetricsOpts is the options of metrics container.
Expand All @@ -65,7 +67,7 @@ type MysqlClusterSpec struct {

// PodPolicy defines the policy to extra specification.
// +optional
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", extraResources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "radondb/mysql57-sidecar:v2.3.0", busyboxImage: "busybox:1.32"}
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", extraResources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "radondb/mysql57-sidecar:v3.0.0-alpha", busyboxImage: "busybox:1.32"}
PodPolicy PodPolicy `json:"podPolicy,omitempty"`

// PVC extra specifiaction.
Expand Down Expand Up @@ -106,6 +108,22 @@ type MysqlClusterSpec struct {
TlsSecretName string `json:"tlsSecretName,omitempty"`
}

// ReadOnly define the ReadOnly pods
type ReadOnlyType struct {
// ReadOnlys is the number of readonly pods.
Num int32 `json:"num"`
// When the host name is empty, use the leader to change master
// +optional
Host string `json:"hostname"`
// The compute resource requirements.
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
}

// MysqlOpts defines the options of MySQL container.
type MysqlOpts struct {
// Specifies mysql image to use.
Expand Down Expand Up @@ -188,7 +206,7 @@ type MysqlOpts struct {
type XenonOpts struct {
// To specify the image that will be used for xenon container.
// +optional
// +kubebuilder:default:="radondb/xenon:v2.3.0"
// +kubebuilder:default:="radondb/xenon:v3.0.0-alpha"
Image string `json:"image,omitempty"`

// High available component admit defeat heartbeat count.
Expand Down Expand Up @@ -255,7 +273,7 @@ type PodPolicy struct {

// To specify the image that will be used for sidecar container.
// +optional
// +kubebuilder:default:="radondb/mysql57-sidecar:v2.3.0"
// +kubebuilder:default:="radondb/mysql57-sidecar:v3.0.0-alpha"
SidecarImage string `json:"sidecarImage,omitempty"`

// The busybox image.
Expand Down Expand Up @@ -367,6 +385,8 @@ type NodeStatus struct {
Message string `json:"message,omitempty"`
// RaftStatus is the raft status of the node.
RaftStatus RaftStatus `json:"raftStatus,omitempty"`
// (RO) ReadOnly Status
RoStatus *RoStatus `json:"roStatus,omitempty"`
// Conditions contains the list of the node conditions fulfilled.
Conditions []NodeCondition `json:"conditions,omitempty"`
}
Expand All @@ -380,6 +400,13 @@ type RaftStatus struct {
Nodes []string `json:"nodes,omitempty"`
}

// (RO) node status
type RoStatus struct {
ReadOnly bool `json:"readOnlyReady,omitempty"`
Replication bool `json:"Replication,omitempty"`
Master string `json:"master,omitempty"`
}

// NodeCondition defines type for representing node conditions.
type NodeCondition struct {
// Type of the node condition.
Expand All @@ -398,6 +425,10 @@ const (
IndexLeader
IndexReadOnly
IndexReplicating
IndexRoInit
IndexRoReadOnly
IndexRoSemiClose
IndexRoReplicating
)

// NodeConditionType defines type for node condition type.
Expand All @@ -412,6 +443,14 @@ const (
NodeConditionReadOnly NodeConditionType = "ReadOnly"
// NodeConditionReplicating represents if the node is replicating or not.
NodeConditionReplicating NodeConditionType = "Replicating"
// ReadOnly Pod initing
NodeConditionRoInitial NodeConditionType = "RoInitial"
// ReadOnly Pod Set ReadOnly
NodeConditionRoReadOnly NodeConditionType = "RoReadOnly"
// ReadOnly Semi check close
NodeConditionRoSemiClose NodeConditionType = "RoSemiClose"
// ReadOnly Pod Ready
NodeConditionRoReplicating NodeConditionType = "RoReplicating"
)

// MysqlClusterStatus defines the observed state of MysqlCluster
Expand All @@ -431,6 +470,7 @@ type MysqlClusterStatus struct {

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.readyNodes
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The cluster status"
// +kubebuilder:printcolumn:name="Desired",type="integer",JSONPath=".spec.replicas",description="The number of desired replicas"
Expand Down
Loading