Skip to content

Commit

Permalink
allow to customize readiness probe path
Browse files Browse the repository at this point in the history
  • Loading branch information
kruftik committed Apr 22, 2024
1 parent 277e13c commit f5262ae
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 10 deletions.
13 changes: 13 additions & 0 deletions pkg/components/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ func NewHTTPProxy(
func() ([]byte, error) {
return cfgen.GetHTTPProxyConfig(spec)
},
WithComponentContainerPorts([]corev1.ContainerPort{
{
Name: "http-proxy-http",
ContainerPort: consts.HTTPProxyHTTPPort,
Protocol: corev1.ProtocolTCP,
},
{
Name: "http-proxy-https",
ContainerPort: consts.HTTPProxyHTTPSPort,
Protocol: corev1.ProtocolTCP,
},
}),
WithReadinessProbeHTTPPath("/ping"),
)

var httpsSecret *resources.TLSSecret
Expand Down
7 changes: 7 additions & 0 deletions pkg/components/rpcproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func NewRPCProxy(
func() ([]byte, error) {
return cfgen.GetRPCProxyConfig(spec)
},
WithComponentContainerPorts([]corev1.ContainerPort{
{
Name: "rpc-proxy",
ContainerPort: consts.RPCProxyRPCPort,
Protocol: corev1.ProtocolTCP,
},
}),
)

var balancingService *resources.RPCService = nil
Expand Down
35 changes: 25 additions & 10 deletions pkg/components/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type serverImpl struct {
configHelper *ConfigHelper

builtStatefulSet *appsv1.StatefulSet

readinessProbeHTTPPath string
componentContainerPorts []corev1.ContainerPort
}

func newServer(
Expand All @@ -63,6 +66,7 @@ func newServer(
instanceSpec *ytv1.InstanceSpec,
binaryPath, configFileName, statefulSetName, serviceName string,
generator ytconfig.YsonGeneratorFunc,
options ...Option,
) server {
proxy := ytsaurus.APIProxy()
commonSpec := ytsaurus.GetCommonSpec()
Expand All @@ -73,6 +77,7 @@ func newServer(
instanceSpec,
binaryPath, configFileName, statefulSetName, serviceName,
generator,
options...,
)
}

Expand All @@ -83,6 +88,7 @@ func newServerConfigured(
instanceSpec *ytv1.InstanceSpec,
binaryPath, configFileName, statefulSetName, serviceName string,
generator ytconfig.YsonGeneratorFunc,
options ...Option,
) server {
image := commonSpec.CoreImage
if instanceSpec.Image != nil {
Expand All @@ -107,7 +113,7 @@ func newServerConfigured(
consts.BusSecretMountPoint)
}

return &serverImpl{
srv := &serverImpl{
labeller: l,
image: image,
proxy: proxy,
Expand Down Expand Up @@ -143,7 +149,22 @@ func newServerConfigured(
Fmt: ytconfig.ConfigFormatYson,
},
}),

readinessProbeHTTPPath: readinessProbeHTTPPath,
componentContainerPorts: []corev1.ContainerPort{
{
Name: serverAPIPortName,
ContainerPort: *instanceSpec.MonitoringPort,
Protocol: corev1.ProtocolTCP,
},
},
}

for _, opt := range options {
opt.apply(srv)
}

return srv
}

func (s *serverImpl) Fetch(ctx context.Context) error {
Expand Down Expand Up @@ -272,19 +293,13 @@ func (s *serverImpl) rebuildStatefulSet() *appsv1.StatefulSet {
Name: consts.YTServerContainerName,
Command: command,
VolumeMounts: volumeMounts,
Ports: []corev1.ContainerPort{
{
Name: serverAPIPortName,
ContainerPort: *s.instanceSpec.MonitoringPort,
Protocol: corev1.ProtocolTCP,
},
},
Resources: s.instanceSpec.Resources,
Ports: s.componentContainerPorts,
Resources: s.instanceSpec.Resources,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromString(serverAPIPortName),
Path: readinessProbeHTTPPath,
Path: s.readinessProbeHTTPPath,
},
},
InitialDelaySeconds: readinessProbeParams.InitialDelaySeconds,
Expand Down
42 changes: 42 additions & 0 deletions pkg/components/serveroptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package components

import corev1 "k8s.io/api/core/v1"

type Option interface {
apply(srv *serverImpl)
}

var (
_ Option = &ReadinessProbeHTTPPath{}
_ Option = &ComponentContainerPorts{}
)

type ReadinessProbeHTTPPath struct {
path string
}

func (r ReadinessProbeHTTPPath) apply(srv *serverImpl) {
srv.readinessProbeHTTPPath = r.path
}

func WithReadinessProbeHTTPPath(path string) Option {
return ReadinessProbeHTTPPath{
path: path,
}
}

type ComponentContainerPorts struct {
ports []corev1.ContainerPort
}

func (c ComponentContainerPorts) apply(srv *serverImpl) {
for _, port := range c.ports {

Check failure on line 33 in pkg/components/serveroptions.go

View workflow job for this annotation

GitHub Actions / Run checks

S1011: should replace loop with `srv.componentContainerPorts = append(srv.componentContainerPorts, c.ports...)` (gosimple)
srv.componentContainerPorts = append(srv.componentContainerPorts, port)
}
}

func WithComponentContainerPorts(ports []corev1.ContainerPort) Option {
return ComponentContainerPorts{
ports: ports,
}
}

0 comments on commit f5262ae

Please sign in to comment.