Skip to content

Commit

Permalink
E2E: use ServiceDiscovery CR to determine if clusterset IP is enabled
Browse files Browse the repository at this point in the history
...in E2E tests coz lighthouse agent may not be present if
service-discovery is disabled.

Signed-off-by: Vishal Thapar <[email protected]>
Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
vthapar authored and tpantelis committed Oct 2, 2024
1 parent 025858c commit ea9fb6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion test/e2e/discovery/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ = Describe("Test Service Discovery Across Clusters", Label(TestLabel), fun
f := lhframework.NewFramework("discovery")

BeforeEach(func() {
if lhframework.ClusterSetIPEnabled {
if lhframework.IsClusterSetIPEnabled() {
Skip("The clusterset IP feature is enabled globally - skipping the test")
}
})
Expand Down
47 changes: 27 additions & 20 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"sync/atomic"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/resource"
"github.com/submariner-io/admiral/pkg/slices"
"github.com/submariner-io/lighthouse/pkg/constants"
Expand Down Expand Up @@ -67,7 +66,7 @@ var (
MCSClients []*mcsClientset.Clientset
EndpointClients []dynamic.ResourceInterface
SubmarinerClients []dynamic.ResourceInterface
ClusterSetIPEnabled = false
clusterSetIPEnabled = atomic.Pointer[bool]{}
)

func init() {
Expand Down Expand Up @@ -101,23 +100,6 @@ func beforeSuite() {
}

framework.DetectGlobalnet()

for _, k8sClient := range framework.KubeClients {
framework.AwaitUntil("find lighthouse agent deployment", func() (interface{}, error) {
return k8sClient.AppsV1().Deployments(framework.TestContext.SubmarinerNamespace).Get(context.TODO(),
names.ServiceDiscoveryComponent, metav1.GetOptions{})
}, func(result interface{}) (bool, string, error) {
d := result.(*appsv1.Deployment)
for i := range d.Spec.Template.Spec.Containers[0].Env {
if d.Spec.Template.Spec.Containers[0].Env[i].Name == "SUBMARINER_CLUSTERSET_IP_ENABLED" &&
d.Spec.Template.Spec.Containers[0].Env[i].Value == strconv.FormatBool(true) {
ClusterSetIPEnabled = true
}
}

return true, "", nil
})
}
}

func createLighthouseClient(restConfig *rest.Config) *mcsClientset.Clientset {
Expand Down Expand Up @@ -151,6 +133,31 @@ func createSubmarinerClientSet(restConfig *rest.Config) dynamic.ResourceInterfac
return submarinersClient
}

func IsClusterSetIPEnabled() bool {
enabledPtr := clusterSetIPEnabled.Load()
if enabledPtr != nil {
return *enabledPtr
}

gvr, _ := schema.ParseResourceArg("servicediscoveries.v1alpha1.submariner.io")
sdClient := framework.DynClients[0].Resource(*gvr).Namespace(framework.TestContext.SubmarinerNamespace)

framework.AwaitUntil("find service-discovery resource", func() (interface{}, error) {
return sdClient.Get(context.TODO(), "service-discovery", metav1.GetOptions{})
}, func(result interface{}) (bool, string, error) {
enabled, _, err := unstructured.NestedBool(result.(*unstructured.Unstructured).Object, "spec", "clustersetIPEnabled")
if err != nil {
return false, "", err
}

clusterSetIPEnabled.Store(ptr.To(enabled))

return true, "", nil
})

return *clusterSetIPEnabled.Load()
}

func (f *Framework) NewServiceExport(cluster framework.ClusterIndex, name, namespace string) *mcsv1a1.ServiceExport {
return f.CreateServiceExport(cluster, &mcsv1a1.ServiceExport{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit ea9fb6e

Please sign in to comment.