66 "fmt"
77 "log"
88 "regexp"
9+ "strings"
910
1011 appsv1 "k8s.io/api/apps/v1"
1112 corev1 "k8s.io/api/core/v1"
@@ -76,14 +77,23 @@ func (b *DatabaseStatefulSetBuilder) buildEnv() []corev1.EnvVar {
7677
7778 envVars = append (envVars ,
7879 corev1.EnvVar {
79- Name : "NODE_NAME " , // for `--grpc-public-host` flag
80+ Name : "POD_NAME " , // for `--grpc-public-host` flag
8081 ValueFrom : & corev1.EnvVarSource {
8182 FieldRef : & corev1.ObjectFieldSelector {
8283 APIVersion : "v1" ,
8384 FieldPath : "metadata.name" ,
8485 },
8586 },
8687 },
88+ corev1.EnvVar {
89+ Name : "NODE_NAME" , // for `--grpc-public-port` flag
90+ ValueFrom : & corev1.EnvVarSource {
91+ FieldRef : & corev1.ObjectFieldSelector {
92+ APIVersion : "v1" ,
93+ FieldPath : "spec.nodeName" ,
94+ },
95+ },
96+ },
8797 corev1.EnvVar {
8898 Name : "POD_IP" , // for `--grpc-public-address-<ip-family>` flag
8999 ValueFrom : & corev1.EnvVarSource {
@@ -643,10 +653,13 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
643653 }
644654
645655 publicHostOption := "--grpc-public-host"
646- publicHost := fmt .Sprintf (api .InterconnectServiceFQDNFormat , b .Database .Name , b .GetNamespace (), domain ) // FIXME .svc.cluster.local
647-
656+ publicHostDomain := fmt .Sprintf (api .InterconnectServiceFQDNFormat , b .Database .Name , b .GetNamespace (), domain )
657+ publicHost := fmt . Sprintf ( "%s.%s" , "$(POD_NAME)" , publicHostDomain )
648658 if b .Spec .Service .GRPC .ExternalHost != "" {
649- publicHost = b .Spec .Service .GRPC .ExternalHost
659+ publicHost = fmt .Sprintf ("%s.%s" , "$(POD_NAME)" , b .Spec .Service .GRPC .ExternalHost )
660+ }
661+ if b .Spec .Service .GRPC .ExternalPort > 0 {
662+ publicHost = "$(NODE_NAME)"
650663 }
651664 if value , ok := b .ObjectMeta .Annotations [api .AnnotationGRPCPublicHost ]; ok {
652665 publicHost = value
@@ -670,7 +683,7 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
670683 args = append (
671684 args ,
672685 "--grpc-public-target-name-override" ,
673- fmt .Sprintf ("%s.%s" , "$(NODE_NAME )" , targetNameOverride ),
686+ fmt .Sprintf ("%s.%s" , "$(POD_NAME )" , targetNameOverride ),
674687 )
675688 }
676689 }
@@ -688,7 +701,7 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
688701 args ,
689702
690703 publicHostOption ,
691- fmt . Sprintf ( "%s.%s" , "$(NODE_NAME)" , publicHost ), // fixme $(NODE_NAME)
704+ publicHost ,
692705
693706 publicPortOption ,
694707 publicPort ,
@@ -704,6 +717,9 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
704717 }
705718
706719 if value , ok := b .ObjectMeta .Annotations [api .AnnotationNodeHost ]; ok {
720+ if ! strings .HasPrefix (value , "$(POD_NAME)." ) {
721+ value = fmt .Sprintf ("%s.%s" , "$(POD_NAME)" , value )
722+ }
707723 args = append (args ,
708724 "--node-host" ,
709725 value ,
0 commit comments