44 "context"
55 "fmt"
66 "os"
7- "path"
87 "path/filepath"
98
109 "github.com/openmcp-project/controller-utils/pkg/clusters"
@@ -15,7 +14,6 @@ import (
1514
1615 cfg "github.com/openmcp-project/bootstrapper/internal/config"
1716 ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
18- "github.com/openmcp-project/bootstrapper/internal/template"
1917 "github.com/openmcp-project/bootstrapper/internal/util"
2018)
2119
@@ -51,6 +49,15 @@ func NewFluxDeployer(config *cfg.BootstrapperConfig, gitConfigPath, ocmConfigPat
5149}
5250
5351func (d * FluxDeployer ) Deploy (ctx context.Context ) (err error ) {
52+ componentManager , err := NewComponentManager (ctx , d .Config , d .OcmConfigPath )
53+ if err != nil {
54+ return fmt .Errorf ("error creating component manager: %w" , err )
55+ }
56+
57+ return d .DeployWithComponentManager (ctx , componentManager )
58+ }
59+
60+ func (d * FluxDeployer ) DeployWithComponentManager (ctx context.Context , componentManager ComponentManager ) (err error ) {
5461 d .log .Infof ("Ensure namespace %s exists" , d .fluxNamespace )
5562 namespaceMutator := resources .NewNamespaceMutator (d .fluxNamespace )
5663 if err := resources .CreateOrUpdateResource (ctx , d .platformCluster .Client (), namespaceMutator ); err != nil {
@@ -99,24 +106,15 @@ func (d *FluxDeployer) Deploy(ctx context.Context) (err error) {
99106 }
100107 d .log .Tracef ("Created repo directory: %s" , d .repoDir )
101108
102- // Get components
103- // - root component
104- // - gitops-templates component
105- // - that contains the image resources for fluxcd source controller component
106- d .log .Info ("Loading root component and gitops-templates component" )
107- componentGetter := ocmcli .NewComponentGetter (d .Config .Component .OpenMCPComponentLocation , d .Config .Component .FluxcdTemplateResourcePath , d .OcmConfigPath )
108- if err := componentGetter .InitializeComponents (ctx ); err != nil {
109- return err
110- }
111-
112- d .fluxcdCV , err = componentGetter .GetComponentVersionForResourceRecursive (ctx , componentGetter .RootComponentVersion (), FluxCDSourceControllerResourceName )
109+ // Get component which contains the fluxcd images as resources
110+ d .fluxcdCV , err = componentManager .GetComponentWithImageResources (ctx )
113111 if err != nil {
114112 return fmt .Errorf ("failed to get fluxcd source controller component version: %w" , err )
115113 }
116114
117115 // Download resource from gitops-templates component into the download directory
118- d .log .Info ("Downloading gitops- templates" )
119- if err := componentGetter .DownloadTemplatesResource (ctx , d .downloadDir ); err != nil {
116+ d .log .Info ("Downloading templates" )
117+ if err := componentManager .DownloadTemplatesResource (ctx , d .downloadDir ); err != nil {
120118 return fmt .Errorf ("error downloading templates: %w" , err )
121119 }
122120
@@ -197,8 +195,17 @@ func (d *FluxDeployer) Template() (err error) {
197195 if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDHelmControllerResourceName , "helmController" ); err != nil {
198196 return fmt .Errorf ("failed to apply fluxcd helm controller template input: %w" , err )
199197 }
198+ if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDNotificationControllerName , "notificationController" ); err != nil {
199+ return fmt .Errorf ("failed to apply fluxcd notification controller template input: %w" , err )
200+ }
201+ if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDImageReflectorControllerName , "imageReflectorController" ); err != nil {
202+ return fmt .Errorf ("failed to apply fluxcd image reflector controller template input: %w" , err )
203+ }
204+ if err = templateInput .AddImageResource (d .fluxcdCV , FluxCDImageAutomationControllerName , "imageAutomationController" ); err != nil {
205+ return fmt .Errorf ("failed to apply fluxcd image automation controller template input: %w" , err )
206+ }
200207
201- if err = TemplateDirectory (d .templatesDir , templateInput , d .repoDir , d .log ); err != nil {
208+ if err = TemplateDirectory (d .templatesDir , d .repoDir , templateInput , d .log ); err != nil {
202209 return fmt .Errorf ("failed to apply templates from directory %s: %w" , d .templatesDir , err )
203210 }
204211
@@ -224,56 +231,3 @@ func (d *FluxDeployer) Kustomize(dir string) ([]byte, error) {
224231
225232 return resourcesYaml , nil
226233}
227-
228- func (d * FluxDeployer ) DeployFluxControllers (ctx context.Context , rootComponentVersion * ocmcli.ComponentVersion , downloadDir string ) error {
229- d .log .Info ("Deploying flux" )
230-
231- images , err := GetFluxCDImages (rootComponentVersion )
232- if err != nil {
233- return fmt .Errorf ("error getting images for flux controllers: %w" , err )
234- }
235-
236- // Read manifest file
237- filepath := path .Join (downloadDir , "resources" , "gotk-components.yaml" )
238- d .log .Debugf ("Reading flux deployment objects from file %s" , filepath )
239- manifestTpl , err := d .readFileContent (filepath )
240- if err != nil {
241- return fmt .Errorf ("error reading flux deployment objects from file %s: %w" , filepath , err )
242- }
243-
244- // Template
245- values := map [string ]any {
246- "Values" : map [string ]any {
247- "namespace" : d .fluxNamespace ,
248- "images" : images ,
249- },
250- }
251- d .log .Debug ("Templating flux deployment objects" )
252- manifest , err := template .NewTemplateExecution ().Execute ("flux-deployment" , string (manifestTpl ), values )
253- if err != nil {
254- return fmt .Errorf ("error templating flux deployment objects: %w" , err )
255- }
256-
257- // Apply
258- d .log .Debug ("Applying flux deployment objects" )
259- if err := util .ApplyManifests (ctx , d .platformCluster , manifest ); err != nil {
260- return err
261- }
262-
263- return nil
264- }
265-
266- func (d * FluxDeployer ) readFileContent (filepath string ) ([]byte , error ) {
267- d .log .Debugf ("Reading file: %s" , filepath )
268-
269- if _ , err := os .Stat (filepath ); os .IsNotExist (err ) {
270- return nil , fmt .Errorf ("file does not exist at path: %s" , filepath )
271- }
272-
273- content , err := os .ReadFile (filepath )
274- if err != nil {
275- return nil , fmt .Errorf ("error reading file %s: %w" , filepath , err )
276- }
277-
278- return content , nil
279- }
0 commit comments