@@ -12,24 +12,13 @@ import (
1212 "sigs.k8s.io/kustomize/api/krusty"
1313 "sigs.k8s.io/kustomize/kyaml/filesys"
1414
15+ "github.com/openmcp-project/bootstrapper/internal/common"
1516 cfg "github.com/openmcp-project/bootstrapper/internal/config"
1617 ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
1718 "github.com/openmcp-project/bootstrapper/internal/template"
1819 "github.com/openmcp-project/bootstrapper/internal/util"
1920)
2021
21- const (
22- EnvsDirectoryName = "envs"
23- FluxCDDirectoryName = "fluxcd"
24- ResourcesDirectoryName = "resources"
25- TemplatesDirectoryName = "templates"
26- OverlaysDirectoryName = "overlays"
27-
28- FluxCDSourceControllerResourceName = "fluxcd-source-controller"
29- FluxCDKustomizationControllerResourceName = "fluxcd-kustomize-controller"
30- FluxCDHelmControllerResourceName = "fluxcd-helm-controller"
31- )
32-
3322type FluxDeployer struct {
3423 Config * cfg.BootstrapperConfig
3524
@@ -115,7 +104,7 @@ func (d *FluxDeployer) Deploy(ctx context.Context) (err error) {
115104 return err
116105 }
117106
118- d .fluxcdCV , err = componentGetter .GetComponentVersionForResourceRecursive (ctx , componentGetter .RootComponentVersion (), FluxCDSourceControllerResourceName )
107+ d .fluxcdCV , err = componentGetter .GetComponentVersionForResourceRecursive (ctx , componentGetter .RootComponentVersion (), common . FluxCDSourceControllerResourceName )
119108 if err != nil {
120109 return fmt .Errorf ("failed to get fluxcd source controller component version: %w" , err )
121110 }
@@ -137,7 +126,7 @@ func (d *FluxDeployer) Deploy(ctx context.Context) (err error) {
137126 }
138127
139128 // Kustomize <workdir>/repo/envs/<envName>/fluxcd
140- fluxCDEnvDir := filepath .Join (d .repoDir , EnvsDirectoryName , d .Config .Environment , FluxCDDirectoryName )
129+ fluxCDEnvDir := filepath .Join (d .repoDir , common . EnvsDirectoryName , d .Config .Environment , common . FluxCDDirectoryName )
141130 manifests , err := d .Kustomize (fluxCDEnvDir )
142131 if err != nil {
143132 return fmt .Errorf ("error kustomizing templated files: %w" , err )
@@ -157,14 +146,14 @@ func (d *FluxDeployer) ArrangeTemplates() (err error) {
157146 d .log .Info ("Arranging template files" )
158147
159148 // Create directory <templatesDir>/envs/<envName>/fluxcd
160- fluxCDEnvDir := filepath .Join (d .templatesDir , EnvsDirectoryName , d .Config .Environment , FluxCDDirectoryName )
149+ fluxCDEnvDir := filepath .Join (d .templatesDir , common . EnvsDirectoryName , d .Config .Environment , common . FluxCDDirectoryName )
161150 err = os .MkdirAll (fluxCDEnvDir , 0755 )
162151 if err != nil {
163152 return fmt .Errorf ("failed to create fluxcd environment directory: %w" , err )
164153 }
165154
166155 // Create directory <templatesDir>/resources/fluxcd
167- fluxCDResourcesDir := filepath .Join (d .templatesDir , ResourcesDirectoryName , FluxCDDirectoryName )
156+ fluxCDResourcesDir := filepath .Join (d .templatesDir , common . ResourcesDirectoryName , common . FluxCDDirectoryName )
168157 err = os .MkdirAll (fluxCDResourcesDir , 0755 )
169158 if err != nil {
170159 return fmt .Errorf ("failed to create fluxcd resources directory: %w" , err )
@@ -173,13 +162,13 @@ func (d *FluxDeployer) ArrangeTemplates() (err error) {
173162 d .log .Debug ("Copying template files to target directories" )
174163
175164 // copy all files from <downloadDir>/templates/overlays to <templatesDir>/envs/<envName>/fluxcd
176- err = util .CopyDir (filepath .Join (d .downloadDir , TemplatesDirectoryName , OverlaysDirectoryName ), fluxCDEnvDir )
165+ err = util .CopyDir (filepath .Join (d .downloadDir , common . TemplatesDirectoryName , common . OverlaysDirectoryName ), fluxCDEnvDir )
177166 if err != nil {
178167 return fmt .Errorf ("failed to copy fluxcd overlays: %w" , err )
179168 }
180169
181170 // copy all files from <downloadDir>/templates/resources to <templatesDir>/resources/fluxcd
182- err = util .CopyDir (filepath .Join (d .downloadDir , TemplatesDirectoryName , ResourcesDirectoryName ), fluxCDResourcesDir )
171+ err = util .CopyDir (filepath .Join (d .downloadDir , common . TemplatesDirectoryName , common . ResourcesDirectoryName ), fluxCDResourcesDir )
183172 if err != nil {
184173 return fmt .Errorf ("failed to copy fluxcd resources: %w" , err )
185174 }
@@ -192,23 +181,15 @@ func (d *FluxDeployer) ArrangeTemplates() (err error) {
192181// The resulting files are written to the repo directory.
193182func (d * FluxDeployer ) Template () (err error ) {
194183 d .log .Infof ("Applying templates from %s to deployment repository" , d .Config .Component .FluxcdTemplateResourcePath )
195- templateInput := template .NewTemplateInput ()
196-
197- templateInput .SetImagePullSecrets (d .Config .ImagePullSecrets )
198-
199- templateInput ["fluxCDEnvPath" ] = "./" + EnvsDirectoryName + "/" + d .Config .Environment + "/" + FluxCDDirectoryName
200- templateInput ["gitRepoEnvBranch" ] = d .Config .DeploymentRepository .RepoBranch
201- templateInput ["fluxCDResourcesPath" ] = "../../../" + ResourcesDirectoryName + "/" + FluxCDDirectoryName
202-
203- templateInput .SetGitRepo (d .Config .DeploymentRepository )
184+ templateInput := common .NewTemplateInputFromConfig (d .Config )
204185
205- if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDSourceControllerResourceName , "sourceController" ); err != nil {
186+ if err = templateInput .AddImageResource (d .fluxcdCV , common . FluxCDSourceControllerResourceName , "sourceController" ); err != nil {
206187 return fmt .Errorf ("failed to apply fluxcd source controller template input: %w" , err )
207188 }
208- if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDKustomizationControllerResourceName , "kustomizeController" ); err != nil {
189+ if err = templateInput .AddImageResource (d .fluxcdCV , common . FluxCDKustomizationControllerResourceName , "kustomizeController" ); err != nil {
209190 return fmt .Errorf ("failed to apply fluxcd kustomize controller template input: %w" , err )
210191 }
211- if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDHelmControllerResourceName , "helmController" ); err != nil {
192+ if err = templateInput .AddImageResource (d .fluxcdCV , common . FluxCDHelmControllerResourceName , "helmController" ); err != nil {
212193 return fmt .Errorf ("failed to apply fluxcd helm controller template input: %w" , err )
213194 }
214195
0 commit comments