Skip to content

Commit 30a9307

Browse files
committed
feat: enable service provider tests with local dev images
On-behalf-of: @SAP [email protected] Signed-off-by: Christopher Junk <[email protected]>
1 parent 3469a3d commit 30a9307

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

e2e/main_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import (
1212

1313
"github.com/openmcp-project/openmcp-testing/pkg/providers"
1414
"github.com/openmcp-project/openmcp-testing/pkg/setup"
15+
"github.com/vladimirvivien/gexe"
1516
)
1617

1718
var testenv env.Environment
1819

1920
func TestMain(m *testing.M) {
2021
initLogging()
22+
serviceProviderImage := "ghcr.io/openmcp-project/images/service-provider-crossplane:v0.1.4"
23+
mustPullImage(serviceProviderImage)
2124
openmcp := setup.OpenMCPSetup{
2225
Namespace: "openmcp-system",
2326
Operator: setup.OpenMCPOperatorSetup{
@@ -35,7 +38,7 @@ func TestMain(m *testing.M) {
3538
ServiceProviders: []providers.ServiceProviderSetup{
3639
{
3740
Name: "crossplane",
38-
Image: "ghcr.io/openmcp-project/images/service-provider-crossplane:v0.1.4",
41+
Image: serviceProviderImage,
3942
},
4043
},
4144
}
@@ -53,3 +56,13 @@ func initLogging() {
5356
}
5457
flag.Parse()
5558
}
59+
60+
func mustPullImage(image string) {
61+
klog.Info("Pulling ", image)
62+
runner := gexe.New()
63+
p := runner.RunProc(fmt.Sprintf("docker pull %s", image))
64+
klog.V(4).Info(p.Out())
65+
if p.Err() != nil {
66+
panic(fmt.Errorf("docker pull %v failed: %w: %s", image, p.Err(), p.Result()))
67+
}
68+
}

pkg/setup/bootstrap.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ type OpenMCPOperatorSetup struct {
3636

3737
// Bootstrap sets up a the minimum set of components of an openMCP installation
3838
func (s *OpenMCPSetup) Bootstrap(testenv env.Environment) error {
39-
platformClusterName := envconf.RandomName("platform-cluster", 16)
39+
platformClusterName := envconf.RandomName("platform-", 16)
4040
s.Operator.Namespace = s.Namespace
4141
testenv.Setup(createPlatformCluster(platformClusterName)).
4242
Setup(envfuncs.CreateNamespace(s.Namespace)).
4343
Setup(s.installOpenMCPOperator()).
44+
Setup(s.loadServiceProviderImages(platformClusterName)).
4445
Setup(s.installClusterProviders()).
4546
Setup(s.installServiceProviders()).
4647
Setup(s.verifyEnvironment()).
@@ -109,7 +110,6 @@ func (s *OpenMCPSetup) installClusterProviders() env.Func {
109110
}
110111
}
111112

112-
// InstallServiceProvider creates a service provider object on the platform cluster and waits until it is ready
113113
func (s *OpenMCPSetup) installServiceProviders() env.Func {
114114
return func(ctx context.Context, c *envconf.Config) (context.Context, error) {
115115
for _, sp := range s.ServiceProviders {
@@ -120,3 +120,24 @@ func (s *OpenMCPSetup) installServiceProviders() env.Func {
120120
return ctx, nil
121121
}
122122
}
123+
124+
func (s *OpenMCPSetup) loadServiceProviderImages(platformCluster string) env.Func {
125+
funcs := []env.Func{}
126+
for _, sp := range s.ServiceProviders {
127+
funcs = append(funcs, envfuncs.LoadDockerImageToCluster(platformCluster, sp.Image))
128+
}
129+
return Compose(funcs...)
130+
}
131+
132+
// Compose executes multiple env.Funcs in a row
133+
func Compose(envfuncs ...env.Func) env.Func {
134+
return func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
135+
for _, envfunc := range envfuncs {
136+
var err error
137+
if ctx, err = envfunc(ctx, cfg); err != nil {
138+
return ctx, err
139+
}
140+
}
141+
return ctx, nil
142+
}
143+
}

0 commit comments

Comments
 (0)