Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions internal/resources/storage_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -101,6 +102,42 @@ func (b *StorageStatefulSetBuilder) Build(obj client.Object) error {
return nil
}

func (b *StorageStatefulSetBuilder) buildEnv() []corev1.EnvVar {
var envVars []corev1.EnvVar

envVars = append(envVars,
corev1.EnvVar{
Name: "POD_NAME", // for `--grpc-public-host` flag
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.name",
},
},
},
corev1.EnvVar{
Name: "NODE_NAME", // for `--grpc-public-host` flag
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.name",
},
},
},
corev1.EnvVar{
Name: "POD_IP", // for `--grpc-public-address-<ip-family>` flag
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "status.podIP",
},
},
},
)

return envVars
}

func (b *StorageStatefulSetBuilder) buildPodTemplateLabels() labels.Labels {
podTemplateLabels := labels.Labels{}

Expand Down Expand Up @@ -403,6 +440,7 @@ func (b *StorageStatefulSetBuilder) buildContainer() corev1.Container { // todo
ImagePullPolicy: imagePullPolicy,
Command: command,
Args: args,
Env: b.buildEnv(),

SecurityContext: mergeSecurityContextWithDefaults(b.Spec.SecurityContext),

Expand Down Expand Up @@ -570,6 +608,37 @@ func (b *StorageStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
}
}

var publicHost string
if b.Spec.Service.GRPC.ExternalHost != "" {
publicHost = fmt.Sprintf("%s.%s", "$(POD_NAME)", b.Spec.Service.GRPC.ExternalHost)
}
if value, ok := b.ObjectMeta.Annotations[api.AnnotationGRPCPublicHost]; ok {
publicHost = value
}
if publicHost != "" {
if !(strings.HasPrefix(publicHost, "$(POD_NAME)") || strings.HasPrefix(publicHost, "$(NODE_NAME)")) {
publicHost = fmt.Sprintf("%s.%s", "$(POD_NAME)", publicHost)
}
args = append(args,
"--grpc-public-host",
publicHost,
)
}

var publicPort string
if b.Spec.Service.GRPC.ExternalPort > 0 {
publicPort = fmt.Sprintf("%d", b.Spec.Service.GRPC.ExternalPort)
}
if value, ok := b.ObjectMeta.Annotations[api.AnnotationGRPCPublicPort]; ok {
publicPort = value
}
if publicPort != "" {
args = append(args,
"--grpc-public-port",
publicPort,
)
}

return command, args
}

Expand Down
Loading