Skip to content

Commit

Permalink
fix: The number of component replicas cannot be set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
daviderli614 committed Dec 10, 2023
1 parent c583e7d commit 5f29c80
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 40 deletions.
18 changes: 15 additions & 3 deletions apis/v1alpha1/defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

"github.com/imdario/mergo"
"google.golang.org/protobuf/proto"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
Expand All @@ -38,6 +39,11 @@ var (
defaultOpenTSDBServicePort = 4242
defaultMetaServicePort = 3002

// The default replicas for frontend/meta/datanode.
defaultFrontendReplicas int32 = 1
defaultMetaReplicas int32 = 1
defaultDatanodeReplicas int32 = 3

// The default storage settings for datanode.
defaultDataNodeStorageName = "datanode"
defaultDataNodeStorageSize = "10Gi"
Expand Down Expand Up @@ -98,30 +104,33 @@ func (in *GreptimeDBCluster) SetDefaults() error {
if in.Spec.Frontend != nil {
defaultGreptimeDBClusterSpec.Frontend = &FrontendSpec{
ComponentSpec: ComponentSpec{
Replicas: 1,
Template: &PodTemplateSpec{},
},
Service: ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
},
}
if in.Spec.Frontend.Replicas == nil || *in.Spec.Frontend.Replicas < 0 {
in.Spec.Frontend.Replicas = proto.Int32(defaultFrontendReplicas)
}
}

if in.Spec.Meta != nil {
defaultGreptimeDBClusterSpec.Meta = &MetaSpec{
ComponentSpec: ComponentSpec{
Replicas: 1,
Template: &PodTemplateSpec{},
},
ServicePort: int32(defaultMetaServicePort),
EnableRegionFailover: false,
}
if in.Spec.Meta.Replicas == nil || *in.Spec.Meta.Replicas < 0 {
in.Spec.Meta.Replicas = proto.Int32(defaultMetaReplicas)
}
}

if in.Spec.Datanode != nil {
defaultGreptimeDBClusterSpec.Datanode = &DatanodeSpec{
ComponentSpec: ComponentSpec{
Replicas: 3,
Template: &PodTemplateSpec{},
},
Storage: StorageSpec{
Expand All @@ -132,6 +141,9 @@ func (in *GreptimeDBCluster) SetDefaults() error {
WalDir: defaultDataNodeStorageMountPath + "/wal",
},
}
if in.Spec.Datanode.Replicas == nil || *in.Spec.Datanode.Replicas < 0 {
in.Spec.Datanode.Replicas = proto.Int32(defaultDatanodeReplicas)
}
}

if err := mergo.Merge(&in.Spec, defaultGreptimeDBClusterSpec); err != nil {
Expand Down
Loading

0 comments on commit 5f29c80

Please sign in to comment.