mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #101960 from knight42/fix/deflake-metrics-proxy
Deflake tests that need to grab metrics from controller-manager or scheduler
This commit is contained in:
commit
c495744436
@ -34,38 +34,53 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type componentInfo struct {
|
type componentInfo struct {
|
||||||
|
Name string
|
||||||
Port int
|
Port int
|
||||||
IP string
|
IP string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupMetricsProxy creates a nginx Pod to expose metrics from the secure port of kube-scheduler and kube-controller-manager in tests.
|
// SetupMetricsProxy creates a nginx Pod to expose metrics from the secure port of kube-scheduler and kube-controller-manager in tests.
|
||||||
func SetupMetricsProxy(c clientset.Interface) error {
|
func SetupMetricsProxy(c clientset.Interface) error {
|
||||||
podList, err := c.CoreV1().Pods(metav1.NamespaceSystem).List(context.TODO(), metav1.ListOptions{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var infos []componentInfo
|
var infos []componentInfo
|
||||||
for _, pod := range podList.Items {
|
// The component pods might take some time to show up.
|
||||||
switch {
|
err := wait.PollImmediate(time.Second*5, time.Minute*5, func() (bool, error) {
|
||||||
case strings.HasPrefix(pod.Name, "kube-scheduler-"):
|
podList, err := c.CoreV1().Pods(metav1.NamespaceSystem).List(context.TODO(), metav1.ListOptions{})
|
||||||
infos = append(infos, componentInfo{
|
if err != nil {
|
||||||
Port: kubeSchedulerPort,
|
return false, fmt.Errorf("list pods in ns %s: %w", metav1.NamespaceSystem, err)
|
||||||
IP: pod.Status.PodIP,
|
|
||||||
})
|
|
||||||
case strings.HasPrefix(pod.Name, "kube-controller-manager-"):
|
|
||||||
infos = append(infos, componentInfo{
|
|
||||||
Port: kubeControllerManagerPort,
|
|
||||||
IP: pod.Status.PodIP,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if len(infos) == 2 {
|
var foundComponents []componentInfo
|
||||||
break
|
for _, pod := range podList.Items {
|
||||||
|
if len(pod.Status.PodIP) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(pod.Name, "kube-scheduler-"):
|
||||||
|
foundComponents = append(foundComponents, componentInfo{
|
||||||
|
Name: pod.Name,
|
||||||
|
Port: kubeSchedulerPort,
|
||||||
|
IP: pod.Status.PodIP,
|
||||||
|
})
|
||||||
|
case strings.HasPrefix(pod.Name, "kube-controller-manager-"):
|
||||||
|
foundComponents = append(foundComponents, componentInfo{
|
||||||
|
Name: pod.Name,
|
||||||
|
Port: kubeControllerManagerPort,
|
||||||
|
IP: pod.Status.PodIP,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if len(foundComponents) != 2 {
|
||||||
|
klog.Infof("Only %d components found. Will retry.", len(foundComponents))
|
||||||
|
klog.Infof("Found components: %v", foundComponents)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
infos = foundComponents
|
||||||
|
return true, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("missing component pods: %w", err)
|
||||||
}
|
}
|
||||||
if len(infos) == 0 {
|
|
||||||
klog.Warningf("Can't find any pods in namespace %s to grab metrics from", metav1.NamespaceSystem)
|
klog.Infof("Found components: %v", infos)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = metricsProxyPod
|
const name = metricsProxyPod
|
||||||
_, err = c.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Create(context.TODO(), &v1.ServiceAccount{
|
_, err = c.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Create(context.TODO(), &v1.ServiceAccount{
|
||||||
|
Loading…
Reference in New Issue
Block a user