-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for PodProbeMarker http/tcp capacities #1321
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/apimachinery/pkg/watch" | ||
v1core "k8s.io/client-go/kubernetes/typed/core/v1" | ||
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/client-go/tools/record" | ||
"k8s.io/client-go/util/workqueue" | ||
|
@@ -88,6 +89,8 @@ | |
nodeName string | ||
// kruise daemon start time | ||
start time.Time | ||
// runtime client | ||
runtimeClient runtimeclient.Client | ||
} | ||
|
||
// NewController returns the controller for pod probe | ||
|
@@ -126,6 +129,7 @@ | |
nodeName: nodeName, | ||
eventRecorder: recorder, | ||
start: time.Now(), | ||
runtimeClient: opts.RuntimeClient, | ||
} | ||
c.prober = newProber(c.runtimeFactory.GetRuntimeService()) | ||
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
|
@@ -407,6 +411,25 @@ | |
return containerStatus, err | ||
} | ||
|
||
func (c *Controller) fetchPodIp(podUID, name, namespace string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our internal cluster is quite large and there are performance issues if Daemon needs to watch Pod resources, so it is recommended that Pod IP can be passed down directly from the NodePodProbeSpec resource. |
||
|
||
podList := &corev1.PodList{} | ||
err := c.runtimeClient.List(context.TODO(), podList, runtimeclient.MatchingFields{"metadata.name": name, "metadata.namespace": namespace}) | ||
|
||
if err != nil { | ||
klog.Errorf("Failed to fetch pod list in namespace %s: %v", namespace, err) | ||
return "", err | ||
} | ||
|
||
for _, pod := range podList.Items { | ||
if string(pod.UID) == podUID { | ||
klog.Info("pod ip is ", pod.Status.PodIP) | ||
return pod.Status.PodIP, nil | ||
} | ||
} | ||
return "", fmt.Errorf("pod %s with Uid %s not found in namespace %s", name, podUID, namespace) | ||
} | ||
|
||
func updateNodePodProbeStatus(update Update, newStatus *appsv1alpha1.NodePodProbeStatus) { | ||
var probeStatus *appsv1alpha1.PodProbeStatus | ||
for i := range newStatus.PodProbeStatuses { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ import ( | |
"bytes" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"time" | ||
|
||
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1" | ||
|
@@ -28,6 +30,8 @@ import ( | |
"k8s.io/klog/v2" | ||
"k8s.io/kubernetes/pkg/probe" | ||
execprobe "k8s.io/kubernetes/pkg/probe/exec" | ||
httpprobe "k8s.io/kubernetes/pkg/probe/http" | ||
tcpprobe "k8s.io/kubernetes/pkg/probe/tcp" | ||
"k8s.io/utils/exec" | ||
) | ||
|
||
|
@@ -36,6 +40,8 @@ const maxProbeMessageLength = 1024 | |
// Prober helps to check the probe(exec, http, tcp) of a container. | ||
type prober struct { | ||
exec execprobe.Prober | ||
tcp tcpprobe.Prober | ||
http httpprobe.Prober | ||
runtimeService criapi.RuntimeService | ||
} | ||
|
||
|
@@ -44,13 +50,15 @@ type prober struct { | |
func newProber(runtimeService criapi.RuntimeService) *prober { | ||
return &prober{ | ||
exec: execprobe.New(), | ||
tcp: tcpprobe.New(), | ||
http: httpprobe.New(false), | ||
runtimeService: runtimeService, | ||
} | ||
} | ||
|
||
// probe probes the container. | ||
func (pb *prober) probe(p *appsv1alpha1.ContainerProbeSpec, container *runtimeapi.ContainerStatus, containerID string) (appsv1alpha1.ProbeState, string, error) { | ||
result, msg, err := pb.runProbe(p, container, containerID) | ||
func (pb *prober) probe(p *appsv1alpha1.ContainerProbeSpec, container *runtimeapi.ContainerStatus, containerID string, hostIP string) (appsv1alpha1.ProbeState, string, error) { | ||
result, msg, err := pb.runProbe(p, container, containerID, hostIP) | ||
if bytes.Count([]byte(msg), nil)-1 > maxProbeMessageLength { | ||
msg = msg[:maxProbeMessageLength] | ||
} | ||
|
@@ -60,17 +68,40 @@ func (pb *prober) probe(p *appsv1alpha1.ContainerProbeSpec, container *runtimeap | |
return appsv1alpha1.ProbeSucceeded, msg, nil | ||
} | ||
|
||
func (pb *prober) runProbe(p *appsv1alpha1.ContainerProbeSpec, container *runtimeapi.ContainerStatus, containerID string) (probe.Result, string, error) { | ||
func (pb *prober) runProbe(p *appsv1alpha1.ContainerProbeSpec, container *runtimeapi.ContainerStatus, containerID string, hostIP string) (probe.Result, string, error) { | ||
timeSecond := p.TimeoutSeconds | ||
if timeSecond <= 0 { | ||
timeSecond = 1 | ||
} | ||
timeout := time.Duration(timeSecond) * time.Second | ||
// current only support exec | ||
// todo: http, tcp | ||
// for probing using exec method | ||
if p.Exec != nil { | ||
return pb.exec.Probe(pb.newExecInContainer(containerID, p.Exec.Command, timeout)) | ||
} | ||
|
||
// for probing using tcp method | ||
if p.TCPSocket.Port.IntVal != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can refer the kubernetes implement, https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/prober/prober.go#L143 |
||
if p.TCPSocket.Host != "" { | ||
return pb.tcp.Probe(p.TCPSocket.Host, p.TCPSocket.Port.IntValue(), timeout) | ||
} else { | ||
return pb.tcp.Probe(hostIP, p.TCPSocket.Port.IntValue(), timeout) | ||
} | ||
} | ||
|
||
// for probing using http method | ||
if p.HTTPGet.Path != "" { | ||
var u url.URL | ||
var header http.Header | ||
u.Scheme = "http" | ||
u.Path = p.HTTPGet.Path | ||
if p.HTTPGet.Host != "" { | ||
u.Host = p.HTTPGet.Host | ||
} else { | ||
u.Host = hostIP | ||
} | ||
return pb.http.Probe(&u, header, timeout) | ||
} | ||
|
||
klog.InfoS("Failed to find probe builder for container", "containerName", container.Metadata.Name) | ||
return probe.Unknown, "", fmt.Errorf("missing probe handler for %s", container.Metadata.Name) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gofmt: File is not
gofmt
-ed with-s
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nitishchauhan0022 you need resolve the gofmt check.