Skip to content

Commit

Permalink
Merge pull request #1548 from daemon1024/chore-tests-cleanup
Browse files Browse the repository at this point in the history
chore(tests): cleanup unused code and add sleep to prevent flakiness
  • Loading branch information
DelusionalOptimist authored Dec 14, 2023
2 parents 15803aa + 95fed37 commit 69b57dd
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 151 deletions.
9 changes: 3 additions & 6 deletions tests/k8s_env/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ var _ = BeforeSuite(func() {
// delete all KSPs
err = DeleteAllKsp()
Expect(err).To(BeNil())

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())
})

var _ = AfterSuite(func() {
// delete wordpress-mysql app
err := K8sDelete([]string{"res/wordpress-mysql-deployment.yaml"})
Expect(err).To(BeNil())

KubearmorPortForwardStop()
})

func getWpsqlPod(name string, ant string) string {
Expand Down Expand Up @@ -96,6 +90,9 @@ var _ = Describe("Posture", func() {
err := K8sApplyFile("res/ksp-wordpress-allow-file.yaml")
Expect(err).To(BeNil())

// wait for policy creation, added due to flaky behaviour
time.Sleep(5 * time.Second)

// Start Kubearmor Logs
err = KarmorLogStart("policy", "wordpress-mysql", "File", wp)
Expect(err).To(BeNil())
Expand Down
13 changes: 8 additions & 5 deletions tests/k8s_env/configmap/kubearmor_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ var _ = BeforeSuite(func() {
// delete all KSPs
err = DeleteAllKsp()
Expect(err).To(BeNil())

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())
})

var _ = AfterSuite(func() {
KubearmorPortForwardStop()
cm := NewDefaultConfigMapData()
cm.DefaultFilePosture = "block"
cm.DefaultCapabilitiesPosture = "block"
Expand Down Expand Up @@ -87,6 +82,10 @@ var _ = Describe("KubeArmor-Config", func() {
// default global visibility is none
cm := NewDefaultConfigMapData()
err := cm.CreateKAConfigMap()
Expect(err).To(BeNil())

// wait for visibility maps to be updated in kernel, added due to flaky behaviour
time.Sleep(5 * time.Second)

err = KarmorLogStart("all", "unannotated", "", unannotated)
Expect(err).To(BeNil())
Expand All @@ -106,6 +105,9 @@ var _ = Describe("KubeArmor-Config", func() {
err = cm.CreateKAConfigMap()
Expect(err).To(BeNil())

// wait for visibility maps to be updated in kernel, added due to flaky behaviour
time.Sleep(5 * time.Second)

err = KarmorLogStart("all", "unannotated", "", unannotated)
Expect(err).To(BeNil())

Expand Down Expand Up @@ -245,6 +247,7 @@ var _ = Describe("KubeArmor-Config", func() {
// default global visibility is none
cm := NewDefaultConfigMapData()
err := cm.CreateKAConfigMap()
Expect(err).To(BeNil())

err = KarmorLogStart("all", "fullyannotated", "", fullyAnnotated)
Expect(err).To(BeNil())
Expand Down
7 changes: 0 additions & 7 deletions tests/k8s_env/ksp/ksp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@ var _ = BeforeSuite(func() {
// delete all KSPs
err = DeleteAllKsp()
Expect(err).To(BeNil())

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())

})

var _ = AfterSuite(func() {
// delete multiubuntu deployment
err := K8sDelete([]string{"multiubuntu/multiubuntu-deployment.yaml"})
Expect(err).To(BeNil())

KubearmorPortForwardStop()
})

func getUbuntuPod(name string, ant string) string {
Expand Down
5 changes: 0 additions & 5 deletions tests/k8s_env/multicontainer/multicontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ var _ = BeforeSuite(func() {

// delete all KSPs
KspDeleteAll()

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())
})

var _ = AfterSuite(func() {
// delete wordpress-mysql app from multicontainer ns
err := K8sDelete([]string{"manifests/multicontainer-deployment.yaml"})
Expect(err).To(BeNil())
KubearmorPortForwardStop()
})

func getMultiContainerPod(name string, ant string) string {
Expand Down
6 changes: 0 additions & 6 deletions tests/k8s_env/smoke/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@ var _ = BeforeSuite(func() {
// delete all KSPs
err = DeleteAllKsp()
Expect(err).To(BeNil())

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())
})

var _ = AfterSuite(func() {
// Delete wordpress-mysql app
err := K8sDelete([]string{"res/wordpress-mysql-deployment.yaml"})
Expect(err).To(BeNil())

KubearmorPortForwardStop()
})

func getWpsqlPod(name string, ant string) string {
Expand Down
6 changes: 0 additions & 6 deletions tests/k8s_env/syscalls/syscalls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@ var _ = BeforeSuite(func() {

// delete all KSPs
KspDeleteAll()

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())

})

var _ = AfterSuite(func() {
// delete wordpress-mysql app from syscalls ns
err := K8sDelete([]string{"manifests/ubuntu-deployment.yaml"})
Expect(err).To(BeNil())
KubearmorPortForwardStop()
})

func getUbuntuPod(name string, ant string) string {
Expand Down
6 changes: 0 additions & 6 deletions tests/k8s_env/visibility/visibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ var _ = BeforeSuite(func() {
// delete all KSPs
err = DeleteAllKsp()
Expect(err).To(BeNil())

// enable kubearmor port forwarding
err = KubearmorPortForward()
Expect(err).To(BeNil())
})

var _ = AfterSuite(func() {
// delete wordpress-mysql app
err := K8sDelete([]string{"../smoke/res/wordpress-mysql-deployment.yaml"})
Expect(err).To(BeNil())

KubearmorPortForwardStop()
})

func getWpsqlPod(name string, ant string) string {
Expand Down
3 changes: 1 addition & 2 deletions tests/util/kartutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

var k8sClient *kcli.Client
var kcClient *kc.SecurityV1Client
var stopChan chan struct{}

// ConfigMapData hosts the structure which is used to configure Config Map Data
type ConfigMapData struct {
Expand Down Expand Up @@ -434,7 +433,7 @@ func DeleteAllKsp() error {
for _, k := range ksp.Items {
err = k8sClient.KSPClientset.KubeArmorPolicies(ns.Name).Delete(context.TODO(), k.Name, metav1.DeleteOptions{})
if err != nil {
log.Errorf("error deleting ksp %s in the namespace %s", k.Name, &ns.Name)
log.Errorf("error deleting ksp %s in the namespace %s", k.Name, ns.Name)
return err
}
log.Printf("deleted ksp %s in the namespace %s", k.Name, ns.Name)
Expand Down
108 changes: 0 additions & 108 deletions tests/util/portforward.go

This file was deleted.

0 comments on commit 69b57dd

Please sign in to comment.