Skip to content

Commit 801c3d4

Browse files
committed
beautirfy node-host annotation
1 parent 1e6840b commit 801c3d4

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

api/v1alpha1/const.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ 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"
5352

5453
AnnotationValueTrue = "true"
5554

internal/annotations/annotations.go

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

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

59
const (
610
PrimaryResourceStorageAnnotation = "ydb.tech/primary-resource-storage"
@@ -53,3 +57,9 @@ func CompareLastAppliedAnnotation(map1, map2 map[string]string) bool {
5357
value2 := GetLastAppliedAnnotation(map2)
5458
return value1 == value2
5559
}
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
2323
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
2424
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
25-
"github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
2625
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
2726
)
2827

@@ -131,7 +130,7 @@ var _ = Describe("Storage controller medium tests", func() {
131130
Expect(foundStorageGenerationLabel).To(BeTrue())
132131

133132
foundConfigurationChecksumAnnotation := false
134-
if podAnnotations[annotations.ConfigurationChecksum] == resources.GetConfigurationChecksum(foundStorage.Spec.Configuration) {
133+
if podAnnotations[annotations.ConfigurationChecksum] == annotations.GetSHA256Checksum(foundStorage.Spec.Configuration) {
135134
foundConfigurationChecksumAnnotation = true
136135
}
137136
Expect(foundConfigurationChecksumAnnotation).To(BeTrue())

internal/resources/database_statefulset.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"regexp"
99
"strconv"
10+
"strings"
1011

1112
appsv1 "k8s.io/api/apps/v1"
1213
corev1 "k8s.io/api/core/v1"
@@ -603,16 +604,13 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
603604
}
604605

605606
if value, ok := b.ObjectMeta.Annotations[api.AnnotationNodeHost]; ok {
607+
nodeHost := value
608+
if !strings.HasPrefix(nodeHost, "$(NODE_NAME).") {
609+
nodeHost = fmt.Sprintf("%s.%s", "$(NODE_NAME)", nodeHost)
610+
}
606611
args = append(args,
607612
"--node-host",
608-
value,
609-
)
610-
}
611-
612-
if value, ok := b.ObjectMeta.Annotations[api.AnnotationNodeDomain]; ok {
613-
args = append(args,
614-
"--node-domain",
615-
value,
613+
nodeHost,
616614
)
617615
}
618616

internal/resources/resource.go

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

33
import (
44
"context"
5-
"crypto/sha256"
6-
"encoding/hex"
75
"errors"
86
"fmt"
97

@@ -341,7 +339,7 @@ func EqualRemoteResourceWithObject(
341339
func LastAppliedAnnotationPredicate() predicate.Predicate {
342340
return predicate.Funcs{
343341
UpdateFunc: func(e event.UpdateEvent) bool {
344-
return !ydbannotations.CompareYdbTechAnnotations(
342+
return !ydbannotations.CompareLastAppliedAnnotation(
345343
e.ObjectOld.GetAnnotations(),
346344
e.ObjectNew.GetAnnotations(),
347345
)
@@ -528,9 +526,3 @@ func buildCAStorePatchingCommandArgs(
528526

529527
return command, args
530528
}
531-
532-
func GetConfigurationChecksum(configuration string) string {
533-
hasher := sha256.New()
534-
hasher.Write([]byte(configuration))
535-
return hex.EncodeToString(hasher.Sum(nil))
536-
}

0 commit comments

Comments
 (0)