Skip to content

Commit

Permalink
feat(storage-node): add reconcile logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Xu-Wentao committed Apr 13, 2023
1 parent d513422 commit 39a3cfa
Show file tree
Hide file tree
Showing 19 changed files with 1,312 additions and 471 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pitr-golint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ name: golangci-lint
on:
push:
branches:
- main
- main
pull_request:
branches:
- main
- main
paths:
- 'pitr/**'
- '.github/workflows/pitr-golint.yml'
Expand All @@ -49,7 +49,7 @@ jobs:
go-version: '1.19'
- name: Download golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
- name: Lint Pitr Cli
- name: Lint Pitr Cli
run: |
cd pitr/cli
$(go env GOPATH)/bin/golangci-lint run -v --timeout 300s ./...
Expand Down
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
1 change: 0 additions & 1 deletion shardingsphere-operator/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ linters:
- staticcheck
- typecheck
- unused
- unused
- bodyclose
- cyclop
- nilerr
Expand Down
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 StorageNodeConditionType = "Available"
StorageNodeConditionTypeDegraded StorageNodeConditionType = "Degraded"
)

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:"user"`
Password string `json:"pass"`
}

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

0 comments on commit 39a3cfa

Please sign in to comment.