Skip to content

Commit b2cf7fd

Browse files
committed
externalPort override publicHost with
1 parent 2d44149 commit b2cf7fd

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

internal/resources/database.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
corev1 "k8s.io/api/core/v1"
7-
"k8s.io/apimachinery/pkg/util/intstr"
87
"k8s.io/client-go/rest"
98

109
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
@@ -153,10 +152,9 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
153152
SelectorLabels: databaseLabels,
154153
Annotations: b.Spec.Service.GRPC.AdditionalAnnotations,
155154
Ports: []corev1.ServicePort{{
156-
Name: api.GRPCServicePortName,
157-
Port: api.GRPCPort,
158-
TargetPort: intstr.IntOrString{Type: intstr.String, StrVal: "grpc"},
159-
NodePort: b.Spec.Service.GRPC.ExternalPort,
155+
Name: api.GRPCServicePortName,
156+
Port: api.GRPCPort,
157+
NodePort: b.Spec.Service.GRPC.ExternalPort,
160158
}},
161159
IPFamilies: b.Spec.Service.GRPC.IPFamilies,
162160
IPFamilyPolicy: b.Spec.Service.GRPC.IPFamilyPolicy,

internal/resources/database_statefulset.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,8 @@ func (b *DatabaseStatefulSetBuilder) buildContainer() corev1.Container {
437437
}
438438
}
439439

440-
var grpcPublicPort int32
441-
if b.Spec.Service.GRPC.ExternalPort != 0 {
442-
grpcPublicPort = b.Spec.Service.GRPC.ExternalPort
443-
} else {
444-
grpcPublicPort = api.GRPCPort
445-
}
446-
447440
ports := []corev1.ContainerPort{{
448-
Name: "grpc", ContainerPort: grpcPublicPort,
441+
Name: "grpc", ContainerPort: api.GRPCPort,
449442
}, {
450443
Name: "interconnect", ContainerPort: api.InterconnectPort,
451444
}, {
@@ -655,12 +648,10 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
655648
publicHostOption := "--grpc-public-host"
656649
publicHostDomain := fmt.Sprintf(api.InterconnectServiceFQDNFormat, b.Database.Name, b.GetNamespace(), domain)
657650
publicHost := fmt.Sprintf("%s.%s", "$(POD_NAME)", publicHostDomain)
651+
658652
if b.Spec.Service.GRPC.ExternalHost != "" {
659653
publicHost = fmt.Sprintf("%s.%s", "$(POD_NAME)", b.Spec.Service.GRPC.ExternalHost)
660654
}
661-
if b.Spec.Service.GRPC.ExternalPort > 0 {
662-
publicHost = "$(NODE_NAME)"
663-
}
664655
if value, ok := b.ObjectMeta.Annotations[api.AnnotationGRPCPublicHost]; ok {
665656
publicHost = value
666657
}
@@ -690,10 +681,12 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
690681

691682
publicPortOption := "--grpc-public-port"
692683
publicPort := fmt.Sprintf("%d", api.GRPCPort)
693-
if b.Spec.Service.GRPC.ExternalPort != 0 {
684+
if b.Spec.Service.GRPC.ExternalPort > 0 {
685+
publicHost = "$(NODE_NAME)"
694686
publicPort = fmt.Sprintf("%d", b.Spec.Service.GRPC.ExternalPort)
695687
}
696688
if value, ok := b.ObjectMeta.Annotations[api.AnnotationGRPCPublicPort]; ok {
689+
publicHost = "$(NODE_NAME)"
697690
publicPort = value
698691
}
699692

internal/resources/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (b *ServiceBuilder) Build(obj client.Object) error {
6363
}
6464

6565
for _, port := range service.Spec.Ports {
66-
if port.NodePort != 0 {
66+
if port.NodePort > 0 {
6767
service.Spec.Type = corev1.ServiceTypeNodePort
6868
}
6969
}

0 commit comments

Comments
 (0)