Skip to content

Commit 2213de1

Browse files
authored
Use subPath for ydb config (#191)
1 parent b54e0b9 commit 2213de1

File tree

8 files changed

+76
-10
lines changed

8 files changed

+76
-10
lines changed

deploy/ydb-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
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.5.4
18+
version: 0.5.5
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.5.4"
24+
appVersion: "0.5.5"

internal/annotations/annotations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const (
66
PrimaryResourceStorageAnnotation = "ydb.tech/primary-resource-storage"
77
PrimaryResourceDatabaseAnnotation = "ydb.tech/primary-resource-database"
88
RemoteResourceVersionAnnotation = "ydb.tech/remote-resource-version"
9+
ConfigurationChecksum = "ydb.tech/configuration-checksum"
910
RemoteFinalizerKey = "ydb.tech/remote-finalizer"
1011
LastAppliedAnnotation = "ydb.tech/last-applied"
1112
)

internal/controllers/storage/controller_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7+
"strconv"
78
"testing"
89

910
. "github.com/onsi/ginkgo/v2"
1011
. "github.com/onsi/gomega"
1112
appsv1 "k8s.io/api/apps/v1"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"k8s.io/apimachinery/pkg/types"
1416
"sigs.k8s.io/controller-runtime/pkg/client"
1517
"sigs.k8s.io/controller-runtime/pkg/manager"
1618

19+
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
1720
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
21+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
1822
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
23+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
24+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
1925
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
2026
)
2127

@@ -55,7 +61,7 @@ var _ = Describe("Storage controller medium tests", func() {
5561
Expect(k8sClient.Delete(ctx, &namespace)).Should(Succeed())
5662
})
5763

