Skip to content

Commit 6e09a0b

Browse files
committed
feat: deploy flux command
1 parent ad3fab1 commit 6e09a0b

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

internal/flux_deployer/deployer.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/openmcp-project/controller-utils/pkg/clusters"
1111
"github.com/sirupsen/logrus"
12+
"sigs.k8s.io/kustomize/api/krusty"
13+
"sigs.k8s.io/kustomize/kyaml/filesys"
1214

1315
cfg "github.com/openmcp-project/bootstrapper/internal/config"
1416
ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
@@ -133,7 +135,7 @@ func (d *FluxDeployer) Deploy(ctx context.Context) (err error) {
133135

134136
// Kustomize
135137
fluxCDEnvDir := filepath.Join(d.repoDir, EnvsDirectoryName, d.Config.Environment, FluxCDDirectoryName)
136-
manifests, err := Kustomize(fluxCDEnvDir)
138+
manifests, err := d.Kustomize(fluxCDEnvDir)
137139
if err != nil {
138140
return fmt.Errorf("error kustomizing templated files: %w", err)
139141
}
@@ -246,6 +248,26 @@ func applyFluxCDTemplateInput(templateInput map[string]interface{}, fluxcdCV *oc
246248
return nil
247249
}
248250

251+
// Kustomize runs kustomize on the given directory and returns the resulting yaml as a byte slice.
252+
func (d *FluxDeployer) Kustomize(dir string) ([]byte, error) {
253+
d.log.Info("Kustomizing files in directory: %s", dir)
254+
fs := filesys.MakeFsOnDisk()
255+
opts := krusty.MakeDefaultOptions()
256+
kustomizer := krusty.MakeKustomizer(opts)
257+
258+
resourceMap, err := kustomizer.Run(fs, dir)
259+
if err != nil {
260+
return nil, fmt.Errorf("error running kustomization: %w", err)
261+
}
262+
263+
resourcesYaml, err := resourceMap.AsYaml()
264+
if err != nil {
265+
return nil, fmt.Errorf("error converting resources to yaml: %w", err)
266+
}
267+
268+
return resourcesYaml, nil
269+
}
270+
249271
func (d *FluxDeployer) DeployFluxControllers(ctx context.Context, rootComponentVersion *ocmcli.ComponentVersion, downloadDir string) error {
250272
d.log.Info("Deploying flux")
251273

internal/flux_deployer/kustomize.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)