Skip to content

Commit

Permalink
Add separate structure for data node
Browse files Browse the repository at this point in the history
Signed-off-by: Tapajit Chandra Paul <[email protected]>
  • Loading branch information
tapojit047 committed May 29, 2024
1 parent 2f4b9c1 commit d6cdd4e
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 635 deletions.
79 changes: 56 additions & 23 deletions apis/kubedb/v1alpha2/druid_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,40 @@ func (d *Druid) PetSetName(nodeRole DruidNodeRoleType) string {
}

func (d *Druid) PodLabels(nodeType DruidNodeRoleType, extraLabels ...map[string]string) map[string]string {
nodeSpec := d.GetNodeSpec(nodeType)
return d.offShootLabels(meta_util.OverwriteKeys(d.OffShootSelectors(), extraLabels...), nodeSpec.PodTemplate.Labels)
nodeSpec, dataNodeSpec := d.GetNodeSpec(nodeType)
var labels map[string]string
if nodeSpec != nil {
labels = nodeSpec.PodTemplate.Labels
} else {
labels = dataNodeSpec.PodTemplate.Labels
}
return d.offShootLabels(meta_util.OverwriteKeys(d.OffShootSelectors(), extraLabels...), labels)
}

func (d *Druid) PodControllerLabels(nodeType DruidNodeRoleType, extraLabels ...map[string]string) map[string]string {
nodeSpec := d.GetNodeSpec(nodeType)
return d.offShootLabels(meta_util.OverwriteKeys(d.OffShootSelectors(), extraLabels...), nodeSpec.PodTemplate.Controller.Labels)
nodeSpec, dataNodeSpec := d.GetNodeSpec(nodeType)
var labels map[string]string
if nodeSpec != nil {
labels = nodeSpec.PodTemplate.Controller.Labels
} else {
labels = dataNodeSpec.PodTemplate.Controller.Labels
}
return d.offShootLabels(meta_util.OverwriteKeys(d.OffShootSelectors(), extraLabels...), labels)
}

