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

*: merge he v2.4.0 function #789

Merged
merged 2 commits into from
May 28, 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
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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.
Expand All @@ -94,11 +94,12 @@ build: generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/manager/main.go

docker-build: ## Build docker image with the manager.
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 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-build: test ## Build docker image with the manager.
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 ${SIDECAR57_IMG}
Expand Down
41 changes: 40 additions & 1 deletion 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 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 @@ -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 Down
24 changes: 24 additions & 0 deletions api/v1alpha1/mysqlcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"net"
"strconv"
"strings"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -108,6 +109,9 @@ func (r *MysqlCluster) ValidateUpdate(old runtime.Object) error {
if err := r.validateNFSServerAddress(oldCluster); err != nil {
return err
}
if err := r.ValidataRo(); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -230,3 +234,23 @@ func (r *MysqlCluster) validBothS3NFS() error {
}
return nil
}

// Validata Readonly
func (r *MysqlCluster) ValidataRo() error {
if r.Spec.ReadOnlys != nil && len(r.Spec.ReadOnlys.Host) != 0 {
// 1. Host name must startwith <clusterName>-mysql-<number>
if !strings.HasPrefix(r.Spec.ReadOnlys.Host, r.Name+"-mysql-") {
goto err
}
numstr := strings.TrimPrefix(r.Spec.ReadOnlys.Host, r.Name+"-mysql-")
// if not num, or num is greater than Spec Replica - 1, return error
if num, err := strconv.Atoi(numstr); err != nil {
goto err
} else if num >= int(*r.Spec.Replicas) || num < 0 {
goto err
}
}
return nil
err:
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("spec.readonly's hostname is not exist in the cluster"))
}
57 changes: 57 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

41 changes: 40 additions & 1 deletion api/v1beta1/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"`
// Username of new user to create.
// Only be a combination of letters, numbers or underlines. The length can not exceed 26 characters.
// +optional
Expand Down Expand Up @@ -146,6 +148,22 @@ type MysqlClusterSpec struct {
Service *ServiceSpec `json:"service,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"`
}

type MySQLConfigs struct {
// Name of the `ConfigMap` containing MySQL config.
// +optional
Expand Down Expand Up @@ -269,6 +287,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 @@ -282,6 +302,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 @@ -300,6 +327,10 @@ const (
IndexLeader
IndexReadOnly
IndexReplicating
IndexRoInit
IndexRoReadOnly
IndexRoSemiClose
IndexRoReplicating
)

// NodeConditionType defines type for node condition type.
Expand All @@ -314,6 +345,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"
)

type XenonOpts struct {
Expand Down
Loading