58-
It("Check volume has been propagated to pods", func() {
64+
It("Checking field propagation to objects", func() {
5965
storageSample := testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-block-4-2-config.yaml"))
6066

6167
tmpFilesDir := "/tmp/mounted_volume"
@@ -76,6 +82,7 @@ var _ = Describe("Storage controller medium tests", func() {
7682

7783
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
7884

85+
By("Check volume has been propagated to pods...")
7986
storageStatefulSets := appsv1.StatefulSetList{}
8087
Eventually(func() bool {
8188
Expect(k8sClient.List(ctx, &storageStatefulSets, client.InNamespace(
@@ -105,5 +112,28 @@ var _ = Describe("Storage controller medium tests", func() {
105112
}
106113
}
107114
Expect(foundVolume).To(BeTrue())
115+
116+
By("Check that label and annotation propagated to pods...", func() {
117+
podLabels := storageSS.Spec.Template.Labels
118+
podAnnotations := storageSS.Spec.Template.Annotations
119+
120+
foundStorage := v1alpha1.Storage{}
121+
Expect(k8sClient.Get(ctx, types.NamespacedName{
122+
Name: testobjects.StorageName,
123+
Namespace: testobjects.YdbNamespace,
124+
}, &foundStorage)).Should(Succeed())
125+
126+
foundStorageGenerationLabel := false
127+
if podLabels[labels.StorageGeneration] == strconv.FormatInt(foundStorage.ObjectMeta.Generation, 10) {
128+
foundStorageGenerationLabel = true
129+
}
130+
Expect(foundStorageGenerationLabel).To(BeTrue())
131+
132+
foundConfigurationChecksumAnnotation := false
133+
if podAnnotations[annotations.ConfigurationChecksum] == resources.GetConfigurationChecksum(foundStorage.Spec.Configuration) {
134+
foundConfigurationChecksumAnnotation = true
135+
}
136+
Expect(foundConfigurationChecksumAnnotation).To(BeTrue())
137+
})
108138
})
109139
})

internal/labels/label.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const (
2626
// RemoteClusterKey The specialization of a remote k8s cluster
2727
RemoteClusterKey = "ydb.tech/remote-cluster"
2828

29+
StorageGeneration = "ydb.tech/storage-generation"
30+
DatabaseGeneration = "ydb.tech/database-generation"
31+
2932
StorageComponent = "storage-node"
3033
DynamicComponent = "dynamic-node"
3134

internal/resources/database_statefulset.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717

1818
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
19+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
20+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
1921
"github.com/ydb-platform/ydb-kubernetes-operator/internal/ptr"
2022
)
2123

@@ -83,10 +85,16 @@ func (b *DatabaseStatefulSetBuilder) buildEnv() []corev1.EnvVar {
8385
}
8486

8587
func (b *DatabaseStatefulSetBuilder) buildPodTemplateSpec() corev1.PodTemplateSpec {
88+
podTemplateLabels := CopyDict(b.Labels)
89+
podTemplateLabels[labels.DatabaseGeneration] = strconv.FormatInt(b.ObjectMeta.Generation, 10)
90+
91+
podTemplateAnnotations := CopyDict(b.Spec.AdditionalAnnotations)
92+
podTemplateAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(b.Spec.Configuration)
93+
8694
podTemplate := corev1.PodTemplateSpec{
8795
ObjectMeta: metav1.ObjectMeta{
88-
Labels: b.Labels,
89-
Annotations: CopyDict(b.Spec.AdditionalAnnotations),
96+
Labels: podTemplateLabels,
97+
Annotations: podTemplateAnnotations,
9098
},
9199
Spec: corev1.PodSpec{
92100
Containers: []corev1.Container{b.buildContainer()},
@@ -417,7 +425,8 @@ func (b *DatabaseStatefulSetBuilder) buildVolumeMounts() []corev1.VolumeMount {
417425
volumeMounts = append(volumeMounts, corev1.VolumeMount{
418426
Name: configVolumeName,
419427
ReadOnly: true,
420-
MountPath: api.ConfigDir,
428+
MountPath: fmt.Sprintf("%s/%s", api.ConfigDir, api.ConfigFileName),
429+
SubPath: api.ConfigFileName,
421430
})
422431

423432
if b.Spec.Service.GRPC.TLSConfiguration.Enabled {

internal/resources/resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package resources
22

33
import (
44
"context"
5+
"crypto/sha256"
6+
"encoding/hex"
57
"errors"
68
"fmt"
79

@@ -488,3 +490,9 @@ func buildCAStorePatchingCommandArgs(
488490

489491
return command, args
490492
}
493+
494+
func GetConfigurationChecksum(configuration string) string {
495+
hasher := sha256.New()
496+
hasher.Write([]byte(configuration))
497+
return hex.EncodeToString(hasher.Sum(nil))
498+
}

internal/resources/storage_init_job.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package resources
33
import (
44
"errors"
55
"fmt"
6+
"strconv"
67

78
batchv1 "k8s.io/api/batch/v1"
89
corev1 "k8s.io/api/core/v1"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"sigs.k8s.io/controller-runtime/pkg/client"
1112

1213
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
14+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
1315
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
1416
"github.com/ydb-platform/ydb-kubernetes-operator/internal/ptr"
1517
)
@@ -64,9 +66,11 @@ func GetInitJobBuilder(storage *api.Storage) ResourceBuilder {
6466
if storage.Spec.InitJob != nil {
6567
if storage.Spec.InitJob.AdditionalLabels != nil {
6668
jobLabels.Merge(storage.Spec.InitJob.AdditionalLabels)
69+
jobLabels[labels.StorageGeneration] = strconv.FormatInt(storage.ObjectMeta.Generation, 10)
6770
}
6871
if storage.Spec.InitJob.AdditionalAnnotations != nil {
6972
jobAnnotations = CopyDict(storage.Spec.InitJob.AdditionalAnnotations)
73+
jobAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(storage.Spec.Configuration)
7074
}
7175
}
7276

@@ -232,7 +236,8 @@ func (b *StorageInitJobBuilder) buildJobVolumeMounts() []corev1.VolumeMount {
232236
{
233237
Name: configVolumeName,
234238
ReadOnly: true,
235-
MountPath: api.ConfigDir,
239+
MountPath: fmt.Sprintf("%s/%s", api.ConfigDir, api.ConfigFileName),
240+
SubPath: api.ConfigFileName,
236241
},
237242
}
238243

internal/resources/storage_statefulset.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"sigs.k8s.io/controller-runtime/pkg/client"
1616

1717
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
18+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
19+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
1820
"github.com/ydb-platform/ydb-kubernetes-operator/internal/ptr"
1921
)
2022

@@ -102,10 +104,17 @@ func (b *StorageStatefulSetBuilder) buildPodTemplateSpec() corev1.PodTemplateSpe
102104
dnsConfigSearches := []string{
103105
fmt.Sprintf(api.InterconnectServiceFQDNFormat, b.Storage.Name, b.GetNamespace()),
104106
}
107+
108+
podTemplateLabels := CopyDict(b.Labels)
109+
podTemplateLabels[labels.StorageGeneration] = strconv.FormatInt(b.ObjectMeta.Generation, 10)
110+
111+
podTemplateAnnotations := CopyDict(b.Spec.AdditionalAnnotations)
112+
podTemplateAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(b.Spec.Configuration)
113+
105114
podTemplate := corev1.PodTemplateSpec{
106115
ObjectMeta: metav1.ObjectMeta{
107-
Labels: b.Labels,
108-
Annotations: CopyDict(b.Spec.AdditionalAnnotations),
116+
Labels: podTemplateLabels,
117+
Annotations: podTemplateAnnotations,
109118
},
110119
Spec: corev1.PodSpec{
111120
Containers: []corev1.Container{b.buildContainer()},
@@ -389,7 +398,8 @@ func (b *StorageStatefulSetBuilder) buildVolumeMounts() []corev1.VolumeMount {
389398
{
390399
Name: configVolumeName,
391400
ReadOnly: true,
392-
MountPath: api.ConfigDir,
401+
MountPath: fmt.Sprintf("%s/%s", api.ConfigDir, api.ConfigFileName),
402+
SubPath: api.ConfigFileName,
393403
},
394404
}
395405

0 commit comments

Comments
 (0)