Skip to content

Commit

Permalink
Merge pull request #5382 from chaosi-zju/master
Browse files Browse the repository at this point in the history
fix pdb collection testing occasional failure
  • Loading branch information
karmada-bot authored Aug 16, 2024
2 parents 3beafb5 + e7e06ce commit 4ac6285
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 5 additions & 1 deletion test/e2e/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions test/helper/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -951,7 +949,7 @@ func NewPodDisruptionBudget(namespace, name string, maxUnAvailable intstr.IntOrS
Spec: policyv1.PodDisruptionBudgetSpec{
MaxUnavailable: &maxUnAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: podLabels,
MatchLabels: matchLabels,
},
},
}
Expand Down

0 comments on commit 4ac6285

Please sign in to comment.