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

feat(storage-node): add reconcile logic #293

Merged
merged 1 commit into from
Apr 13, 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
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ header:
- 'cloudformation/multi-az/*.json'
- '**/*.json'
- '**/Cargo.lock'
- '**/mocks/**'

comment: on-failure
2 changes: 1 addition & 1 deletion shardingsphere-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fmt: ## Run go fmt against code.

.PHONY: test
test: manifests generate fmt envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -gcflags=-l ./... -coverprofile cover.out

.PHONY: clean
clean:
Expand Down
2 changes: 1 addition & 1 deletion shardingsphere-operator/api/v1alpha1/compute_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ComputeNodeUser struct {
Password string `json:"password"`
}

// ComputeNodeAuth is used to set up initial user to login compute node, and authority data of storage node.
// ComputeNodeAuthority is used to set up initial user to login compute node, and authority data of storage node.
type ComputeNodeAuthority struct {
Users []ComputeNodeUser `json:"users"`
// +optional
Expand Down
123 changes: 120 additions & 3 deletions shardingsphere-operator/api/v1alpha1/storage_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,65 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type StorageNodePhaseStatus string

const (
StorageNodePhaseReady StorageNodePhaseStatus = "Ready"
StorageNodePhaseNotReady StorageNodePhaseStatus = "NotReady"
)

type StorageNodeConditionType string

// StorageNodeConditionType shows some states during the startup process of storage node
const (
// StorageNodeConditionTypeAvailable means the all the instances and the cluster are ready, and the storage node is ready to provide external services.
StorageNodeConditionTypeAvailable StorageNodeConditionType = "Available"
mlycore marked this conversation as resolved.
Show resolved Hide resolved
)

type StorageNodeConditions []*StorageNodeCondition

// StorageNodeCondition contains details for the current condition of this StorageNode.
type StorageNodeCondition struct {
Type StorageNodeConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
Reason string `json:"reason"`
Message string `json:"message"`
}

// ClusterStatus is the status of a database cluster, including the primary endpoint, reader endpoints, and other properties.
// Properties are some additional information about the cluster, like 'arn, identifier, credentials, etc.'
type ClusterStatus struct {
Status string `json:"status"`
PrimaryEndpoint Endpoint `json:"primaryEndpoint"`
ReaderEndpoints []Endpoint `json:"readerEndpoints"`
Properties map[string]string `json:"properties"`
}

type CredentialType struct {
BasicCredential `json:"basic_credential"`
}

type InstanceStatus struct {
Status string `json:"status"`
Endpoint Endpoint `json:"primaryEndpoint"`
Properties map[string]string `json:"properties"`
}

type BasicCredential struct {
Username string `json:"username"`
Password string `json:"password"`
}

type Endpoint struct {
Address string `json:"address"`
Port int32 `json:"port"`
}

// +kubebuilder:object:root=true
// StorageNodeList contains a list of StorageNode
Expand All @@ -41,7 +99,66 @@ type StorageNode struct {
}

// StorageNodeSpec defines the desired state of a set of storage units
type StorageNodeSpec struct{}
type StorageNodeSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:DatabaseClass defined by: https://github.com/database-mesh/golang-sdk/blob/main/kubernetes/api/v1alpha1/databaseclass.go
DatabaseClassName string `json:"databaseClassName"`
// +optional
Schema string `json:"schema"`
}

// StorageNodeStatus defines the actual state of a set of storage units
type StorageNodeStatus struct{}
type StorageNodeStatus struct {
// The generation observed by the StorageNode controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Phase is a brief summary of the StorageNode life cycle
// There are two possible phase values:
// Ready: StorageNode can already provide external services
// NotReady: StorageNode cannot provide external services
// +optional
Phase StorageNodePhaseStatus `json:"phase"`

// Conditions The conditions array, the reason and message fields
// +optional
Conditions StorageNodeConditions `json:"conditions"`

// Cluster contains the current status of the StorageNode cluster
// +optional
Cluster ClusterStatus `json:"cluster,omitempty"`

// Instance contains the current status of the StorageNode instance
// +optional
Instances []InstanceStatus `json:"instances,omitempty"`
}

// AddCondition adds the given condition to the StorageNodeConditions.
func (c *StorageNodeConditions) AddCondition(condition *StorageNodeCondition) {
*c = append(*c, condition)
}

// UpsertCondition updates the given condition in the StorageNodeConditions.
func (c *StorageNodeConditions) UpsertCondition(condition *StorageNodeCondition) {
for i, existing := range *c {
if existing.Type == condition.Type {
(*c)[i] = condition
return
}
}
c.AddCondition(condition)
}

// RemoveCondition removes the given condition from the StorageNodeConditions.
func (c *StorageNodeConditions) RemoveCondition(conditionType StorageNodeConditionType) {
var newConditions []*StorageNodeCondition
for _, existing := range *c {
if existing.Type != conditionType {
newConditions = append(newConditions, existing)
}
}
*c = newConditions
}

func init() {
SchemeBuilder.Register(&StorageNode{}, &StorageNodeList{})
}
159 changes: 158 additions & 1 deletion shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go

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

Loading