Skip to content

Commit

Permalink
Added testing for issue skupperproject#753
Browse files Browse the repository at this point in the history
Signed-off-by: Danilo Gonzalez Hashimoto <[email protected]>
  • Loading branch information
hash-d committed Jun 3, 2022
1 parent 0aba3c8 commit 29bfbe3
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
136 changes: 136 additions & 0 deletions test/integration/acceptance/custom/hello_policy/issues_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//go:build policy
// +build policy

package hello_policy

import (
"fmt"
"log"
"strings"
"testing"
"time"

"github.com/skupperproject/skupper/client"
skupperv1 "github.com/skupperproject/skupper/pkg/apis/skupper/v1alpha1"
"github.com/skupperproject/skupper/pkg/kube"
"github.com/skupperproject/skupper/test/utils/base"
"github.com/skupperproject/skupper/test/utils/skupper/cli"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func test753(t *testing.T, pub, prv *base.ClusterContext) {

done := make(chan int)
var count int

testTable := []policyTestCase{
{
name: "init",
steps: []policyTestStep{
{
name: "init",
parallel: true,
pubPolicy: []skupperv1.SkupperClusterPolicySpec{
allowIncomingLinkPolicy(pub.Namespace, true),
},
cliScenarios: []cli.TestScenario{
skupperInitInteriorTestScenario(pub, "", true),
skupperInitEdgeTestScenario(prv, "", true),
},
},
},
}, {
name: "main",
steps: []policyTestStep{
{
name: "do-on-hook",
preHook: func(_ map[string]string) error {
// keep removing the pod
go func() {
breakLabel:
for {
select {
case <-done:
break breakLabel
default:
seekServiceControllerAndDelete(pub)
count++
}
time.Sleep(time.Second)
}
log.Print("Closing goroutine")
}()

p := client.NewPolicyValidatorAPI(pub.VanClient)
for count < 30 {
_, err := p.IncomingLink()

if err != nil {
log.Printf("Error: %v", err)
if strings.Contains(err.Error(), "command terminated with exit code") {
return fmt.Errorf("Error matched: '%w'", err)
}
}

}

close(done)
return nil
},
},
},
}, {
name: "cleanup",
steps: []policyTestStep{
{
name: "execute",
parallel: true,
cliScenarios: []cli.TestScenario{
deleteSkupperTestScenario(pub, "pub"),
deleteSkupperTestScenario(prv, "prv"),
},
},
},
},
}

policyTestRunner{
testCases: testTable,
keepPolicies: true,
prvPolicies: []skupperv1.SkupperClusterPolicySpec{
allowedOutgoingLinksHostnamesPolicy(prv.Namespace, []string{"*"}),
},
}.run(t, pub, prv)

}

func seekServiceControllerAndDelete(ctx *base.ClusterContext) {
/*
pods, err := ctx.VanClient.KubeClient.CoreV1().Pods(ctx.Namespace).List(
metav1.ListOptions{LabelSelector: "skupper.io/component=service-controller"},
)
if err != nil {
log.Printf("Got pod listing error: %v", err)
return
}
if len(pods.Items) == 0 {
log.Printf("No pods found")
return
}
if len(pods.Items) > 1 {
log.Printf("Multiple pounds found; picking the one that shows as ready")
}
*/

pod, err := kube.GetReadyPod(ctx.Namespace, ctx.VanClient.KubeClient, "service-controller")
if err != nil {
log.Printf("Ignoring pod listing error '%v'", err)
return
}

ctx.VanClient.KubeClient.CoreV1().Pods(ctx.Namespace).Delete(
pod.Name,
&metav1.DeleteOptions{},
)

}
2 changes: 2 additions & 0 deletions test/integration/acceptance/custom/hello_policy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ func TestPolicies(t *testing.T) {
function: testHostnamesPolicy,
}, {
function: testResourcesPolicy,
}, {
function: test753,
},
}

Expand Down

0 comments on commit 29bfbe3

Please sign in to comment.