Skip to content

Commit

Permalink
Assorted fixes on -use-cluster tests (#1391)
Browse files Browse the repository at this point in the history
- Use routes as ingress, when available
- Ignore unexpected additional clusterroles, when running as -use-cluster
- Shutdown previous informers between iterations
- Ignore additional cm openshift-service-ca.crt, along with kube-root-ca.crt
- Cherry pick Fernando's
- Router Create test improvement #1386 into 1.5
  • Loading branch information
hash-d committed Sep 5, 2024
1 parent f9d1eae commit c221f3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
18 changes: 15 additions & 3 deletions client/router_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,23 @@ func TestRouterCreateDefaults(t *testing.T) {
rolesFound = append(rolesFound, role.Name)
},
})

expectedClusterRoles := sets.NewString(c.clusterRolesExpected...)
clusterRoleInformer := clusterRoleInformerFactory.Rbac().V1().ClusterRoles().Informer()
clusterRoleInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
clusterRole := obj.(*rbacv1.ClusterRole)
if strings.HasPrefix(clusterRole.Name, "skupper") {
clusterRolesFound = append(clusterRolesFound, clusterRole.Name)
for _, p := range clusterRole.Rules {
clusterRolesResourcesFound = clusterRolesResourcesFound.Insert(p.Resources...)
if isCluster && !expectedClusterRoles.Has(clusterRole.Name) {
// A real cluster may have pre-existing clusterroles that would
// make this test flaky, so we ignore clusterroles not listed
// on the test.
fmt.Printf("clusterrole %q ignored due to -use-cluster\n", clusterRole.Name)
} else {
clusterRolesFound = append(clusterRolesFound, clusterRole.Name)
for _, p := range clusterRole.Rules {
clusterRolesResourcesFound = clusterRolesResourcesFound.Insert(p.Resources...)
}
}
}
},
Expand Down Expand Up @@ -476,6 +485,9 @@ func TestRouterCreateDefaults(t *testing.T) {
if diff := cmp.Diff(c.secretsExpected, secretsFound, c.opts...); diff != "" {
t.Errorf("TestRouterCreateDefaults "+c.doc+" secrets mismatch (-want +got):\n%s", diff)
}

// Close informers
cancel()
}
}

Expand Down
6 changes: 5 additions & 1 deletion client/serviceinterface_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func check_result(t *testing.T, name string, timeoutSeconds float64, resultType
if len(expected) <= 0 {
return
}

fmt.Printf("Checking %q results for test %q on %q\n", resultType, doc, name)

// Sometimes it requires a little time for the requested entities to be
// created and for the informers to tell us about them.
// So -- count down by tenths of a second until the allotted timeout expires,
Expand Down Expand Up @@ -227,7 +230,8 @@ func TestServiceInterfaceCreate(t *testing.T) {
cmInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
cm := obj.(*corev1.ConfigMap)
if cm.Name != "kube-root-ca.crt" { // seems to be something added in more recent kubernetes?
if cm.Name != "kube-root-ca.crt" && // auto-created, introduced in K8S 1.20
cm.Name != "openshift-service-ca.crt" { // auto-created, OCP 4.7
cmsFound = append(cmsFound, cm.Name)
}
},
Expand Down
25 changes: 25 additions & 0 deletions pkg/domain/podman/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ package podman
import (
"context"
"fmt"
"log"
"net"
"net/url"
"testing"
"time"

"github.com/skupperproject/skupper/pkg/utils"
"gotest.tools/assert"
corev1 "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -42,6 +46,27 @@ func TestLinkHandlerPodman(t *testing.T) {
}
assert.Assert(t, err)
assert.Assert(t, token != nil)

// On some clouds, it may take a while for the service DNS name to be externally
// resolvable. So, we extract that URL and wait for the name resolution to work
// before creating the link. If anything fails, we just log and keep going, as
// that's not the focus of the test; the whole thing may fail down the road,
// but with additional information for debugging.
skupperUrl := token.Annotations["skupper.io/url"]
if skupperUrl != "" {
parsed, err := url.Parse(skupperUrl)
if err != nil {
log.Printf("The skupper.io/url annotation did not parse as an URL (%q): %v", skupperUrl, err)
} else {
err = utils.RetryError(time.Second*2, 60, func() error {
_, err := net.ResolveIPAddr("ip", parsed.Hostname())
return err
})
if err != nil {
log.Printf("Name resolution for skupper.io/url (%q) still failing after 2 minutes: %v", parsed.Hostname(), err)
}
}
}
err = linkHandler.Create(token, linkName, 2)
assert.Assert(t, err)
})
Expand Down
6 changes: 6 additions & 0 deletions pkg/domain/podman/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,16 @@ func teardownKube() {
}

func configureSiteAndCreateRouter(ctx context.Context, cli *client.VanClient, name string) error {
var ingressType string
if cli.GetRouteClient() != nil {
// Like the product, we default to routes on OpenShift
ingressType = types.IngressRouteString
}
routerCreateOpts := types.SiteConfigSpec{
SkupperName: "skupper",
RouterMode: string(types.TransportModeInterior),
EnableController: true,
Ingress: ingressType,
}
siteConfig, err := cli.SiteConfigCreate(ctx, routerCreateOpts)
if err != nil {
Expand Down

0 comments on commit c221f3f

Please sign in to comment.