-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f08f9f3
commit 575b3ef
Showing
5 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Azure/eraser/test/e2e/util" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"sigs.k8s.io/e2e-framework/klient/wait" | ||
"sigs.k8s.io/e2e-framework/klient/wait/conditions" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/features" | ||
) | ||
|
||
func TestDeleteDeployment(t *testing.T) { | ||
deleteDeploymentFeat := features.New("Delete deployment should delete eraser pods"). | ||
Assess("Non-vulnerable image successfully deleted from all nodes", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||
ctxT, cancel := context.WithTimeout(ctx, util.Timeout) | ||
defer cancel() | ||
util.CheckImageRemoved(ctxT, t, util.GetClusterNodes(t), util.NonVulnerableImage) | ||
|
||
return ctx | ||
}). | ||
Assess("Delete deployment", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||
if err := util.GetPodLogs(t); err != nil { | ||
t.Error("error getting eraser pod logs", err) | ||
} | ||
|
||
if err := util.KubectlDelete(cfg.KubeconfigFile(), util.TestNamespace, []string{"deployment", "eraser-controller-manager"}); err != nil { | ||
t.Error("unable to delete eraser-controller-manager deployment") | ||
} | ||
|
||
return ctx | ||
}). | ||
Assess("Check eraser pods are deleted", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { | ||
if err := util.GetPodLogs(t); err != nil { | ||
t.Error("error getting eraser pod logs", err) | ||
} | ||
|
||
c, err := cfg.NewClient() | ||
if err != nil { | ||
t.Fatal("Failed to create new client", err) | ||
} | ||
|
||
var ls corev1.PodList | ||
err = c.Resources().List(ctx, &ls, func(o *metav1.ListOptions) { | ||
o.LabelSelector = labels.SelectorFromSet(map[string]string{util.ImageJobTypeLabelKey: util.CollectorLabel}).String() | ||
}) | ||
if err != nil { | ||
t.Errorf("could not list pods: %v", err) | ||
} | ||
|
||
err = wait.For(conditions.New(c.Resources()).ResourcesDeleted(&ls), wait.WithTimeout(util.Timeout)) | ||
if err != nil { | ||
t.Errorf("error waiting for pods to be deleted: %v", err) | ||
} | ||
|
||
return ctx | ||
}). | ||
Feature() | ||
|
||
util.Testenv.Test(t, deleteDeploymentFeat) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
eraserv1alpha1 "github.com/Azure/eraser/api/v1alpha1" | ||
"github.com/Azure/eraser/test/e2e/util" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/e2e-framework/pkg/env" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/envfuncs" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
utilruntime.Must(eraserv1alpha1.AddToScheme(scheme.Scheme)) | ||
|
||
removerImage := util.ParsedImages.RemoverImage | ||
managerImage := util.ParsedImages.ManagerImage | ||
collectorImage := util.ParsedImages.CollectorImage | ||
|
||
util.Testenv = env.NewWithConfig(envconf.New()) | ||
// Create KinD Cluster | ||
util.Testenv.Setup( | ||
envfuncs.CreateKindClusterWithConfig(util.KindClusterName, util.NodeVersion, util.KindConfigPath), | ||
envfuncs.CreateNamespace(util.TestNamespace), | ||
util.LoadImageToCluster(util.KindClusterName, util.ManagerImage, util.ManagerTarballPath), | ||
util.LoadImageToCluster(util.KindClusterName, util.RemoverImage, util.RemoverTarballPath), | ||
util.LoadImageToCluster(util.KindClusterName, util.RemoverImage, util.RemoverTarballPath), | ||
util.LoadImageToCluster(util.KindClusterName, util.CollectorImage, util.CollectorTarballPath), | ||
util.LoadImageToCluster(util.KindClusterName, util.NonVulnerableImage, ""), | ||
util.HelmDeployLatestEraserRelease(util.TestNamespace, | ||
"--set", util.ScannerEnable.Set("false"), | ||
"--set", util.CollectorEnable.Set("false"), | ||
"--set", util.RemoverImageRepo.Set(removerImage.Repo), | ||
"--set", util.RemoverImageTag.Set(removerImage.Tag), | ||
"--set", util.ManagerImageRepo.Set(managerImage.Repo), | ||
"--set", util.ManagerImageTag.Set(managerImage.Tag), | ||
), | ||
util.UpgradeEraserHelm(util.TestNamespace, | ||
"--set", util.ScannerEnable.Set("false"), | ||
"--set", util.RemoverImageRepo.Set(removerImage.Repo), | ||
"--set", util.RemoverImageTag.Set(removerImage.Tag), | ||
"--set", util.CollectorEnable.Set("true"), | ||
"--set", util.CollectorImageRepo.Set(collectorImage.Repo), | ||
"--set", util.CollectorImageTag.Set(collectorImage.Tag), | ||
"--set", util.ManagerImageRepo.Set(managerImage.Repo), | ||
"--set", util.ManagerImageTag.Set(managerImage.Tag), | ||
"--set", util.CleanupOnSuccessDelay.Set("2m"), | ||
), | ||
).Finish( | ||
envfuncs.DestroyKindCluster(util.KindClusterName), | ||
) | ||
os.Exit(util.Testenv.Run(m)) | ||
} |