Skip to content

Commit

Permalink
dev: start CR unification
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsingerus committed May 15, 2024
1 parent 1217194 commit 597c2f7
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 222 deletions.
3 changes: 1 addition & 2 deletions pkg/apis/clickhouse.altinity.com/v1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ type IChi interface {
GetName() string
GetLabels() map[string]string
GetAnnotations() map[string]string
GetRuntime() IClickHouseInstallationRuntime
GetRuntime() ICustomResourceRuntime
GetRootServiceTemplate() (*ServiceTemplate, bool)
GetSpec() *ChiSpec
GetObjectMeta() meta.Object

WalkClusters(f func(cluster ICluster) error) []error
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/clickhouse.altinity.com/v1/type_chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (chi *ClickHouseInstallation) FillCHIPointer() {
cluster.Runtime.CHI = chi
shard.Runtime.CHI = chi
replica.Runtime.CHI = chi
host.SetCHI(chi)
host.SetCR(chi)
return nil
},
)
Expand Down Expand Up @@ -719,7 +719,7 @@ func (chi *ClickHouseInstallation) YAML(opts CopyCHIOptions) string {
return string(yamlBytes)
}

func (chi *ClickHouseInstallation) GetRuntime() IClickHouseInstallationRuntime {
func (chi *ClickHouseInstallation) GetRuntime() ICustomResourceRuntime {
return chi.ensureRuntime()
}

Expand Down
52 changes: 30 additions & 22 deletions pkg/apis/clickhouse.altinity.com/v1/type_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ import (

// Host defines host (a data replica within a shard) of .spec.configuration.clusters[n].shards[m]
type Host struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Insecure *StringBool `json:"insecure,omitempty" yaml:"insecure,omitempty"`
Secure *StringBool `json:"secure,omitempty" yaml:"secure,omitempty"`
HostPorts `json:",inline" yaml:",inline"`
Settings *Settings `json:"settings,omitempty" yaml:"settings,omitempty"`
Files *Settings `json:"files,omitempty" yaml:"files,omitempty"`
Templates *TemplatesList `json:"templates,omitempty" yaml:"templates,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
HostSecure `json:",inline" yaml:",inline"`
HostPorts `json:",inline" yaml:",inline"`
HostSettings `json:",inline" yaml:",inline"`
Templates *TemplatesList `json:"templates,omitempty" yaml:"templates,omitempty"`

Runtime HostRuntime `json:"-" yaml:"-"`
}

type HostSecure struct {
Insecure *StringBool `json:"insecure,omitempty" yaml:"insecure,omitempty"`
Secure *StringBool `json:"secure,omitempty" yaml:"secure,omitempty"`
}

type HostPorts struct {
// DEPRECATED - to be removed soon
Port *Int32 `json:"port,omitempty" yaml:"port,omitempty"`
Expand All @@ -44,6 +47,11 @@ type HostPorts struct {
InterserverHTTPPort *Int32 `json:"interserverHTTPPort,omitempty" yaml:"interserverHTTPPort,omitempty"`
}

type HostSettings struct {
Settings *Settings `json:"settings,omitempty" yaml:"settings,omitempty"`
Files *Settings `json:"files,omitempty" yaml:"files,omitempty"`
}

type HostRuntime struct {
// Internal data
Address HostAddress `json:"-" yaml:"-"`
Expand Down Expand Up @@ -154,7 +162,7 @@ func (host *Host) GetHostTemplate() (*HostTemplate, bool) {
return nil, false
}
name := host.Templates.GetHostTemplate()
return host.GetCHI().GetHostTemplate(name)
return host.GetCR().GetHostTemplate(name)
}

// GetPodTemplate gets pod template
Expand All @@ -163,7 +171,7 @@ func (host *Host) GetPodTemplate() (*PodTemplate, bool) {
return nil, false
}
name := host.Templates.GetPodTemplate()
return host.GetCHI().GetPodTemplate(name)
return host.GetCR().GetPodTemplate(name)
}

// GetServiceTemplate gets service template
Expand All @@ -172,7 +180,7 @@ func (host *Host) GetServiceTemplate() (*ServiceTemplate, bool) {
return nil, false
}
name := host.Templates.GetReplicaServiceTemplate()
return host.GetCHI().GetServiceTemplate(name)
return host.GetCR().GetServiceTemplate(name)
}

// GetStatefulSetReplicasNum gets stateful set replica num
Expand Down Expand Up @@ -208,38 +216,38 @@ func (host *Host) GetName() string {
return host.Name
}

// GetCHI gets CHI
func (host *Host) GetCHI() *ClickHouseInstallation {
// GetCR gets CHI
func (host *Host) GetCR() *ClickHouseInstallation {
if host == nil {
return nil
}
return host.Runtime.CHI
}

// HasCHI checks whether host has CHI
func (host *Host) HasCHI() bool {
return host.GetCHI() != nil
// HasCR checks whether host has CHI
func (host *Host) HasCR() bool {
return host.GetCR() != nil
}

func (host *Host) SetCHI(chi *ClickHouseInstallation) {
func (host *Host) SetCR(chi *ClickHouseInstallation) {
host.Runtime.CHI = chi
}

// GetCluster gets cluster
func (host *Host) GetCluster() *Cluster {
// Host has to have filled Address
return host.GetCHI().FindCluster(host.Runtime.Address.ClusterName)
return host.GetCR().FindCluster(host.Runtime.Address.ClusterName)
}

// GetShard gets shard
func (host *Host) GetShard() *ChiShard {
// Host has to have filled Address
return host.GetCHI().FindShard(host.Runtime.Address.ClusterName, host.Runtime.Address.ShardName)
return host.GetCR().FindShard(host.Runtime.Address.ClusterName, host.Runtime.Address.ShardName)
}

// GetAncestor gets ancestor of a host
func (host *Host) GetAncestor() *Host {
return host.GetCHI().GetAncestor().FindHost(
return host.GetCR().GetAncestor().FindHost(
host.Runtime.Address.ClusterName,
host.Runtime.Address.ShardName,
host.Runtime.Address.HostName,
Expand All @@ -253,7 +261,7 @@ func (host *Host) HasAncestor() bool {

// GetAncestorCHI gets ancestor of a host
func (host *Host) GetAncestorCHI() *ClickHouseInstallation {
return host.GetCHI().GetAncestor()
return host.GetCR().GetAncestor()
}

// HasAncestorCHI checks whether host has an ancestor
Expand All @@ -263,12 +271,12 @@ func (host *Host) HasAncestorCHI() bool {

// WalkVolumeClaimTemplates walks VolumeClaimTemplate(s)
func (host *Host) WalkVolumeClaimTemplates(f func(template *VolumeClaimTemplate)) {
host.GetCHI().WalkVolumeClaimTemplates(f)
host.GetCR().WalkVolumeClaimTemplates(f)
}

// IsStopped checks whether host is stopped
func (host *Host) IsStopped() bool {
return host.GetCHI().IsStopped()
return host.GetCR().IsStopped()
}

// IsNewOne checks whether host is a new one
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/clickhouse.altinity.com/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newClickHouseInstallationRuntime() *ClickHouseInstallationRuntime {
}
}

type IClickHouseInstallationRuntime interface {
type ICustomResourceRuntime interface {
GetAttributes() *ComparableAttributes
LockCommonConfig()
UnlockCommonConfig()
Expand Down
74 changes: 54 additions & 20 deletions pkg/apis/clickhouse.altinity.com/v1/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions pkg/controller/chi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (c *Controller) doUpdateCHIObjectStatus(ctx context.Context, chi *api.Click
return nil
}
log.V(1).M(chi).F().Error("NULL returned")
return fmt.Errorf("ERROR GetCHI (%s/%s): NULL returned", namespace, name)
return fmt.Errorf("ERROR GetCR (%s/%s): NULL returned", namespace, name)
}

// Update status of a real object.
Expand Down Expand Up @@ -845,7 +845,7 @@ func (c *Controller) installFinalizer(ctx context.Context, chi *api.ClickHouseIn
return err
}
if cur == nil {
return fmt.Errorf("ERROR GetCHI (%s/%s): NULL returned", chi.Namespace, chi.Name)
return fmt.Errorf("ERROR GetCR (%s/%s): NULL returned", chi.Namespace, chi.Name)
}

if util.InArray(FinalizerName, cur.GetObjectMeta().GetFinalizers()) {
Expand Down Expand Up @@ -873,7 +873,7 @@ func (c *Controller) uninstallFinalizer(ctx context.Context, chi *api.ClickHouse
return err
}
if cur == nil {
return fmt.Errorf("ERROR GetCHI (%s/%s): NULL returned", chi.Namespace, chi.Name)
return fmt.Errorf("ERROR GetCR (%s/%s): NULL returned", chi.Namespace, chi.Name)
}

cur.GetObjectMeta().SetFinalizers(util.RemoveFromArray(FinalizerName, cur.GetObjectMeta().GetFinalizers()))
Expand Down

0 comments on commit 597c2f7

Please sign in to comment.