Skip to content

*: reconstructe the status controller #634

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

Draft
wants to merge 2 commits into
base: security_enhanced_version
Choose a base branch
from
Draft
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
92 changes: 92 additions & 0 deletions api/v1alpha1/mysqlcluster_status_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
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

import (
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ClusterState defines cluster state.
type ClusterState string

const (
// ClusterInitState indicates whether the cluster is initializing.
ClusterInitState ClusterState = "Initializing"
// ClusterUpdateState indicates whether the cluster is being updated.
ClusterUpdateState ClusterState = "Updating"
// ClusterReadyState indicates whether all containers in the pod are ready.
ClusterReadyState ClusterState = "Ready"
// ClusterCloseState indicates whether the cluster is closed.
ClusterCloseState ClusterState = "Closed"
// ClusterScaleInState indicates whether the cluster replicas is decreasing.
ClusterScaleInState ClusterState = "ScaleIn"
// ClusterScaleOutState indicates whether the cluster replicas is increasing.
ClusterScaleOutState ClusterState = "ScaleOut"
)

// ClusterConditionType defines type for cluster condition type.
type ClusterConditionType string

const (
ClusterInitialized ClusterConditionType = "Initialized"
ClusterAvaliable ClusterConditionType = "Avaliable"
ClusterInUpgrade ClusterConditionType = "InUpgrade"
ClusterAllReady ClusterConditionType = "AllReady"
)

// MySQLClusterCondition defines type for cluster conditions.
type MySQLClusterCondition struct {
// Type of cluster condition, values in (\"Initializing\", \"Ready\", \"Error\").
Type ClusterConditionType `json:"type"`
// Status of the condition, one of (\"True\", \"False\", \"Unknown\").
Status metav1.ConditionStatus `json:"status"`
}

// MysqlClusterStatus defines the observed state of MysqlCluster
type MysqlClusterStatus struct {
// StatefulSetStatus is the status of the StatefulSet reconciled by the mysqlcluster controller.
StatefulSetStatus *appsv1.StatefulSetStatus `json:"statefulSetStatus,omitempty"`
// State is the state of the mysqlcluster.
State ClusterState `json:"state,omitempty"`
// Conditions contains the list of the mysqlcluster conditions.
Conditions []MySQLClusterCondition `json:"conditions,omitempty"`
}

func (s *MysqlClusterStatus) GetStatefulSetStatus() *appsv1.StatefulSetStatus {
return s.StatefulSetStatus
}

func (s *MysqlClusterStatus) GetState() ClusterState {
return s.State
}

func (s *MysqlClusterStatus) GetConditions() []MySQLClusterCondition {
return s.Conditions
}

func (s *MysqlClusterStatus) SetStatefulSetStatus(status *appsv1.StatefulSetStatus) {
s.StatefulSetStatus = status
}

func (s *MysqlClusterStatus) SetState(state ClusterState) {
s.State = state
}

func (s *MysqlClusterStatus) SetConditions(conditions []MySQLClusterCondition) {
s.Conditions = conditions
}
123 changes: 0 additions & 123 deletions api/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,129 +270,6 @@ type Persistence struct {
Size string `json:"size,omitempty"`
}

// ClusterState defines cluster state.
type ClusterState string

const (
// ClusterInitState indicates whether the cluster is initializing.
ClusterInitState ClusterState = "Initializing"
// ClusterUpdateState indicates whether the cluster is being updated.
ClusterUpdateState ClusterState = "Updating"
// ClusterReadyState indicates whether all containers in the pod are ready.
ClusterReadyState ClusterState = "Ready"
// ClusterCloseState indicates whether the cluster is closed.
ClusterCloseState ClusterState = "Closed"
// ClusterScaleInState indicates whether the cluster replicas is decreasing.
ClusterScaleInState ClusterState = "ScaleIn"
// ClusterScaleOutState indicates whether the cluster replicas is increasing.
ClusterScaleOutState ClusterState = "ScaleOut"
)

// ClusterConditionType defines type for cluster condition type.
type ClusterConditionType string

const (
// ConditionInit indicates whether the cluster is initializing.
ConditionInit ClusterConditionType = "Initializing"
// ConditionUpdate indicates whether the cluster is being updated.
ConditionUpdate ClusterConditionType = "Updating"
// ConditionReady indicates whether all containers in the pod are ready.
ConditionReady ClusterConditionType = "Ready"
// ConditionClose indicates whether the cluster is closed.
ConditionClose ClusterConditionType = "Closed"
// ConditionError indicates whether there is an error in the cluster.
ConditionError ClusterConditionType = "Error"
// ConditionScaleIn indicates whether the cluster replicas is decreasing.
ConditionScaleIn ClusterConditionType = "ScaleIn"
// ConditionScaleOut indicates whether the cluster replicas is increasing.
ConditionScaleOut ClusterConditionType = "ScaleOut"
)

// ClusterCondition defines type for cluster conditions.
type ClusterCondition struct {
// Type of cluster condition, values in (\"Initializing\", \"Ready\", \"Error\").
Type ClusterConditionType `json:"type"`
// Status of the condition, one of (\"True\", \"False\", \"Unknown\").
Status corev1.ConditionStatus `json:"status"`

// The last time this Condition type changed.
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
// One word, camel-case reason for current status of the condition.
Reason string `json:"reason,omitempty"`
// Full text reason for current status of the condition.
Message string `json:"message,omitempty"`
}

// NodeStatus defines type for status of a node into cluster.
type NodeStatus struct {
// Name of the node.
Name string `json:"name"`
// Full text reason for current status of the node.
Message string `json:"message,omitempty"`
// RaftStatus is the raft status of the node.
RaftStatus RaftStatus `json:"raftStatus,omitempty"`
// Conditions contains the list of the node conditions fulfilled.
Conditions []NodeCondition `json:"conditions,omitempty"`
}

type RaftStatus struct {
// Role is one of (LEADER/CANDIDATE/FOLLOWER/IDLE/INVALID)
Role string `json:"role,omitempty"`
// Leader is the name of the Leader of the current node.
Leader string `json:"leader,omitempty"`
// Nodes is a list of nodes that can be identified by the current node.
Nodes []string `json:"nodes,omitempty"`
}

// NodeCondition defines type for representing node conditions.
type NodeCondition struct {
// Type of the node condition.
Type NodeConditionType `json:"type"`
// Status of the node, one of (\"True\", \"False\", \"Unknown\").
Status corev1.ConditionStatus `json:"status"`
// The last time this Condition type changed.
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
}

// The index of the NodeStatus.Conditions.
type NodeConditionsIndex uint8

const (
IndexLagged NodeConditionsIndex = iota
IndexLeader
IndexReadOnly
IndexReplicating
)

// NodeConditionType defines type for node condition type.
type NodeConditionType string

const (
// NodeConditionLagged represents if the node is lagged.
NodeConditionLagged NodeConditionType = "Lagged"
// NodeConditionLeader represents if the node is leader or not.
NodeConditionLeader NodeConditionType = "Leader"
// NodeConditionReadOnly repesents if the node is read only or not
NodeConditionReadOnly NodeConditionType = "ReadOnly"
// NodeConditionReplicating represents if the node is replicating or not.
NodeConditionReplicating NodeConditionType = "Replicating"
)

// MysqlClusterStatus defines the observed state of MysqlCluster
type MysqlClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// ReadyNodes represents number of the nodes that are in ready state.
ReadyNodes int `json:"readyNodes,omitempty"`
// State
State ClusterState `json:"state,omitempty"`
// Conditions contains the list of the cluster conditions fulfilled.
Conditions []ClusterCondition `json:"conditions,omitempty"`
// Nodes contains the list of the node status fulfilled.
Nodes []NodeStatus `json:"nodes,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.readyNodes
Expand Down
105 changes: 21 additions & 84 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading