fix pdb collection testing occasional failure

Signed-off-by: chaosi-zju <chaosi@zju.edu.cn>
This commit is contained in:
chaosi-zju 2024-08-15 20:26:15 +08:00
parent cd99897506
commit e7e06ceed8
2 changed files with 7 additions and 5 deletions

View File

@ -571,9 +571,13 @@ var _ = ginkgo.Describe("[resource-status collection] resource status collection
pdbNamespace = testNamespace
pdbName = policyName
deploymentName := policyName
// use a special label value to prevent PDB from selecting pods of other parallel e2e cases.
matchLabels := map[string]string{"app": "nginx-" + rand.String(RandomStrLength)}
deployment = testhelper.NewDeployment(pdbNamespace, deploymentName)
pdb = testhelper.NewPodDisruptionBudget(pdbNamespace, pdbName, intstr.FromString("50%"))
deployment.Spec.Selector.MatchLabels = matchLabels
deployment.Spec.Template.Labels = matchLabels
pdb = testhelper.NewPodDisruptionBudget(pdbNamespace, pdbName, intstr.FromString("50%"), matchLabels)
policy = testhelper.NewPropagationPolicy(policyNamespace, policyName, []policyv1alpha1.ResourceSelector{
{
APIVersion: pdb.APIVersion,

View File

@ -936,9 +936,7 @@ func NewIngress(namespace, name string) *networkingv1.Ingress {
}
// NewPodDisruptionBudget will build a new PodDisruptionBudget object.
func NewPodDisruptionBudget(namespace, name string, maxUnAvailable intstr.IntOrString) *policyv1.PodDisruptionBudget {
podLabels := map[string]string{"app": "nginx"}
func NewPodDisruptionBudget(namespace, name string, maxUnAvailable intstr.IntOrString, matchLabels map[string]string) *policyv1.PodDisruptionBudget {
return &policyv1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
APIVersion: "policy/v1",
@ -951,7 +949,7 @@ func NewPodDisruptionBudget(namespace, name string, maxUnAvailable intstr.IntOrS
Spec: policyv1.PodDisruptionBudgetSpec{
MaxUnavailable: &maxUnAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: podLabels,
MatchLabels: matchLabels,
},
},
}