|
9 | 9 |
|
10 | 10 | "github.com/openmcp-project/controller-utils/pkg/clusters" |
11 | 11 | "github.com/sirupsen/logrus" |
| 12 | + "sigs.k8s.io/kustomize/api/krusty" |
| 13 | + "sigs.k8s.io/kustomize/kyaml/filesys" |
12 | 14 |
|
13 | 15 | cfg "github.com/openmcp-project/bootstrapper/internal/config" |
14 | 16 | ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli" |
@@ -133,7 +135,7 @@ func (d *FluxDeployer) Deploy(ctx context.Context) (err error) { |
133 | 135 |
|
134 | 136 | // Kustomize |
135 | 137 | fluxCDEnvDir := filepath.Join(d.repoDir, EnvsDirectoryName, d.Config.Environment, FluxCDDirectoryName) |
136 | | - manifests, err := Kustomize(fluxCDEnvDir) |
| 138 | + manifests, err := d.Kustomize(fluxCDEnvDir) |
137 | 139 | if err != nil { |
138 | 140 | return fmt.Errorf("error kustomizing templated files: %w", err) |
139 | 141 | } |
@@ -246,6 +248,26 @@ func applyFluxCDTemplateInput(templateInput map[string]interface{}, fluxcdCV *oc |
246 | 248 | return nil |
247 | 249 | } |
248 | 250 |
|
| 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 | + |
249 | 271 | func (d *FluxDeployer) DeployFluxControllers(ctx context.Context, rootComponentVersion *ocmcli.ComponentVersion, downloadDir string) error { |
250 | 272 | d.log.Info("Deploying flux") |
251 | 273 |
|
|
0 commit comments