Skip to content

Commit a313d8c

Browse files
committed
fixes
1 parent 8ea8c56 commit a313d8c

File tree

12 files changed

+103
-89
lines changed

12 files changed

+103
-89
lines changed

api/v1alpha1/const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
AnnotationDataCenter = "ydb.tech/data-center"
5050
AnnotationGRPCPublicHost = "ydb.tech/grpc-public-host"
5151
AnnotationNodeHost = "ydb.tech/node-host"
52+
AnnotationNodeDomain = "ydb.tech/node-domain"
5253

5354
AnnotationValueTrue = "true"
5455

api/v1alpha1/database_webhook.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
logf "sigs.k8s.io/controller-runtime/pkg/log"
1515
"sigs.k8s.io/controller-runtime/pkg/webhook"
1616

17-
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
1817
. "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants" //nolint:revive,stylecheck
1918
)
2019

@@ -158,11 +157,6 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
158157
database.Spec.Configuration = string(configuration)
159158
}
160159

161-
if database.Spec.AdditionalAnnotations == nil {
162-
database.Spec.AdditionalAnnotations = make(map[string]string)
163-
}
164-
database.Spec.AdditionalAnnotations[annotations.ConfigurationChecksum] = annotations.GetSHA256Checksum(database.Spec.Configuration)
165-
166160
return nil
167161
}
168162

api/v1alpha1/storage_webhook.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
logf "sigs.k8s.io/controller-runtime/pkg/log"
1717
"sigs.k8s.io/controller-runtime/pkg/webhook"
1818

19-
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
2019
"github.com/ydb-platform/ydb-kubernetes-operator/internal/configuration/schema"
2120
. "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants" //nolint:revive,stylecheck
2221
)
@@ -169,11 +168,6 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
169168
}
170169
storage.Spec.Configuration = string(configuration)
171170

172-
if storage.Spec.AdditionalAnnotations == nil {
173-
storage.Spec.AdditionalAnnotations = make(map[string]string)
174-
}
175-
storage.Spec.AdditionalAnnotations[annotations.ConfigurationChecksum] = annotations.GetSHA256Checksum(storage.Spec.Configuration)
176-
177171
return nil
178172
}
179173

internal/annotations/annotations.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package annotations
22

3-
import (
4-
"crypto/sha256"
5-
"encoding/hex"
6-
"strings"
7-
)
3+
import "strings"
84

