Skip to content

Commit 42c8809

Browse files
authored
Add new annotations, add old annotations support for Database obj. (#113)
* add new annotations, make old annotations work with Database obj * add AnnotationValueTrue constant
1 parent c57786e commit 42c8809

File tree

6 files changed

+51
-22
lines changed

6 files changed

+51
-22
lines changed

api/v1alpha1/const.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ const (
3131
BinariesDir = "/opt/ydb/bin"
3232
DaemonBinaryName = "ydbd"
3333

34-
AnnotationSkipInitialization = "ydb.tech/skip-initialization"
34+
AnnotationUpdateStrategyOnDelete = "ydb.tech/update-strategy-on-delete"
35+
AnnotationSkipInitialization = "ydb.tech/skip-initialization"
36+
AnnotationDisableLivenessProbe = "ydb.tech/disable-liveness-probe"
37+
AnnotationDataCenter = "ydb.tech/data-center"
38+
39+
AnnotationValueTrue = "true"
3540

3641
legacyTenantNameFormat = "/%s/%s"
3742
)

deploy/ydb-operator/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.4.25
18+
version: 0.4.26
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.4.25"
24+
appVersion: "0.4.26"

internal/controllers/database/sync.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func (r *Reconciler) setInitialStatus(
299299
) (bool, ctrl.Result, error) {
300300
r.Log.Info("running step setInitialStatus")
301301

302-
if value, ok := database.Annotations[v1alpha1.AnnotationSkipInitialization]; ok && value == "true" {
302+
if value, ok := database.Annotations[v1alpha1.AnnotationSkipInitialization]; ok && value == v1alpha1.AnnotationValueTrue {
303303
if meta.FindStatusCondition(database.Status.Conditions, TenantInitializedCondition) == nil ||
304304
meta.IsStatusConditionFalse(database.Status.Conditions, TenantInitializedCondition) {
305305
return r.processSkipInitPipeline(ctx, database)

internal/controllers/storage/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (r *Reconciler) setInitialStatus(
4949
// It is needed when large clusters are migrated where `waitForStatefulSetToScale`
5050
// does not make sense, since some nodes can be down for a long time (and it is okay, since
5151
// database is healthy even with partial outage).
52-
if value, ok := storage.Annotations[v1alpha1.AnnotationSkipInitialization]; ok && value == "true" {
52+
if value, ok := storage.Annotations[v1alpha1.AnnotationSkipInitialization]; ok && value == v1alpha1.AnnotationValueTrue {
5353
if meta.FindStatusCondition(storage.Status.Conditions, StorageInitializedCondition) == nil ||
5454
meta.IsStatusConditionFalse(storage.Status.Conditions, StorageInitializedCondition) {
5555
return r.processSkipInitPipeline(ctx, storage)

internal/resources/database_statefulset.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"log"
7+
"regexp"
78
"strconv"
89

910
appsv1 "k8s.io/api/apps/v1"
@@ -26,6 +27,8 @@ type DatabaseStatefulSetBuilder struct {
2627
Storage *v1alpha1.Storage
2728
}
2829

30+
var annotationDataCenterPattern = regexp.MustCompile("^[a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$")
31+
2932
func (b *DatabaseStatefulSetBuilder) Build(obj client.Object) error {
3033
sts, ok := obj.(*appsv1.StatefulSet)
3134
if !ok {
@@ -49,6 +52,12 @@ func (b *DatabaseStatefulSetBuilder) Build(obj client.Object) error {
4952
Template: b.buildPodTemplateSpec(),
5053
}
5154

55+
if value, ok := b.ObjectMeta.Annotations[v1alpha1.AnnotationUpdateStrategyOnDelete]; ok && value == v1alpha1.AnnotationValueTrue {
56+
sts.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
57+
Type: "OnDelete",
58+
}
59+
}
60+
5261
return nil
5362
}
5463

@@ -342,13 +351,7 @@ func (b *DatabaseStatefulSetBuilder) buildContainer() corev1.Container {
342351
Command: command,
343352
Args: args,
344353
Env: b.buildEnv(),
345-
LivenessProbe: &corev1.Probe{
346-
ProbeHandler: corev1.ProbeHandler{
347-
TCPSocket: &corev1.TCPSocketAction{
348-
Port: intstr.FromInt(v1alpha1.GRPCPort),
349-
},
350-
},
351-
},
354+
352355
VolumeMounts: b.buildVolumeMounts(),
353356
SecurityContext: &corev1.SecurityContext{
354357
Privileged: ptr.Bool(false),
@@ -358,6 +361,16 @@ func (b *DatabaseStatefulSetBuilder) buildContainer() corev1.Container {
358361
},
359362
}
360363

364+
if value, ok := b.ObjectMeta.Annotations[v1alpha1.AnnotationDisableLivenessProbe]; !ok || value != v1alpha1.AnnotationValueTrue {
365+
container.LivenessProbe = &corev1.Probe{
366+
ProbeHandler: corev1.ProbeHandler{
367+
TCPSocket: &corev1.TCPSocketAction{
368+
Port: intstr.FromInt(v1alpha1.GRPCPort),
369+
},
370+
},
371+
}
372+
}
373+
361374
ports := []corev1.ContainerPort{{
362375
Name: "grpc", ContainerPort: v1alpha1.GRPCPort,
363376
}, {
@@ -553,6 +566,15 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
553566
strconv.Itoa(v1alpha1.GRPCPort),
554567
)
555568

569+
if value, ok := b.ObjectMeta.Annotations[v1alpha1.AnnotationDataCenter]; ok {
570+
if annotationDataCenterPattern.MatchString(value) {
571+
args = append(args,
572+
"--data-center",
573+
value,
574+
)
575+
}
576+
}
577+
556578
return command, args
557579
}
558580

internal/resources/storage_statefulset.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import (
1818
)
1919

2020
const (
21-
configVolumeName = "ydb-config"
22-
annotationUpdateStrategyOnDelete = "ydb.tech/update-strategy-on-delete"
21+
configVolumeName = "ydb-config"
2322
)
2423

2524
type StorageStatefulSetBuilder struct {
@@ -69,7 +68,7 @@ func (b *StorageStatefulSetBuilder) Build(obj client.Object) error {
6968
Template: b.buildPodTemplateSpec(),
7069
}
7170

72-
if value, ok := b.ObjectMeta.Annotations[annotationUpdateStrategyOnDelete]; ok && value == "true" {
71+
if value, ok := b.ObjectMeta.Annotations[v1alpha1.AnnotationUpdateStrategyOnDelete]; ok && value == v1alpha1.AnnotationValueTrue {
7372
sts.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
7473
Type: "OnDelete",
7574
}
@@ -299,13 +298,6 @@ func (b *StorageStatefulSetBuilder) buildContainer() corev1.Container { // todo
299298
ImagePullPolicy: *b.Spec.Image.PullPolicyName,
300299
Command: command,
301300
Args: args,
302-
LivenessProbe: &corev1.Probe{
303-
ProbeHandler: corev1.ProbeHandler{
304-
TCPSocket: &corev1.TCPSocketAction{
305-
Port: intstr.FromInt(v1alpha1.GRPCPort),
306-
},
307-
},
308-
},
309301

310302
SecurityContext: &corev1.SecurityContext{
311303
Privileged: ptr.Bool(false),
@@ -326,6 +318,16 @@ func (b *StorageStatefulSetBuilder) buildContainer() corev1.Container { // todo
326318
Resources: b.Spec.Resources,
327319
}
328320

321+
if value, ok := b.ObjectMeta.Annotations[v1alpha1.AnnotationDisableLivenessProbe]; !ok || value != v1alpha1.AnnotationValueTrue {
322+
container.LivenessProbe = &corev1.Probe{
323+
ProbeHandler: corev1.ProbeHandler{
324+
TCPSocket: &corev1.TCPSocketAction{
325+
Port: intstr.FromInt(v1alpha1.GRPCPort),
326+
},
327+
},
328+
}
329+
}
330+
329331
var volumeDeviceList []corev1.VolumeDevice // todo decide on PVC volumeMode?
330332
var volumeMountList []corev1.VolumeMount
331333
for i, spec := range b.Spec.DataStore {

0 commit comments

Comments
 (0)