Skip to content

Commit

Permalink
Merge pull request kubernetes#108803 from SergeyKanzhelev/httpProbeMi…
Browse files Browse the repository at this point in the history
…norCleanup

remove TODOs from http package and prober
  • Loading branch information
k8s-ci-robot authored Jun 1, 2022
2 parents 875d48b + 1df526b commit 737f706
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
38 changes: 12 additions & 26 deletions pkg/kubelet/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ const maxProbeRetries = 3

// Prober helps to check the liveness/readiness/startup of a container.
type prober struct {
exec execprobe.Prober
// probe types needs different httpprobe instances so they don't
// share a connection pool which can cause collisions to the
// same host:port and transient failures. See #49740.
readinessHTTP httpprobe.Prober
livenessHTTP httpprobe.Prober
startupHTTP httpprobe.Prober
tcp tcpprobe.Prober
grpc grpcprobe.Prober
runner kubecontainer.CommandRunner
exec execprobe.Prober
http httpprobe.Prober
tcp tcpprobe.Prober
grpc grpcprobe.Prober
runner kubecontainer.CommandRunner

recorder record.EventRecorder
}
Expand All @@ -71,14 +66,12 @@ func newProber(

const followNonLocalRedirects = false
return &prober{
exec: execprobe.New(),
readinessHTTP: httpprobe.New(followNonLocalRedirects),
livenessHTTP: httpprobe.New(followNonLocalRedirects),
startupHTTP: httpprobe.New(followNonLocalRedirects),
tcp: tcpprobe.New(),
grpc: grpcprobe.New(),
runner: runner,
recorder: recorder,
exec: execprobe.New(),
http: httpprobe.New(followNonLocalRedirects),
tcp: tcpprobe.New(),
grpc: grpcprobe.New(),
runner: runner,
recorder: recorder,
}
}

Expand Down Expand Up @@ -179,14 +172,7 @@ func (pb *prober) runProbe(probeType probeType, p *v1.Probe, pod *v1.Pod, status
url := formatURL(scheme, host, port, path)
headers := buildHeader(p.HTTPGet.HTTPHeaders)
klog.V(4).InfoS("HTTP-Probe Headers", "headers", headers)
switch probeType {
case liveness:
return pb.livenessHTTP.Probe(url, headers, timeout)
case startup:
return pb.startupHTTP.Probe(url, headers, timeout)
default:
return pb.readinessHTTP.Probe(url, headers, timeout)
}
return pb.http.Probe(url, headers, timeout)
}
if p.TCPSocket != nil {
port, err := extractPort(p.TCPSocket.Port, container)
Expand Down
1 change: 0 additions & 1 deletion pkg/kubelet/prober/prober_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var ProberResults = metrics.NewCounterVec(
// probe (AddPod). The worker periodically probes its assigned container and caches the results. The
// manager use the cached probe results to set the appropriate Ready state in the PodStatus when
// requested (UpdatePodStatus). Updating probe parameters is not currently supported.
// TODO: Move liveness probing out of the runtime, to here.
type Manager interface {
// AddPod creates new probe workers for every container probe. This should be called for every
// pod created.
Expand Down
4 changes: 1 addition & 3 deletions pkg/kubelet/prober/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ func (w *worker) doProbe() (keepGoing bool) {
}
}

// TODO: in order for exec probes to correctly handle downward API env, we must be able to reconstruct
// the full container environment here, OR we must make a call to the CRI in order to get those environment
// values from the running container.
// Note, exec probe does NOT have access to pod environment variables or downward API
result, err := w.probeManager.prober.probe(w.probeType, w.pod, status, w.container, w.containerID)
if err != nil {
// Prober error, throw away the result.
Expand Down
10 changes: 5 additions & 5 deletions pkg/probe/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ func NewWithTLSConfig(config *tls.Config, followNonLocalRedirects bool) Prober {
// We do not want the probe use node's local proxy set.
transport := utilnet.SetTransportDefaults(
&http.Transport{
TLSClientConfig: config,
DisableKeepAlives: true,
Proxy: http.ProxyURL(nil),
TLSClientConfig: config,
DisableKeepAlives: true,
Proxy: http.ProxyURL(nil),
DisableCompression: true, // removes Accept-Encoding header
})
return httpProber{transport, followNonLocalRedirects}
}
Expand All @@ -68,9 +69,8 @@ type httpProber struct {
followNonLocalRedirects bool
}

// Probe returns a ProbeRunner capable of running an HTTP check.
// Probe returns a probing result. The only case the err will not be nil is when there is a problem reading the response body.
func (pr httpProber) Probe(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, error) {
pr.transport.DisableCompression = true // removes Accept-Encoding header
client := &http.Client{
Timeout: timeout,
Transport: pr.transport,
Expand Down

0 comments on commit 737f706

Please sign in to comment.