func (d *Druid) GetNodeSpec(nodeType DruidNodeRoleType) *DruidNode {
func (d *Druid) GetNodeSpec(nodeType DruidNodeRoleType) (*DruidNode, *DruidDataNode) {
if nodeType == DruidNodeRoleCoordinators {
return d.Spec.Topology.Coordinators
return d.Spec.Topology.Coordinators, nil
} else if nodeType == DruidNodeRoleOverlords {
return d.Spec.Topology.Overlords
return d.Spec.Topology.Overlords, nil
} else if nodeType == DruidNodeRoleMiddleManagers {
return d.Spec.Topology.MiddleManagers
return nil, d.Spec.Topology.MiddleManagers
} else if nodeType == DruidNodeRoleHistoricals {
return d.Spec.Topology.Historicals
return nil, d.Spec.Topology.Historicals
} else if nodeType == DruidNodeRoleBrokers {
return d.Spec.Topology.Brokers
return d.Spec.Topology.Brokers, nil
} else if nodeType == DruidNodeRoleRouters {
return d.Spec.Topology.Routers
return d.Spec.Topology.Routers, nil
}

panic("Node role name does not match any known types")
Expand Down Expand Up @@ -361,10 +373,6 @@ func (d *Druid) SetDefaults() {
d.Spec.TerminationPolicy = TerminationPolicyDelete
}

if d.Spec.StorageType == "" {
d.Spec.StorageType = StorageTypeDurable
}

if d.Spec.DisableSecurity == nil {
d.Spec.DisableSecurity = pointer.BoolP(false)
}
Expand Down Expand Up @@ -397,6 +405,9 @@ func (d *Druid) SetDefaults() {
d.Spec.Topology.Coordinators = &DruidNode{}
}
if d.Spec.Topology.Coordinators != nil {
if d.Spec.Topology.Coordinators.Replicas == nil {
d.Spec.Topology.Coordinators.Replicas = pointer.Int32P(1)
}
if version.Major() > 25 {
if d.Spec.Topology.Coordinators.PodTemplate.Spec.SecurityContext == nil {
d.Spec.Topology.Coordinators.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{FSGroup: druidVersion.Spec.SecurityContext.RunAsUser}
Expand All @@ -405,7 +416,11 @@ func (d *Druid) SetDefaults() {
d.setDefaultContainerResourceLimits(&d.Spec.Topology.Coordinators.PodTemplate, DruidNodeRoleCoordinators)
}
}

if d.Spec.Topology.Overlords != nil {
if d.Spec.Topology.Overlords.Replicas == nil {
d.Spec.Topology.Overlords.Replicas = pointer.Int32P(1)
}
if version.Major() > 25 {
if d.Spec.Topology.Overlords.PodTemplate.Spec.SecurityContext == nil {
d.Spec.Topology.Overlords.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{FSGroup: druidVersion.Spec.SecurityContext.RunAsUser}
Expand All @@ -416,12 +431,18 @@ func (d *Druid) SetDefaults() {
}

if d.Spec.Topology.MiddleManagers == nil {
d.Spec.Topology.MiddleManagers = &DruidNode{}
}
if d.Spec.Topology.MiddleManagers.Storage == nil && d.Spec.StorageType == StorageTypeDurable {
d.Spec.Topology.MiddleManagers.Storage = d.getDefaultPVC()
d.Spec.Topology.MiddleManagers = &DruidDataNode{}
}
if d.Spec.Topology.MiddleManagers != nil {
if d.Spec.Topology.MiddleManagers.Replicas == nil {
d.Spec.Topology.MiddleManagers.Replicas = pointer.Int32P(1)
}
if d.Spec.Topology.MiddleManagers.StorageType == "" {
d.Spec.Topology.MiddleManagers.StorageType = StorageTypeDurable
}
if d.Spec.Topology.MiddleManagers.Storage == nil && d.Spec.Topology.MiddleManagers.StorageType == StorageTypeDurable {
d.Spec.Topology.MiddleManagers.Storage = d.getDefaultPVC()
}
if version.Major() > 25 {
if d.Spec.Topology.MiddleManagers.PodTemplate.Spec.SecurityContext == nil {
d.Spec.Topology.MiddleManagers.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{FSGroup: druidVersion.Spec.SecurityContext.RunAsUser}
Expand All @@ -432,12 +453,18 @@ func (d *Druid) SetDefaults() {
}

if d.Spec.Topology.Historicals == nil {
d.Spec.Topology.Historicals = &DruidNode{}
}
if d.Spec.Topology.Historicals.Storage == nil && d.Spec.StorageType == StorageTypeDurable {
d.Spec.Topology.Historicals.Storage = d.getDefaultPVC()
d.Spec.Topology.Historicals = &DruidDataNode{}
}
if d.Spec.Topology.Historicals != nil {
if d.Spec.Topology.Historicals.Replicas == nil {
d.Spec.Topology.Historicals.Replicas = pointer.Int32P(1)
}
if d.Spec.Topology.Historicals.StorageType == "" {
d.Spec.Topology.Historicals.StorageType = StorageTypeDurable
}
if d.Spec.Topology.Historicals.Storage == nil && d.Spec.Topology.Historicals.StorageType == StorageTypeDurable {
d.Spec.Topology.Historicals.Storage = d.getDefaultPVC()
}
if version.Major() > 25 {
if d.Spec.Topology.Historicals.PodTemplate.Spec.SecurityContext == nil {
d.Spec.Topology.Historicals.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{FSGroup: druidVersion.Spec.SecurityContext.RunAsUser}
Expand All @@ -451,6 +478,9 @@ func (d *Druid) SetDefaults() {
d.Spec.Topology.Brokers = &DruidNode{}
}
if d.Spec.Topology.Brokers != nil {
if d.Spec.Topology.Brokers.Replicas == nil {
d.Spec.Topology.Brokers.Replicas = pointer.Int32P(1)
}
if version.Major() > 25 {
if d.Spec.Topology.Brokers.PodTemplate.Spec.SecurityContext == nil {
d.Spec.Topology.Brokers.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{FSGroup: druidVersion.Spec.SecurityContext.RunAsUser}
Expand All @@ -462,6 +492,9 @@ func (d *Druid) SetDefaults() {
}

if d.Spec.Topology.Routers != nil {
if d.Spec.Topology.Routers.Replicas == nil {
d.Spec.Topology.Routers.Replicas = pointer.Int32P(1)
}
if version.Major() > 25 {
if d.Spec.Topology.Routers.PodTemplate.Spec.SecurityContext == nil {
d.Spec.Topology.Routers.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{FSGroup: druidVersion.Spec.SecurityContext.RunAsUser}
Expand Down
23 changes: 14 additions & 9 deletions apis/kubedb/v1alpha2/druid_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ type DruidSpec struct {
// +optional
Topology *DruidClusterTopology `json:"topology,omitempty"`

// StorageType can be durable (default) or ephemeral.
StorageType StorageType `json:"storageType,omitempty"`

// disable security. It disables authentication security of user.
// If unset, default is false
// +optional
Expand Down Expand Up @@ -122,9 +119,9 @@ type DruidClusterTopology struct {
// +optional
Overlords *DruidNode `json:"overlords,omitempty"`

MiddleManagers *DruidNode `json:"middleManagers,omitempty"`
MiddleManagers *DruidDataNode `json:"middleManagers,omitempty"`

Historicals *DruidNode `json:"historicals,omitempty"`
Historicals *DruidDataNode `json:"historicals,omitempty"`

Brokers *DruidNode `json:"brokers,omitempty"`
// +optional
Expand All @@ -141,10 +138,6 @@ type DruidNode struct {
// +optional
Suffix string `json:"suffix,omitempty"`

// Storage to specify how storage shall be used.
// +optional
Storage *core.PersistentVolumeClaimSpec `json:"storage,omitempty"`

// PodTemplate is an optional configuration for pods used to expose database
// +optional
PodTemplate ofst.PodTemplateSpec `json:"podTemplate,omitempty"`
Expand All @@ -163,6 +156,18 @@ type DruidNode struct {
// +kubebuilder:default={name: "default"}
// +optional
PodPlacementPolicy *core.LocalObjectReference `json:"podPlacementPolicy,omitempty"`
}

type DruidDataNode struct {
// DruidDataNode has all the characteristics of DruidNode
DruidNode `json:",inline"`

// StorageType specifies if the storage
// of this node is durable (default) or ephemeral.
StorageType StorageType `json:"storageType,omitempty"`

// Storage to specify how storage shall be used.
Storage *core.PersistentVolumeClaimSpec `json:"storage,omitempty"`

// EphemeralStorage spec to specify the configuration of ephemeral storage type.
EphemeralStorage *core.EmptyDirVolumeSource `json:"ephemeralStorage,omitempty"`
Expand Down
Loading

0 comments on commit d6cdd4e

Please sign in to comment.