@@ -58,13 +58,15 @@ func NewFluxDeployer(componentLocation, deploymentTemplates, deploymentRepositor
5858
5959func (d * FluxDeployer ) Deploy (ctx context.Context ) error {
6060
61- // Build helper object to get root component and templates component.
61+ // Get root component and gitops-templates component.
62+ d .log .Info ("Loading root component and gitops-templates component" )
6263 componentGetter := ocmcli .NewComponentGetter (d .componentLocation , d .deploymentTemplates , d .ocmConfig )
6364 if err := componentGetter .InitializeComponents (ctx ); err != nil {
6465 return err
6566 }
6667
6768 // Create a temporary directory to store the downloaded resource
69+ d .log .Info ("Creating download directory for gitops-templates" )
6870 downloadDir , err := os .MkdirTemp ("" , "flux-resource-" )
6971 if err != nil {
7072 return fmt .Errorf ("error creating temporary download directory for flux resource: %w" , err )
@@ -74,9 +76,10 @@ func (d *FluxDeployer) Deploy(ctx context.Context) error {
7476 fmt .Printf ("error removing temporary download directory for flux resource: %v\n " , err )
7577 }
7678 }()
77- fmt . Println ( "created temporary download directory:" , downloadDir )
79+ d . log . Debugf ( "Download directory: %s " , downloadDir )
7880
79- // Download resource from templates component into the download directory
81+ // Download resource from gitops-templates component into the download directory
82+ d .log .Info ("Downloading gitops-templates" )
8083 if err := componentGetter .DownloadTemplatesResource (ctx , downloadDir ); err != nil {
8184 return fmt .Errorf ("error downloading templates: %w" , err )
8285 }
@@ -86,13 +89,14 @@ func (d *FluxDeployer) Deploy(ctx context.Context) error {
8689 }
8790
8891 if err := d .establishFluxSync (ctx , downloadDir ); err != nil {
89- return fmt .Errorf ("error establishing flux sync : %w" , err )
92+ return fmt .Errorf ("error establishing flux synchronization : %w" , err )
9093 }
9194
9295 return nil
9396}
9497
9598func (d * FluxDeployer ) DeployFluxControllers (ctx context.Context , rootComponentVersion * ocmcli.ComponentVersion , downloadDir string ) error {
99+ d .log .Info ("Deploying flux" )
96100
97101 images , err := GetFluxCDImages (rootComponentVersion )
98102 if err != nil {
@@ -101,9 +105,10 @@ func (d *FluxDeployer) DeployFluxControllers(ctx context.Context, rootComponentV
101105
102106 // Read manifest file
103107 filepath := path .Join (downloadDir , "resources" , "gotk-components.yaml" )
108+ d .log .Debugf ("Reading flux deployment objects from file %s" , filepath )
104109 manifestTpl , err := d .readFileContent (filepath )
105110 if err != nil {
106- return fmt .Errorf ("error reading manifests for flux controllers : %w" , err )
111+ return fmt .Errorf ("error reading flux deployment objects from file %s : %w" , filepath , err )
107112 }
108113
109114 // Template
@@ -113,12 +118,14 @@ func (d *FluxDeployer) DeployFluxControllers(ctx context.Context, rootComponentV
113118 "images" : images ,
114119 },
115120 }
116- manifest , err := template .NewTemplateExecution ().Execute ("syncManifest" , string (manifestTpl ), values )
121+ d .log .Debug ("Templating flux deployment objects" )
122+ manifest , err := template .NewTemplateExecution ().Execute ("flux-deployment" , string (manifestTpl ), values )
117123 if err != nil {
118- return fmt .Errorf ("error templating flux sync manifest : %w" , err )
124+ return fmt .Errorf ("error templating flux deployment objects : %w" , err )
119125 }
120126
121127 // Apply
128+ d .log .Debug ("Applying flux deployment objects" )
122129 if err := d .applyManifests (ctx , manifest ); err != nil {
123130 return err
124131 }
@@ -127,20 +134,24 @@ func (d *FluxDeployer) DeployFluxControllers(ctx context.Context, rootComponentV
127134}
128135
129136func (d * FluxDeployer ) establishFluxSync (ctx context.Context , downloadDir string ) error {
137+ d .log .Info ("Establishing flux synchronization with deployment repository" )
138+
130139 const secretName = "git"
131140
132- if err := CreateGitCredentialsSecret (ctx , d .gitCredentials , secretName , d .fluxcdNamespace , d .platformCluster .Client ()); err != nil {
141+ if err := CreateGitCredentialsSecret (ctx , d .log , d . gitCredentials , secretName , d .fluxcdNamespace , d .platformCluster .Client ()); err != nil {
133142 return err
134143 }
135144
136145 // Read manifest file
137146 filepath := path .Join (downloadDir , "resources" , "gotk-sync.yaml" )
147+ d .log .Debugf ("Reading flux synchronization objects from file %s" , filepath )
138148 manifestTpl , err := d .readFileContent (filepath )
139149 if err != nil {
140150 return fmt .Errorf ("error reading manifests for flux sync: %w" , err )
141151 }
142152
143153 // Template
154+ d .log .Debug ("Templating flux synchronization objects" )
144155 values := map [string ]any {
145156 "Values" : map [string ]any {
146157 "namespace" : d .fluxcdNamespace ,
@@ -154,10 +165,11 @@ func (d *FluxDeployer) establishFluxSync(ctx context.Context, downloadDir string
154165 }
155166 manifest , err := template .NewTemplateExecution ().Execute ("flux-sync" , string (manifestTpl ), values )
156167 if err != nil {
157- return fmt .Errorf ("error templating manifests for flux sync : %w" , err )
168+ return fmt .Errorf ("error templating flux synchronization objects : %w" , err )
158169 }
159170
160171 // Apply
172+ d .log .Debug ("Applying flux synchronization objects" )
161173 if err := d .applyManifests (ctx , manifest ); err != nil {
162174 return err
163175 }
@@ -166,6 +178,8 @@ func (d *FluxDeployer) establishFluxSync(ctx context.Context, downloadDir string
166178}
167179
168180func (d * FluxDeployer ) readFileContent (filepath string ) ([]byte , error ) {
181+ d .log .Debugf ("Reading file: %s" , filepath )
182+
169183 if _ , err := os .Stat (filepath ); os .IsNotExist (err ) {
170184 return nil , fmt .Errorf ("file does not exist at path: %s" , filepath )
171185 }
0 commit comments