Skip to content

Commit

Permalink
refactor: deprecate hmeta
Browse files Browse the repository at this point in the history
  • Loading branch information
g1eny0ung committed Apr 8, 2024
1 parent 685a752 commit 7cabe1a
Show file tree
Hide file tree
Showing 29 changed files with 259 additions and 7,021 deletions.
1 change: 0 additions & 1 deletion api/v1alpha2/component_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
ComponentTypeConsole ComponentType = "console"
ComponentTypeHServer ComponentType = "hserver"
ComponentTypeHStore ComponentType = "hstore"
ComponentTypeHMeta ComponentType = "hmeta"
)

func (ct ComponentType) GetResName(hdb *HStreamDB) string {
Expand Down
12 changes: 6 additions & 6 deletions api/v1alpha2/condition_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

const (
HMetaReady string = "HMetaReady"
HStoreReady string = "HStoreReady"
HServerReady string = "HServerReady"
GatewayReady string = "GatewayReady"
ConsoleReady string = "ConsoleReady"
Ready string = "Ready"
InternalRqliteReady string = "InternalRqliteReady"
HStoreReady string = "HStoreReady"
HServerReady string = "HServerReady"
GatewayReady string = "GatewayReady"
ConsoleReady string = "ConsoleReady"
Ready string = "Ready"
)

func (hdb *HStreamDB) IsConditionTrue(conditionType string) bool {
Expand Down
74 changes: 41 additions & 33 deletions api/v1alpha2/hstreamdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha2

import (
"strconv"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -50,32 +50,36 @@ type HStreamDBList struct {

// HStreamDBSpec defines the desired state of HStreamDB
type HStreamDBSpec struct {
// ExternalHMeta set external HMeta cluster addr
// +optional
ExternalHMeta *ExternalHMeta `json:"externalHmeta,omitempty"`

Config Config `json:"config,omitempty"`

Gateway *Gateway `json:"gateway,omitempty"`
Console *Component `json:"console,omitempty"`
AdminServer Component `json:"adminServer,omitempty"`
HServer Component `json:"hserver,omitempty"`
HStore Component `json:"hstore,omitempty"`
HMeta Component `json:"hmeta,omitempty"`
Gateway *Gateway `json:"gateway,omitempty"`

Console *Component `json:"console,omitempty"`

AdminServer Component `json:"adminServer,omitempty"`

HServer Component `json:"hserver,omitempty"`

HStore Component `json:"hstore,omitempty"`

// +kubebuilder:validation:Required
Rqlite Rqlite `json:"rqlite"`
}

type ExternalHMeta struct {
// Host set external HMeta cluster host, it can be ip addr or service name
type Rqlite struct {
// +kubebuilder:validation:Required
Host string `json:"host"`

// +kubebuilder:validation:Required
Port int32 `json:"port"`
// Namespace the namespace of external HMeta cluster
// +kubebuilder:default:=default
// +optional

Namespace string `json:"namespace"`
}

func (r *Rqlite) GetAddr() string {
return fmt.Sprintf("%s.%s:%d", r.Host, r.Namespace, r.Port)
}

type Config struct {
// KafkaMode decides whether to use Kafka protocol or not.
//
Expand Down Expand Up @@ -119,31 +123,35 @@ type Config struct {
// HStreamDBStatus defines the observed state of HStreamDB
type HStreamDBStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
// HMeta store the status of HMeta cluster
HMeta HMetaStatus `json:"hmeta"`

InternalRqlite InternalRqliteStatus `json:"internalRqlite,omitempty"`
}

type HMetaStatus struct {
// Nodes the status of node that return by api http://localhost:4001/status?pretty in HMeta pod
Nodes []HMetaNode `json:"nodes"`
Version string `json:"version"`
type InternalRqliteStatus struct {
Nodes map[string]RqliteNode `json:"nodes"`
}

type HMetaNode struct {
NodeId string `json:"nodeId"`
type RqliteNode struct {
Id string `json:"id"`
Addr string `json:"addr"`
Reachable bool `json:"reachable"`
Leader bool `json:"leader"`
Error string `json:"error,omitempty"`
}

func init() {
SchemeBuilder.Register(&HStreamDB{}, &HStreamDBList{})
}
func (rs *InternalRqliteStatus) IsAllNodesReady() bool {
if len(rs.Nodes) == 0 {
return false
}

func (er *ExternalHMeta) GetAddr() string {
addr := er.Host
if er.Namespace != "" {
addr += "." + er.Namespace
for _, node := range rs.Nodes {
if !node.Reachable {
return false
}
}
return addr + ":" + strconv.Itoa(int(er.Port))

return true
}

func init() {
SchemeBuilder.Register(&HStreamDB{}, &HStreamDBList{})
}
111 changes: 54 additions & 57 deletions api/v1alpha2/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 7cabe1a

Please sign in to comment.