mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +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) {
|
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
|
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)
|
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)
|
command := kubecontainer.ExpandContainerCommandOnlyStatic(p.Exec.Command, container.Env)
|
||||||
return pb.exec.Probe(pb.newExecInContainer(ctx, container, containerID, command, timeout))
|
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")
|
req, err := httpprobe.NewRequestForHTTPGetAction(p.HTTPGet, &container, status.PodIP, "probe")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return probe.Unknown, "", err
|
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)
|
klogV4.InfoS("HTTP-Probe", "scheme", scheme, "host", host, "port", port, "path", path, "timeout", timeout, "headers", headers)
|
||||||
}
|
}
|
||||||
return pb.http.Probe(req, timeout)
|
return pb.http.Probe(req, timeout)
|
||||||
}
|
|
||||||
if p.TCPSocket != nil {
|
case p.TCPSocket != nil:
|
||||||
port, err := probe.ResolveContainerPort(p.TCPSocket.Port, &container)
|
port, err := probe.ResolveContainerPort(p.TCPSocket.Port, &container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return probe.Unknown, "", err
|
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)
|
klog.V(4).InfoS("TCP-Probe", "host", host, "port", port, "timeout", timeout)
|
||||||
return pb.tcp.Probe(host, port, timeout)
|
return pb.tcp.Probe(host, port, timeout)
|
||||||
}
|
|
||||||
|
|
||||||
if p.GRPC != nil {
|
case p.GRPC != nil:
|
||||||
host := status.PodIP
|
host := status.PodIP
|
||||||
service := ""
|
service := ""
|
||||||
if p.GRPC.Service != nil {
|
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)
|
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)
|
return pb.grpc.Probe(host, service, int(p.GRPC.Port), timeout)
|
||||||
}
|
|
||||||
|
|
||||||
klog.InfoS("Failed to find probe builder for container", "containerName", container.Name)
|
default:
|
||||||
return probe.Unknown, "", fmt.Errorf("missing probe handler for %s:%s", format.Pod(pod), container.Name)
|
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 {
|
type execInContainer struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user