Skip to content

Commit b9ea76e

Browse files
committed
refactor: embed bootstrap config files
On-behalf-of: @SAP [email protected] Signed-off-by: Christopher Junk <[email protected]>
1 parent 2b66722 commit b9ea76e

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

internal/util.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package internal
22

33
import (
4+
"embed"
5+
"fmt"
46
"io"
57
"os"
8+
"path/filepath"
69
"strings"
710
"text/template"
811

@@ -66,3 +69,22 @@ func UnstructuredRef(name string, namespace string, gvk schema.GroupVersionKind)
6669
obj.SetGroupVersionKind(gvk)
6770
return obj
6871
}
72+
73+
// MustTmpFileFromEmbedFS creates a temporary file from an embedded file and returns the file path
74+
func MustTmpFileFromEmbedFS(fs embed.FS, path string) string {
75+
data, err := fs.ReadFile(path)
76+
if err != nil {
77+
panic(err)
78+
}
79+
file := filepath.Base(path)
80+
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-*", file))
81+
if err != nil {
82+
panic(err)
83+
}
84+
tmpPath := filepath.Join(tmpDir, file)
85+
var userRW os.FileMode = 0o600
86+
if err := os.WriteFile(tmpPath, data, userRW); err != nil {
87+
panic(err)
88+
}
89+
return tmpPath
90+
}

pkg/setup/bootstrap.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package setup
22

33
import (
44
"context"
5+
"embed"
6+
"os"
57

68
apimachinerytypes "k8s.io/apimachinery/pkg/types"
79
"k8s.io/klog/v2"
@@ -13,10 +15,14 @@ import (
1315
"sigs.k8s.io/e2e-framework/pkg/types"
1416
"sigs.k8s.io/e2e-framework/support/kind"
1517

18+
"github.com/openmcp-project/openmcp-testing/internal"
1619
"github.com/openmcp-project/openmcp-testing/pkg/providers"
1720
"github.com/openmcp-project/openmcp-testing/pkg/resources"
1821
)
1922

23+
//go:embed config/*
24+
var configFS embed.FS
25+
2026
type OpenMCPSetup struct {
2127
Namespace string
2228
Operator OpenMCPOperatorSetup
@@ -36,28 +42,33 @@ type OpenMCPOperatorSetup struct {
3642

3743
// Bootstrap sets up a the minimum set of components of an openMCP installation
3844
func (s *OpenMCPSetup) Bootstrap(testenv env.Environment) error {
45+
kindConfig := internal.MustTmpFileFromEmbedFS(configFS, "config/kind-config.yaml")
46+
operatorTemplate := internal.MustTmpFileFromEmbedFS(configFS, "config/operator.yaml.tmpl")
3947
platformClusterName := envconf.RandomName("platform", 16)
4048
s.Operator.Namespace = s.Namespace
41-
testenv.Setup(createPlatformCluster(platformClusterName)).
49+
testenv.Setup(createPlatformCluster(platformClusterName, kindConfig)).
4250
Setup(envfuncs.CreateNamespace(s.Namespace)).
43-
Setup(s.installOpenMCPOperator()).
51+
Setup(s.installOpenMCPOperator(operatorTemplate)).
4452
Setup(s.installClusterProviders()).
4553
Setup(s.loadServiceProviderImages(platformClusterName)).
4654
Setup(s.installServiceProviders()).
4755
Setup(s.verifyEnvironment()).
48-
Finish(s.cleanup()).
56+
Finish(s.cleanup(kindConfig, operatorTemplate)).
4957
Finish(envfuncs.DestroyCluster(platformClusterName))
5058
return nil
5159
}
5260

53-
func createPlatformCluster(name string) types.EnvFunc {
61+
func createPlatformCluster(name string, kindConfig string) types.EnvFunc {
5462
klog.Info("create platform cluster...")
55-
return envfuncs.CreateClusterWithConfig(kind.NewProvider(), name, "../pkg/setup/kind/config.yaml")
63+
return envfuncs.CreateClusterWithConfig(kind.NewProvider(), name, kindConfig)
5664
}
5765

58-
func (s *OpenMCPSetup) cleanup() types.EnvFunc {
66+
func (s *OpenMCPSetup) cleanup(tmpFiles ...string) types.EnvFunc {
5967
return func(ctx context.Context, c *envconf.Config) (context.Context, error) {
6068
klog.Info("cleaning up environment...")
69+
for _, f := range tmpFiles {
70+
os.RemoveAll(f)
71+
}
6172
for _, sp := range s.ServiceProviders {
6273
if err := providers.DeleteServiceProvider(ctx, c, sp.Name, sp.WaitOpts...); err != nil {
6374
klog.Errorf("delete service provider failed: %v", err)
@@ -83,10 +94,10 @@ func (s *OpenMCPSetup) verifyEnvironment() types.EnvFunc {
8394
}
8495
}
8596

86-
func (s *OpenMCPSetup) installOpenMCPOperator() types.EnvFunc {
97+
func (s *OpenMCPSetup) installOpenMCPOperator(tmpl string) types.EnvFunc {
8798
return func(ctx context.Context, c *envconf.Config) (context.Context, error) {
8899
// apply openmcp operator manifests
89-
if _, err := resources.CreateObjectsFromTemplateFile(ctx, c, "../pkg/setup/templates/openmcp-operator.yaml.tmpl", s.Operator); err != nil {
100+
if _, err := resources.CreateObjectsFromTemplateFile(ctx, c, tmpl, s.Operator); err != nil {
90101
return ctx, err
91102
}
92103
// wait for deployment to be ready
File renamed without changes.

0 commit comments

Comments
 (0)