Skip to content

Commit

Permalink
Remove completed pods in e2e
Browse files Browse the repository at this point in the history
EKS cluster suffers from limited number of private IPs, which are
exausted by test suites running in parallel. It affects GitRepo
processing, where a pod created to update content of the repo in order
to apply manifests to the cluster. Since the pod is not able to be
scheduled, e2e tests are failing.

Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Jan 22, 2025
1 parent 3d5dd5d commit d01728d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion test/e2e/specs/import_gitops_mgmtv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type CreateMgmtV3UsingGitOpsSpecInput struct {
// automatically imports into Rancher Manager.
func CreateMgmtV3UsingGitOpsSpec(ctx context.Context, inputGetter func() CreateMgmtV3UsingGitOpsSpecInput) {
var (
specName = "creategitops-v3"
specName = "creategitops"
input CreateMgmtV3UsingGitOpsSpecInput
namespace *corev1.Namespace
repoName string
Expand Down Expand Up @@ -172,6 +172,7 @@ func CreateMgmtV3UsingGitOpsSpec(ctx context.Context, inputGetter func() CreateM
input = inputGetter()
Expect(turtlesframework.Parse(&input)).To(Succeed(), "Failed to parse environment variables")

Expect(input.GitAddr).ToNot(BeEmpty(), "Invalid argument. input.GitAddr can't be empty when calling %s spec", specName)
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
Expect(os.MkdirAll(input.ArtifactFolder, 0750)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/suites/import-gitops-v3/import_gitops_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var _ = Describe("[Azure] [AKS] - [management.cattle.io/v3] Create and delete CA
E2EConfig: e2e.LoadE2EConfig(),
BootstrapClusterProxy: bootstrapClusterProxy,
ClusterTemplate: e2e.CAPIAzureAKSTopology,
ClusterName: "highlander-e2e-topology",
ClusterName: "cluster-aks",
ControlPlaneMachineCount: ptr.To[int](1),
WorkerMachineCount: ptr.To[int](1),
GitAddr: gitAddress,
Expand All @@ -125,7 +125,7 @@ var _ = Describe("[AWS] [EKS] - [management.cattle.io/v3] Create and delete CAPI
E2EConfig: e2e.LoadE2EConfig(),
BootstrapClusterProxy: bootstrapClusterProxy,
ClusterTemplate: e2e.CAPIAwsEKSMMP,
ClusterName: "clusterv3-eks",
ClusterName: "cluster-eks",
ControlPlaneMachineCount: ptr.To[int](1),
WorkerMachineCount: ptr.To[int](1),
GitAddr: gitAddress,
Expand All @@ -152,7 +152,7 @@ var _ = Describe("[GCP] [GKE] - [management.cattle.io/v3] Create and delete CAPI
E2EConfig: e2e.LoadE2EConfig(),
BootstrapClusterProxy: bootstrapClusterProxy,
ClusterTemplate: e2e.CAPIGCPGKE,
ClusterName: "clusterv3-gke",
ClusterName: "cluster-gke",
ControlPlaneMachineCount: ptr.To[int](1),
WorkerMachineCount: ptr.To[int](1),
GitAddr: gitAddress,
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/suites/import-gitops-v3/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ package import_gitops_v3

import (
"context"
"encoding/json"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher/turtles/test/e2e"
"github.com/rancher/turtles/test/testenv"
"k8s.io/apimachinery/pkg/util/json"
capiframework "sigs.k8s.io/cluster-api/test/framework"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand Down Expand Up @@ -132,6 +132,8 @@ var _ = SynchronizedBeforeSuite(
CustomIngressConfig: e2e.GiteaIngress,
})

Expect(testenv.CleanupClusterPodPool(ctx, setupClusterResult.BootstrapClusterProxy.GetClient())).To(Succeed())

data, err := json.Marshal(e2e.Setup{
ClusterName: setupClusterResult.ClusterName,
KubeconfigPath: setupClusterResult.KubeconfigPath,
Expand All @@ -158,11 +160,11 @@ var _ = SynchronizedAfterSuite(
},
func() {
testenv.UninstallGitea(ctx, testenv.UninstallGiteaInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
BootstrapClusterProxy: bootstrapClusterProxy,
})

testenv.UninstallRancherTurtles(ctx, testenv.UninstallRancherTurtlesInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
BootstrapClusterProxy: bootstrapClusterProxy,
})

testenv.CleanupTestCluster(ctx, testenv.CleanupTestClusterInput{
Expand Down
17 changes: 17 additions & 0 deletions test/testenv/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
turtlesframework "github.com/rancher/turtles/test/framework"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

Expand Down Expand Up @@ -139,3 +143,16 @@ func dumpBootstrapCluster(ctx context.Context) {
return
}
}

// CleanupClusterPodPool removes some of the finished pods after rancher rollout to cleanup pod pool to
// allow scheduling new pods.
func CleanupClusterPodPool(ctx context.Context, cl client.Client) error {
req, err := labels.NewRequirement("pod-impersonation.cattle.io/token", selection.Exists, []string{})
if err != nil {
return err
}

return cl.DeleteAllOf(ctx, &corev1.Pod{}, client.InNamespace(""), client.MatchingLabelsSelector{
Selector: labels.NewSelector().Add(*req),
})
}

0 comments on commit d01728d

Please sign in to comment.