Skip to content

Commit e53b240

Browse files
authored
feat: support to configure standalone replicas (#334)
1 parent a64d189 commit e53b240

File tree

11 files changed

+103
-2
lines changed

11 files changed

+103
-2
lines changed

apis/v1alpha1/defaulting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ func (in *GreptimeDBStandalone) defaultSpec() *GreptimeDBStandaloneSpec {
414414
SlowQuery: defaultSlowQuery(),
415415
}
416416

417+
if in.Spec.Replicas == nil {
418+
defaultSpec.Replicas = ptr.To(int32(DefaultReplicas))
419+
}
420+
417421
return defaultSpec
418422
}
419423

apis/v1alpha1/greptimedbstandalone_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ type GreptimeDBStandaloneSpec struct {
6565
// +optional
6666
Version string `json:"version,omitempty"`
6767

68+
// The number of replicas of the standalone.
69+
// +optional
70+
// +kubebuilder:validation:Enum:={0, 1}
71+
Replicas *int32 `json:"replicas,omitempty"`
72+
6873
// Initializer is the init container to set up components configurations before running the container.
6974
// +optional
7075
Initializer *InitializerSpec `json:"initializer,omitempty"`
@@ -108,6 +113,12 @@ type GreptimeDBStandaloneSpec struct {
108113

109114
// GreptimeDBStandaloneStatus defines the observed state of GreptimeDBStandalone
110115
type GreptimeDBStandaloneStatus struct {
116+
// Replicas is the number of replicas of the standalone.
117+
Replicas int32 `json:"replicas"`
118+
119+
// ReadyReplicas is the number of ready replicas of the standalone.
120+
ReadyReplicas int32 `json:"readyReplicas"`
121+
111122
// Version is the version of the greptimedb.
112123
// +optional
113124
Version string `json:"version,omitempty"`
@@ -129,6 +140,7 @@ type GreptimeDBStandaloneStatus struct {
129140
// +kubebuilder:object:root=true
130141
// +kubebuilder:subresource:status
131142
// +kubebuilder:resource:shortName=gts
143+
// +kubebuilder:printcolumn:name="STANDALONE",type="integer",JSONPath=".status.readyReplicas"
132144
// +kubebuilder:printcolumn:name="PHASE",type=string,JSONPath=".status.standalonePhase"
133145
// +kubebuilder:printcolumn:name="VERSION",type=string,JSONPath=".status.version"
134146
// +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=".metadata.creationTimestamp"

apis/v1alpha1/testdata/defaulting/greptimedbcluster/setdefaults/test03/expect.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ spec:
102102
enabled: true
103103
logsCollection: {}
104104
standalone:
105+
replicas: 1
105106
base:
106107
main:
107108
image: greptime/greptimedb:latest

apis/v1alpha1/testdata/defaulting/greptimedbstandalone/test00/expect.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ spec:
99
mysqlPort: 4002
1010
postgreSQLPort: 4003
1111
rpcPort: 4001
12+
replicas: 1
1213
configMergeStrategy: ConfigMergeStrategyInjectedDataFirst
1314
base:
1415
main:

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/resources/greptime.io_greptimedbclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27340,6 +27340,12 @@ spec:
2734027340
required:
2734127341
- enabled
2734227342
type: object
27343+
replicas:
27344+
enum:
27345+
- 0
27346+
- 1
27347+
format: int32
27348+
type: integer
2734327349
rollingUpdate:
2734427350
properties:
2734527351
maxUnavailable:

config/crd/resources/greptime.io_greptimedbstandalones.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ spec:
1717
scope: Namespaced
1818
versions:
1919
- additionalPrinterColumns:
20+
- jsonPath: .status.readyReplicas
21+
name: STANDALONE
22+
type: integer
2023
- jsonPath: .status.standalonePhase
2124
name: PHASE
2225
type: string
@@ -3528,6 +3531,12 @@ spec:
35283531
required:
35293532
- enabled
35303533
type: object
3534+
replicas:
3535+
enum:
3536+
- 0
3537+
- 1
3538+
format: int32
3539+
type: integer
35313540
rollingUpdate:
35323541
properties:
35333542
maxUnavailable:
@@ -3663,10 +3672,19 @@ spec:
36633672
observedGeneration:
36643673
format: int64
36653674
type: integer
3675+
readyReplicas:
3676+
format: int32
3677+
type: integer
3678+
replicas:
3679+
format: int32
3680+
type: integer
36663681
standalonePhase:
36673682
type: string
36683683
version:
36693684
type: string
3685+
required:
3686+
- readyReplicas
3687+
- replicas
36703688
type: object
36713689
type: object
36723690
served: true

controllers/greptimedbstandalone/deployer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/klog/v2"
28-
"k8s.io/utils/ptr"
2928
ctrl "sigs.k8s.io/controller-runtime"
3029
"sigs.k8s.io/controller-runtime/pkg/client"
3130

@@ -141,6 +140,12 @@ func (d *StandaloneDeployer) CheckAndUpdateStatus(ctx context.Context, crdObject
141140
return false, err
142141
}
143142

143+
standalone.Status.Replicas = *sts.Spec.Replicas
144+
standalone.Status.ReadyReplicas = sts.Status.ReadyReplicas
145+
if err = UpdateStatus(ctx, standalone, d.Client); err != nil {
146+
klog.Errorf("Failed to update status: %s", err)
147+
}
148+
144149
return k8sutil.IsStatefulSetReady(sts), nil
145150
}
146151

@@ -251,7 +256,7 @@ func (b *standaloneBuilder) BuildStatefulSet() deployer.Builder {
251256
},
252257
Spec: appsv1.StatefulSetSpec{
253258
// Always set replicas to 1 for standalone mode.
254-
Replicas: ptr.To(int32(1)),
259+
Replicas: b.standalone.Spec.Replicas,
255260
Selector: &metav1.LabelSelector{
256261
MatchLabels: map[string]string{
257262
constant.GreptimeDBComponentName: common.ResourceName(b.standalone.Name, v1alpha1.StandaloneRoleKind),

docs/api-references/docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ _Appears in:_
495495
| `postgreSQLPort` _integer_ | PostgreSQLPort is the port of the greptimedb postgresql service. | | Maximum: 65535 <br />Minimum: 0 <br /> |
496496
| `prometheusMonitor` _[PrometheusMonitorSpec](#prometheusmonitorspec)_ | PrometheusMonitor is the specification for creating PodMonitor or ServiceMonitor. | | |
497497
| `version` _string_ | Version is the version of the greptimedb. | | |
498+
| `replicas` _integer_ | The number of replicas of the standalone. | | Enum: [0 1] <br /> |
498499
| `initializer` _[InitializerSpec](#initializerspec)_ | Initializer is the init container to set up components configurations before running the container. | | |
499500
| `objectStorage` _[ObjectStorageProviderSpec](#objectstorageproviderspec)_ | ObjectStorageProvider is the storage provider for the greptimedb cluster. | | |
500501
| `datanodeStorage` _[DatanodeStorageSpec](#datanodestoragespec)_ | DatanodeStorage is the default file storage of the datanode. For example, WAL, cache, index etc. | | |

manifests/bundle.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27346,6 +27346,12 @@ spec:
2734627346
required:
2734727347
- enabled
2734827348
type: object
27349+
replicas:
27350+
enum:
27351+
- 0
27352+
- 1
27353+
format: int32
27354+
type: integer
2734927355
rollingUpdate:
2735027356
properties:
2735127357
maxUnavailable:
@@ -27794,6 +27800,9 @@ spec:
2779427800
scope: Namespaced
2779527801
versions:
2779627802
- additionalPrinterColumns:
27803+
- jsonPath: .status.readyReplicas
27804+
name: STANDALONE
27805+
type: integer
2779727806
- jsonPath: .status.standalonePhase
2779827807
name: PHASE
2779927808
type: string
@@ -31305,6 +31314,12 @@ spec:
3130531314
required:
3130631315
- enabled
3130731316
type: object
31317+
replicas:
31318+
enum:
31319+
- 0
31320+
- 1
31321+
format: int32
31322+
type: integer
3130831323
rollingUpdate:
3130931324
properties:
3131031325
maxUnavailable:
@@ -31440,10 +31455,19 @@ spec:
3144031455
observedGeneration:
3144131456
format: int64
3144231457
type: integer
31458+
readyReplicas:
31459+
format: int32
31460+
type: integer
31461+
replicas:
31462+
format: int32
31463+
type: integer
3144331464
standalonePhase:
3144431465
type: string
3144531466
version:
3144631467
type: string
31468+
required:
31469+
- readyReplicas
31470+
- replicas
3144731471
type: object
3144831472
type: object
3144931473
served: true

0 commit comments

Comments
 (0)