mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Merge pull request #123336 from HyunSu1768/hyunsu1768/use-switch-cases
Refactoring to encourage use of switch case
This commit is contained in:
commit
229ebabc0a
@ -135,12 +135,13 @@ func (pb *prober) runProbeWithRetries(ctx context.Context, probeType probeType,
|
||||
|
||||
func (pb *prober) runProbe(ctx context.Context, probeType probeType, p *v1.Probe, pod *v1.Pod, status v1.PodStatus, container v1.Container, containerID kubecontainer.ContainerID) (probe.Result, string, error) {
|
||||
timeout := time.Duration(p.TimeoutSeconds) * time.Second
|
||||
if p.Exec != nil {
|
||||
switch {
|
||||
case p.Exec != nil:
|
||||
klog.V(4).InfoS("Exec-Probe runProbe", "pod", klog.KObj(pod), "containerName", container.Name, "execCommand", p.Exec.Command)
|
||||
command := kubecontainer.ExpandContainerCommandOnlyStatic(p.Exec.Command, container.Env)
|
||||
return pb.exec.Probe(pb.newExecInContainer(ctx, container, containerID, command, timeout))
|
||||
}
|
||||
if p.HTTPGet != nil {
|
||||
|
||||
case p.HTTPGet != nil:
|
||||
req, err := httpprobe.NewRequestForHTTPGetAction(p.HTTPGet, &container, status.PodIP, "probe")
|
||||
if err != nil {
|
||||
return probe.Unknown, "", err
|
||||
@ -154,8 +155,8 @@ func (pb *prober) runProbe(ctx context.Context, probeType probeType, p *v1.Probe
|
||||
klogV4.InfoS("HTTP-Probe", "scheme", scheme, "host", host, "port", port, "path", path, "timeout", timeout, "headers", headers)
|
||||
}
|
||||
return pb.http.Probe(req, timeout)
|
||||
}
|
||||
if p.TCPSocket != nil {
|
||||
|
||||
case p.TCPSocket != nil:
|
||||
port, err := probe.ResolveContainerPort(p.TCPSocket.Port, &container)
|
||||
if err != nil {
|
||||
return probe.Unknown, "", err
|
||||
@ -166,9 +167,8 @@ func (pb *prober) runProbe(ctx context.Context, probeType probeType, p *v1.Probe
|
||||
}
|
||||
klog.V(4).InfoS("TCP-Probe", "host", host, "port", port, "timeout", timeout)
|
||||
return pb.tcp.Probe(host, port, timeout)
|
||||
}
|
||||
|
||||
if p.GRPC != nil {
|
||||
case p.GRPC != nil:
|
||||
host := status.PodIP
|
||||
service := ""
|
||||
if p.GRPC.Service != nil {
|
||||
@ -176,10 +176,11 @@ func (pb *prober) runProbe(ctx context.Context, probeType probeType, p *v1.Probe
|
||||
}
|
||||
klog.V(4).InfoS("GRPC-Probe", "host", host, "service", service, "port", p.GRPC.Port, "timeout", timeout)
|
||||
return pb.grpc.Probe(host, service, int(p.GRPC.Port), timeout)
|
||||
}
|
||||
|
||||
klog.InfoS("Failed to find probe builder for container", "containerName", container.Name)
|
||||
return probe.Unknown, "", fmt.Errorf("missing probe handler for %s:%s", format.Pod(pod), container.Name)
|
||||
default:
|
||||
klog.InfoS("Failed to find probe builder for container", "containerName", container.Name)
|
||||
return probe.Unknown, "", fmt.Errorf("missing probe handler for %s:%s", format.Pod(pod), container.Name)
|
||||
}
|
||||
}
|
||||
|
||||
type execInContainer struct {
|
||||
|
Loading…
Reference in New Issue
Block a user