95
const (
106
PrimaryResourceStorageAnnotation = "ydb.tech/primary-resource-storage"
@@ -57,9 +53,3 @@ func CompareLastAppliedAnnotation(map1, map2 map[string]string) bool {
5753
value2 := GetLastAppliedAnnotation(map2)
5854
return value1 == value2
5955
}
60-
61-
func GetSHA256Checksum(text string) string {
62-
hasher := sha256.New()
63-
hasher.Write([]byte(text))
64-
return hex.EncodeToString(hasher.Sum(nil))
65-
}

internal/controllers/storage/controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import (
1212
appsv1 "k8s.io/api/apps/v1"
1313
corev1 "k8s.io/api/core/v1"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"k8s.io/apimachinery/pkg/types"
1516
"sigs.k8s.io/controller-runtime/pkg/client"
1617
"sigs.k8s.io/controller-runtime/pkg/manager"
1718

1819
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
1920
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
21+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
2022
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
23+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
2124
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
2225
)
2326

@@ -53,6 +56,10 @@ var _ = Describe("Storage controller medium tests", func() {
5356
Expect(k8sClient.Create(ctx, &namespace)).Should(Succeed())
5457
})
5558

59+
AfterEach(func() {
60+
Expect(k8sClient.Delete(ctx, &namespace)).Should(Succeed())
61+
})
62+
5663
It("Checking field propagation to objects", func() {
5764
storageSample := testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-block-4-2-config.yaml"))
5865

@@ -105,6 +112,22 @@ var _ = Describe("Storage controller medium tests", func() {
105112
}
106113
Expect(foundVolume).To(BeTrue())
107114

115+
By("Check that annotation propagated to pods...", func() {
116+
podAnnotations := storageSS.Spec.Template.Annotations
117+
118+
foundStorage := v1alpha1.Storage{}
119+
Expect(k8sClient.Get(ctx, types.NamespacedName{
120+
Name: testobjects.StorageName,
121+
Namespace: testobjects.YdbNamespace,
122+
}, &foundStorage)).Should(Succeed())
123+
124+
foundConfigurationChecksumAnnotation := false
125+
if podAnnotations[annotations.ConfigurationChecksum] == resources.GetSHA256Checksum(foundStorage.Spec.Configuration) {
126+
foundConfigurationChecksumAnnotation = true
127+
}
128+
Expect(foundConfigurationChecksumAnnotation).To(BeTrue())
129+
})
130+
108131
By("Check that args with --label propagated to pods...", func() {
109132
podContainerArgs := storageSS.Spec.Template.Spec.Containers[0].Args
110133
var labelArgKey string

internal/resources/database.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,34 @@ func (b *DatabaseBuilder) Unwrap() *api.Database {
3131
return b.DeepCopy()
3232
}
3333

34-
func DatabaseLabels(database *api.Database) labels.Labels {
35-
l := labels.Common(database.Name, database.Labels)
34+
func (b *DatabaseBuilder) NewLabels() labels.Labels {
35+
l := labels.Common(b.Name, b.Labels)
3636

37-
l.Merge(database.Spec.AdditionalLabels)
38-
l.Merge(map[string]string{
39-
labels.ComponentKey: labels.DynamicComponent,
40-
})
37+
l.Merge(b.Spec.AdditionalLabels)
38+
l.Merge(map[string]string{labels.ComponentKey: labels.DynamicComponent})
4139

4240
return l
4341
}
4442

43+
func (b *DatabaseBuilder) NewAnnotations() map[string]string {
44+
an := annotations.GetYdbTechAnnotations(b.Annotations)
45+
an[annotations.ConfigurationChecksum] = GetSHA256Checksum(b.Spec.Configuration)
46+
delete(an, annotations.LastAppliedAnnotation)
47+
48+
for k, v := range b.Spec.AdditionalAnnotations {
49+
an[k] = v
50+
}
51+
52+
return an
53+
}
54+
4555
func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []ResourceBuilder {
4656
if b.Spec.ServerlessResources != nil {
4757
return []ResourceBuilder{}
4858
}
4959

50-
databaseLabels := DatabaseLabels(b.Unwrap())
51-
databaseAnnotations := annotations.GetYdbTechAnnotations(b.Annotations)
52-
delete(databaseAnnotations, annotations.LastAppliedAnnotation)
60+
databaseLabels := b.NewLabels()
61+
databaseAnnotations := b.NewAnnotations()
5362

5463
grpcServiceLabels := databaseLabels.Copy()
5564
grpcServiceLabels.Merge(b.Spec.Service.GRPC.AdditionalLabels)
@@ -67,11 +76,6 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
6776
datastreamsServiceLabels.Merge(b.Spec.Service.Datastreams.AdditionalLabels)
6877
datastreamsServiceLabels.Merge(map[string]string{labels.ServiceComponent: labels.DatastreamsComponent})
6978

70-
statefulSetAnnotations := CopyDict(databaseAnnotations)
71-
for k, v := range b.Spec.AdditionalAnnotations {
72-
statefulSetAnnotations[k] = v
73-
}
74-
7579
var optionalBuilders []ResourceBuilder
7680

7781
if b.Spec.Configuration != "" {
@@ -197,7 +201,7 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
197201

198202
Name: b.Name,
199203
Labels: databaseLabels,
200-
Annotations: statefulSetAnnotations,
204+
Annotations: databaseAnnotations,
201205
},
202206
)
203207
} else {
@@ -221,6 +225,8 @@ func (b *DatabaseBuilder) getNodeSetBuilders(
221225

222226
nodeSetLabels := databaseLabels.Copy()
223227
nodeSetLabels.Merge(nodeSetSpecInline.Labels)
228+
229+
nodeSetLabels[labels.DatabaseNodeSetComponent] = nodeSetSpecInline.Name
224230
if nodeSetSpecInline.Remote != nil {
225231
nodeSetLabels[labels.RemoteClusterKey] = nodeSetSpecInline.Remote.Cluster
226232
}
@@ -230,7 +236,7 @@ func (b *DatabaseBuilder) getNodeSetBuilders(
230236
nodeSetAnnotations[k] = v
231237
}
232238

233-
databaseNodeSetSpec := b.recastDatabaseNodeSetSpecInline(nodeSetSpecInline.DeepCopy())
239+
nodeSetSpec := b.recastDatabaseNodeSetSpecInline(nodeSetSpecInline.DeepCopy())
234240

235241
if nodeSetSpecInline.Remote != nil {
236242
nodeSetBuilders = append(
@@ -242,7 +248,7 @@ func (b *DatabaseBuilder) getNodeSetBuilders(
242248
Labels: nodeSetLabels,
243249
Annotations: nodeSetAnnotations,
244250

245-
DatabaseNodeSetSpec: databaseNodeSetSpec,
251+
DatabaseNodeSetSpec: nodeSetSpec,
246252
},
247253
)
248254
} else {
@@ -255,7 +261,7 @@ func (b *DatabaseBuilder) getNodeSetBuilders(
255261
Labels: nodeSetLabels,
256262
Annotations: nodeSetAnnotations,
257263

258-
DatabaseNodeSetSpec: databaseNodeSetSpec,
264+
DatabaseNodeSetSpec: nodeSetSpec,
259265
},
260266
)
261267
}
@@ -297,15 +303,14 @@ func (b *DatabaseBuilder) recastDatabaseNodeSetSpecInline(nodeSetSpecInline *api
297303
}
298304

299305
if nodeSetSpecInline.TopologySpreadConstraints != nil {
300-
nodeSetSpec.TopologySpreadConstraints = append([]corev1.TopologySpreadConstraint{}, nodeSetSpecInline.TopologySpreadConstraints...)
306+
nodeSetSpec.TopologySpreadConstraints = nodeSetSpecInline.TopologySpreadConstraints
301307
}
302308

303309
if nodeSetSpecInline.Tolerations != nil {
304310
nodeSetSpec.Tolerations = append(nodeSetSpec.Tolerations, nodeSetSpecInline.Tolerations...)
305311
}
306312

307313
nodeSetSpec.AdditionalLabels = CopyDict(b.Spec.AdditionalLabels)
308-
nodeSetSpec.AdditionalLabels[labels.DatabaseNodeSetComponent] = nodeSetSpecInline.Name
309314
if nodeSetSpecInline.AdditionalLabels != nil {
310315
for k, v := range nodeSetSpecInline.AdditionalLabels {
311316
nodeSetSpec.AdditionalLabels[k] = v

internal/resources/database_statefulset.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,19 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
645645
}
646646

647647
if value, ok := b.ObjectMeta.Annotations[api.AnnotationNodeHost]; ok {
648-
nodeHost := value
649-
if !strings.HasPrefix(nodeHost, "$(NODE_NAME).") {
650-
nodeHost = fmt.Sprintf("%s.%s", "$(NODE_NAME)", nodeHost)
648+
if !strings.HasPrefix(value, "$(NODE_NAME).") {
649+
value = fmt.Sprintf("%s.%s", "$(NODE_NAME)", value)
651650
}
652651
args = append(args,
653652
"--node-host",
654-
nodeHost,
653+
value,
654+
)
655+
}
656+
657+
if value, ok := b.ObjectMeta.Annotations[api.AnnotationNodeDomain]; ok {
658+
args = append(args,
659+
"--node-domain",
660+
value,
655661
)
656662
}
657663

internal/resources/databasenodeset.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"sigs.k8s.io/controller-runtime/pkg/client"
99

1010
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
11-
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
1211
)
1312

1413
type DatabaseNodeSetBuilder struct {
@@ -56,24 +55,20 @@ func (b *DatabaseNodeSetBuilder) Placeholder(cr client.Object) client.Object {
5655
func (b *DatabaseNodeSetResource) GetResourceBuilders(restConfig *rest.Config) []ResourceBuilder {
5756
var resourceBuilders []ResourceBuilder
5857

59-
database := api.RecastDatabaseNodeSet(b.DatabaseNodeSet)
60-
databaseLabels := DatabaseLabels(database)
58+
ydbCr := api.RecastDatabaseNodeSet(b.DatabaseNodeSet)
6159

62-
databaseAnnotations := annotations.GetYdbTechAnnotations(b.Annotations)
63-
delete(databaseAnnotations, annotations.LastAppliedAnnotation)
64-
statefulSetAnnotations := CopyDict(databaseAnnotations)
65-
for k, v := range b.Spec.AdditionalAnnotations {
66-
statefulSetAnnotations[k] = v
67-
}
60+
database := NewDatabase(ydbCr)
61+
databaseLabels := database.NewLabels()
62+
databaseAnnotations := database.NewAnnotations()
6863

6964
resourceBuilders = append(resourceBuilders,
7065
&DatabaseStatefulSetBuilder{
71-
Database: database,
66+
Database: ydbCr,
7267
RestConfig: restConfig,
7368

7469
Name: b.Name,
7570
Labels: databaseLabels,
76-
Annotations: statefulSetAnnotations,
71+
Annotations: databaseAnnotations,
7772
},
7873
)
7974
return resourceBuilders

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

@@ -610,6 +612,12 @@ func buildCAStorePatchingCommandArgs(
610612
return command, args
611613
}
612614

615+
func GetSHA256Checksum(text string) string {
616+
hasher := sha256.New()
617+
hasher.Write([]byte(text))
618+
return hex.EncodeToString(hasher.Sum(nil))
619+
}
620+
613621
func isSignAlgorithmSupported(alg string) bool {
614622
supportedAlgs := jwt.GetAlgorithms()
615623

0 commit comments

Comments
 (0)