@@ -26,11 +26,12 @@ const (
2626 FluxCDKustomizationControllerResourceName = "fluxcd-kustomize-controller"
2727 FluxCDHelmControllerResourceName = "fluxcd-helm-controller"
2828
29- EnvsDirectoryName = "envs"
30- ResourcesDirectoryName = "resources"
31- OpenMCPDirectoryName = "openmcp"
32- FluxCDDirectoryName = "fluxcd"
33- CRDsDirectoryName = "crds"
29+ EnvsDirectoryName = "envs"
30+ ResourcesDirectoryName = "resources"
31+ OpenMCPDirectoryName = "openmcp"
32+ FluxCDDirectoryName = "fluxcd"
33+ CRDsDirectoryName = "crds"
34+ ExtraManifestsDirectory = "extra"
3435)
3536
3637// DeploymentRepoManager manages the deployment repository by applying templates and committing changes.
@@ -43,11 +44,15 @@ type DeploymentRepoManager struct {
4344 // +optional
4445 OcmConfigPath string
4546
47+ // Config is the bootstrapper configuration
4648 Config * config.BootstrapperConfig
4749
4850 // TargetCluster is the Kubernetes cluster to which the deployment will be applied
4951 TargetCluster * clusters.Cluster
5052
53+ // ExtraManifestDir is an optional directory containing extra manifests to be added to the deployment repository
54+ ExtraManifestDir string
55+
5156 // Internals
5257 // workDir is a temporary directory used for processing
5358 workDir string
@@ -69,16 +74,18 @@ type DeploymentRepoManager struct {
6974 // fluxcdCV is the component version of the fluxcd source controller component
7075 fluxcdCV * ocmcli.ComponentVersion
7176 // crdFiles is a list of CRD files downloaded from the openmcp-operator component
72- crdFiles []string
77+ crdFiles []string
78+ extraManifests []string
7379}
7480
7581// NewDeploymentRepoManager creates a new DeploymentRepoManager with the specified parameters.
76- func NewDeploymentRepoManager (config * config.BootstrapperConfig , targetCluster * clusters.Cluster , gitConfigPath , ocmConfigPath string ) * DeploymentRepoManager {
82+ func NewDeploymentRepoManager (config * config.BootstrapperConfig , targetCluster * clusters.Cluster , gitConfigPath , ocmConfigPath , extraManifestDir string ) * DeploymentRepoManager {
7783 return & DeploymentRepoManager {
78- Config : config ,
79- TargetCluster : targetCluster ,
80- GitConfigPath : gitConfigPath ,
81- OcmConfigPath : ocmConfigPath ,
84+ Config : config ,
85+ TargetCluster : targetCluster ,
86+ GitConfigPath : gitConfigPath ,
87+ OcmConfigPath : ocmConfigPath ,
88+ ExtraManifestDir : extraManifestDir ,
8289 }
8390}
8491
@@ -243,39 +250,6 @@ func (m *DeploymentRepoManager) ApplyTemplates(ctx context.Context) error {
243250 return fmt .Errorf ("failed to apply templates from directory %s: %w" , m .templatesDir , err )
244251 }
245252
246- /*
247- workTree, err := m.gitRepo.Worktree()
248- if err != nil {
249- return fmt.Errorf("failed to get worktree: %w", err)
250- }
251-
252- workTreePath := filepath.Join(ResourcesDirectoryName, OpenMCPDirectoryName, "extra")
253-
254- for _, manifest := range m.Config.OpenMCPOperator.Manifests {
255- workTreeFile := filepath.Join(workTreePath, manifest.Name+".yaml")
256- logger.Infof("Applying openmcp-operator manifest %s to deployment repository", manifest.Name)
257-
258- manifestRaw, err := yaml.Marshal(manifest.ManifestParsed)
259- if err != nil {
260- return fmt.Errorf("failed to marshal openmcp-operator manifest %s: %w", manifest.Name, err)
261- }
262-
263- err = os.MkdirAll(filepath.Join(m.gitRepoDir, workTreePath), 0755)
264- if err != nil {
265- return fmt.Errorf("failed to create directory %s in deployment repository: %w", workTreePath, err)
266- }
267-
268- err = os.WriteFile(filepath.Join(m.gitRepoDir, workTreeFile), manifestRaw, 0o644)
269- if err != nil {
270- return fmt.Errorf("failed to write openmcp-operator manifest %s to deployment repository: %w", manifest.Name, err)
271- }
272- _, err = workTree.Add(workTreePath)
273- if err != nil {
274- return fmt.Errorf("failed to add openmcp-operator manifest %s to git index: %w", manifest.Name, err)
275- }
276- }
277- */
278-
279253 return nil
280254}
281255
@@ -378,15 +352,57 @@ func (m *DeploymentRepoManager) ApplyCustomResourceDefinitions(ctx context.Conte
378352 return nil
379353}
380354
355+ // ApplyExtraManifests copies extra manifests from the specified directory to the deployment repository and stages them for commit.
356+ func (m * DeploymentRepoManager ) ApplyExtraManifests (_ context.Context ) error {
357+ logger := log .GetLogger ()
358+ if len (m .ExtraManifestDir ) == 0 {
359+ logger .Infof ("No extra manifest directory specified, skipping" )
360+ return nil
361+ }
362+
363+ // if an extra manifest directory is specified, copy its contents to the deployment repository
364+ logger .Infof ("Applying extra manifests from %s to deployment repository" , m .ExtraManifestDir )
365+ err := util .CopyDir (m .ExtraManifestDir , filepath .Join (m .gitRepoDir , ResourcesDirectoryName , OpenMCPDirectoryName , ExtraManifestsDirectory ))
366+ if err != nil {
367+ return fmt .Errorf ("failed to copy extra manifests from %s to deployment repository: %w" , m .ExtraManifestDir , err )
368+ }
369+ workTree , err := m .gitRepo .Worktree ()
370+ if err != nil {
371+ return fmt .Errorf ("failed to get worktree: %w" , err )
372+ }
373+ _ , err = workTree .Add (filepath .Join (ResourcesDirectoryName , OpenMCPDirectoryName , ExtraManifestsDirectory ))
374+ if err != nil {
375+ return fmt .Errorf ("failed to add extra manifests to git index: %w" , err )
376+ }
377+
378+ entries , err := os .ReadDir (m .ExtraManifestDir )
379+ if err != nil {
380+ return fmt .Errorf ("failed to read extra manifest directory: %w" , err )
381+ }
382+
383+ m .extraManifests = make ([]string , 0 )
384+ for _ , entry := range entries {
385+ if ! entry .IsDir () {
386+ fileName := entry .Name ()
387+ // Check if file has .yaml or .yml extension
388+ if filepath .Ext (fileName ) == ".yaml" || filepath .Ext (fileName ) == ".yml" {
389+ m .extraManifests = append (m .extraManifests , fileName )
390+ logger .Tracef ("Added extra manifest: %s" , fileName )
391+ }
392+ }
393+ }
394+
395+ return nil
396+ }
397+
381398func (m * DeploymentRepoManager ) UpdateResourcesKustomization () error {
382399 logger := log .GetLogger ()
383400 files := make ([]string , 0 ,
384401 len (m .Config .Providers .ClusterProviders )+
385402 len (m .Config .Providers .ServiceProviders )+
386403 len (m .Config .Providers .PlatformServices )+
387- len (m .crdFiles ))
388-
389- // len(m.Config.OpenMCPOperator.Manifests))
404+ len (m .crdFiles )+
405+ len (m .extraManifests ))
390406
391407 for _ , crdFile := range m .crdFiles {
392408 files = append (files , filepath .Join (CRDsDirectoryName , filepath .Base (crdFile )))
@@ -404,11 +420,9 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
404420 files = append (files , filepath .Join ("platform-services" , platformService + ".yaml" ))
405421 }
406422
407- /*
408- for _, manifest := range m.Config.OpenMCPOperator.Manifests {
409- files = append(files, filepath.Join("extra", manifest.Name+".yaml"))
410- }
411- */
423+ for _ , manifest := range m .extraManifests {
424+ files = append (files , filepath .Join (ExtraManifestsDirectory , filepath .Base (manifest )))
425+ }
412426
413427 // open resources root customization
414428 resourcesRootKustomizationPath := filepath .Join (ResourcesDirectoryName , OpenMCPDirectoryName , "kustomization.yaml" )
0 commit comments