Skip to content

Commit

Permalink
Fix TCP probes when the optional host field is not given
Browse files Browse the repository at this point in the history
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
  • Loading branch information
hedayat authored and ashley-cui committed Jul 20, 2023
1 parent 6817e0a commit 48deafc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/specgen/generate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ func probeToHealthConfig(probe *v1.Probe, containerPorts []v1.ContainerPort) (*m
var commandString string
failureCmd := "exit 1"
probeHandler := probe.Handler
host := "localhost" // Kubernetes default is host IP, but with Podman currently we run inside the container

// configure healthcheck on the basis of Handler Actions.
switch {
Expand All @@ -585,7 +586,6 @@ func probeToHealthConfig(probe *v1.Probe, containerPorts []v1.ContainerPort) (*m
if probeHandler.HTTPGet.Scheme != "" {
uriScheme = probeHandler.HTTPGet.Scheme
}
host := "localhost" // Kubernetes default is host IP, but with Podman there is only one node
if probeHandler.HTTPGet.Host != "" {
host = probeHandler.HTTPGet.Host
}
Expand All @@ -603,7 +603,10 @@ func probeToHealthConfig(probe *v1.Probe, containerPorts []v1.ContainerPort) (*m
if err != nil {
return nil, err
}
commandString = fmt.Sprintf("nc -z -v %s %d || %s", probeHandler.TCPSocket.Host, portNum, failureCmd)
if probeHandler.TCPSocket.Host != "" {
host = probeHandler.TCPSocket.Host
}
commandString = fmt.Sprintf("nc -z -v %s %d || %s", host, portNum, failureCmd)
}
return makeHealthCheck(commandString, probe.PeriodSeconds, probe.FailureThreshold, probe.TimeoutSeconds, probe.InitialDelaySeconds)
}
Expand Down

0 comments on commit 48deafc

Please sign in to comment.