Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #1653: E2E: use ServiceDiscovery CR to determine if clusterset IP is #1654

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading