From caa0bfed26a6aa704b3e0286695f2f49b8842f93 Mon Sep 17 00:00:00 2001 From: Christopher Junk Date: Wed, 3 Dec 2025 15:29:07 +0100 Subject: [PATCH] fix: support wait options for any setup and use default timeouts in sample test On-behalf-of: @SAP christopher.junk@sap.com Signed-off-by: Christopher Junk --- e2e/main_test.go | 8 -------- pkg/providers/clusterprovider.go | 8 ++++---- pkg/providers/serviceprovider.go | 8 ++++---- pkg/setup/bootstrap.go | 14 +++++++------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/e2e/main_test.go b/e2e/main_test.go index 6ac42b5..bc03a10 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -5,10 +5,8 @@ import ( "fmt" "os" "testing" - "time" "k8s.io/klog/v2" - "sigs.k8s.io/e2e-framework/klient/wait" "sigs.k8s.io/e2e-framework/pkg/env" "sigs.k8s.io/e2e-framework/pkg/envconf" @@ -32,18 +30,12 @@ func TestMain(m *testing.M) { { Name: "kind", Image: "ghcr.io/openmcp-project/images/cluster-provider-kind:v0.0.15", - Opts: []wait.Option{ - wait.WithTimeout(time.Minute), - }, }, }, ServiceProviders: []providers.ServiceProviderSetup{ { Name: "crossplane", Image: "ghcr.io/openmcp-project/images/service-provider-crossplane:v0.1.4", - Opts: []wait.Option{ - wait.WithTimeout(time.Minute), - }, }, }, } diff --git a/pkg/providers/clusterprovider.go b/pkg/providers/clusterprovider.go index d28732b..2a9785f 100644 --- a/pkg/providers/clusterprovider.go +++ b/pkg/providers/clusterprovider.go @@ -47,9 +47,9 @@ spec: // ClusterProviderSetup represents the configuration parameters to set up a cluster provider type ClusterProviderSetup struct { - Name string - Image string - Opts []wait.Option + Name string + Image string + WaitOpts []wait.Option } func mcpRef(ref types.NamespacedName) *unstructured.Unstructured { @@ -93,7 +93,7 @@ func InstallClusterProvider(ctx context.Context, c *envconf.Config, clusterProvi if err != nil { return err } - return wait.For(conditions.Match(obj, c, "Ready", corev1.ConditionTrue), clusterProvider.Opts...) + return wait.For(conditions.Match(obj, c, "Ready", corev1.ConditionTrue), clusterProvider.WaitOpts...) } // DeleteClusterProvider deletes the cluster provider object and waits until the object has been deleted diff --git a/pkg/providers/serviceprovider.go b/pkg/providers/serviceprovider.go index ccce52c..5c83fbc 100644 --- a/pkg/providers/serviceprovider.go +++ b/pkg/providers/serviceprovider.go @@ -28,9 +28,9 @@ spec: // ServiceProviderSetup represents the configuration parameters to set up a service provider type ServiceProviderSetup struct { - Name string - Image string - Opts []wait.Option + Name string + Image string + WaitOpts []wait.Option } func serviceProviderRef(name string) *unstructured.Unstructured { @@ -51,7 +51,7 @@ func InstallServiceProvider(ctx context.Context, c *envconf.Config, sp ServicePr if err != nil { return err } - return wait.For(conditions.Match(obj, c, "Ready", corev1.ConditionTrue), sp.Opts...) + return wait.For(conditions.Match(obj, c, "Ready", corev1.ConditionTrue), sp.WaitOpts...) } // ImportServiceProviderAPIs iterates over each resource from the passed in directory diff --git a/pkg/setup/bootstrap.go b/pkg/setup/bootstrap.go index 885651f..df5a911 100644 --- a/pkg/setup/bootstrap.go +++ b/pkg/setup/bootstrap.go @@ -2,7 +2,6 @@ package setup import ( "context" - "time" apimachinerytypes "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" @@ -23,6 +22,7 @@ type OpenMCPSetup struct { Operator OpenMCPOperatorSetup ClusterProviders []providers.ClusterProviderSetup ServiceProviders []providers.ServiceProviderSetup + WaitOpts []wait.Option } type OpenMCPOperatorSetup struct { @@ -31,6 +31,7 @@ type OpenMCPOperatorSetup struct { Image string Environment string PlatformName string + WaitOpts []wait.Option } // Bootstrap sets up a the minimum set of components of an openMCP installation @@ -57,16 +58,16 @@ func (s *OpenMCPSetup) cleanup() types.EnvFunc { return func(ctx context.Context, c *envconf.Config) (context.Context, error) { klog.Info("cleaning up environment...") for _, sp := range s.ServiceProviders { - if err := providers.DeleteServiceProvider(ctx, c, sp.Name, wait.WithTimeout(time.Minute)); err != nil { + if err := providers.DeleteServiceProvider(ctx, c, sp.Name, sp.WaitOpts...); err != nil { klog.Errorf("delete service provider failed: %v", err) } } if err := providers.DeleteCluster(ctx, c, apimachinerytypes.NamespacedName{Namespace: s.Namespace, Name: "onboarding"}, - wait.WithTimeout(time.Second*20)); err != nil { + s.WaitOpts...); err != nil { klog.Errorf("delete cluster failed: %v", err) } for _, cp := range s.ClusterProviders { - if err := providers.DeleteClusterProvider(ctx, c, cp.Name, wait.WithTimeout(time.Minute)); err != nil { + if err := providers.DeleteClusterProvider(ctx, c, cp.Name, cp.WaitOpts...); err != nil { klog.Errorf("delete cluster provider failed: %v", err) } } @@ -77,7 +78,7 @@ func (s *OpenMCPSetup) cleanup() types.EnvFunc { func (s *OpenMCPSetup) verifyEnvironment() types.EnvFunc { return func(ctx context.Context, c *envconf.Config) (context.Context, error) { klog.Info("verify environment...") - return ctx, providers.ClustersReady(ctx, c, wait.WithTimeout(time.Minute)) + return ctx, providers.ClustersReady(ctx, c, s.WaitOpts...) } } @@ -89,8 +90,7 @@ func (s *OpenMCPSetup) installOpenMCPOperator() types.EnvFunc { } // wait for deployment to be ready if err := wait.For(conditions.New(c.Client().Resources()). - DeploymentAvailable(s.Operator.Name, s.Operator.Namespace), - wait.WithTimeout(time.Minute)); err != nil { + DeploymentAvailable(s.Operator.Name, s.Operator.Namespace), s.Operator.WaitOpts...); err != nil { return ctx, err } klog.Info("openmcp operator ready")