func PortsListToPorts(list testers.Ports) []corev1.ContainerPort {
	ports := []corev1.ContainerPort{}
	for _, p := range list.TCP {
		ports = append(ports, corev1.ContainerPort{
			ContainerPort: p,
			Protocol:      corev1.ProtocolTCP,
		})
	}
	for _, p := range list.UDP {
		ports = append(ports, corev1.ContainerPort{
			ContainerPort: p,
			Protocol:      corev1.ProtocolUDP,
		})
	}
	return ports
}
PortsListToPorts PortList testers.Port to Kubernetes []corev1.ContainerPort conversion (for TCP and UDP)
package k8sutil
import (
	"context"
	"fmt"
	"time"
	"github.com/cloudical-io/ancientt/testers"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/client-go/kubernetes"
)
func PodRecreate(k8sclient kubernetes.Interface, pod *corev1.Pod, delTimeout int) error {
	if err := PodDelete(k8sclient, pod, delTimeout); err != nil {
		return err
	}
	ctx := context.TODO()
	if _, err := k8sclient.CoreV1().Pods(pod.ObjectMeta.Namespace).Create(ctx, pod, metav1.CreateOptions{}); err != nil {
		if !errors.IsAlreadyExists(err) {
			return err
		}
	}
	return nil
}
func PodDelete(k8sclient kubernetes.Interface, pod *corev1.Pod, timeout int) error {
	namespace := pod.ObjectMeta.Namespace
	podName := pod.ObjectMeta.Name
	ctx := context.TODO()
	if err := k8sclient.CoreV1().Pods(namespace).Delete(ctx, podName, metav1.DeleteOptions{}); err != nil {
		if errors.IsNotFound(err) {
			return nil
		}
		return err
	}
	for i := 0; i < timeout; i++ {
		ctx := context.TODO()
		if _, err := k8sclient.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{}); err != nil {
			if errors.IsNotFound(err) {
				return nil
			}
			return err
		}
		time.Sleep(1 * time.Second)
	}
	return fmt.Errorf("pod %s/%s not deleted after 30s", namespace, podName)
}
func PodDeleteByName(k8sclient kubernetes.Interface, namespace string, podName string, timeout int) error {
	return PodDelete(k8sclient, &corev1.Pod{
		ObjectMeta: metav1.ObjectMeta{
			Namespace: namespace,
			Name:      podName,
		},
	}, timeout)
}
func PodDeleteByLabels(k8sclient kubernetes.Interface, namespace string, selectorLabels map[string]string) error {
	set := labels.Set(selectorLabels)
	ctx := context.TODO()
	pods, err := k8sclient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
		LabelSelector: set.AsSelector().String(),
	})
	if err != nil {
		if errors.IsNotFound(err) {
			return nil
		}
		return err
	}
	if pods.Items == nil || len(pods.Items) == 0 {
		return nil
	}
	for _, pod := range pods.Items {
		ctx := context.TODO()
		if err := k8sclient.CoreV1().Pods(namespace).Delete(ctx, pod.ObjectMeta.Name, metav1.DeleteOptions{}); err != nil {
			if errors.IsNotFound(err) {
				return nil
			}
			return err
		}
	}
	return nil
}
func WaitForPodToRun(k8sclient kubernetes.Interface, namespace string, podName string, timeout int) (bool, error) {
	for i := 0; i < timeout; i++ {
		ctx := context.TODO()
		pod, err := k8sclient.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
		if err != nil {
			if !errors.IsAlreadyExists(err) {
				return false, err
			}
		}
		if pod.Status.Phase == corev1.PodRunning {
			return true, nil
		}
		time.Sleep(1 * time.Second)
	}
	return false, nil
}
func WaitForPodToSucceed(k8sclient kubernetes.Interface, namespace string, podName string, timeout int) (bool, error) {
	for i := 0; i < timeout; i++ {
		ctx := context.TODO()
		pod, err := k8sclient.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
		if err != nil {
			return false, err
		}
		if pod.Status.Phase == corev1.PodSucceeded {
			return true, nil
		}
		time.Sleep(1 * time.Second)
	}
	return false, nil
}
func WaitForPodToRunOrSucceed(k8sclient kubernetes.Interface, namespace string, podName string, timeout int) (bool, error) {
	for i := 0; i < timeout; i++ {
		ctx := context.TODO()
		pod, err := k8sclient.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
		if err != nil {
			return false, err
		}
		if pod.Status.Phase == corev1.PodRunning || pod.Status.Phase == corev1.PodSucceeded {
			return true, nil
		}
		time.Sleep(1 * time.Second)
	}
	return false, nil
}