@@ -18,35 +18,55 @@ const (
1818 openMCPOperatorComponentName = "openmcp-operator"
1919)
2020
21- type GitLogWriter struct {}
22-
23- func (w GitLogWriter ) Write (p []byte ) (n int , err error ) {
24- logger := log .GetLogger ()
25- logger .Debugf ("Git progress: %s" , string (p ))
26- return len (p ), nil
27- }
28-
21+ // DeploymentRepoManager manages the deployment repository by applying templates and committing changes.
2922type DeploymentRepoManager struct {
30- ComponentLocation string
31- TemplateResourceLocation string
32- DeploymentRepository string
23+ // Vars set via constructor or "With" methods
24+
25+ // ComponentLocation is the location of the OCM component to use for deployment
26+ ComponentLocation string
27+ // TemplateResourceLocation is the location of the templates resource within the component or its references
28+ TemplateResourceLocation string
29+ // DeploymentRepository is the URL of the Git repository to manage
30+ DeploymentRepository string
31+ // DeploymentRepositoryBranch is the branch of the Git repository to manage
3332 DeploymentRepositoryBranch string
34- GitConfigPath string
35- OcmConfigPath string
36- ClusterProviders []string
37- ServiceProviders []string
38- PlatformServices []string
39- ImagePullSecrets []string
40-
41- tempDir string
33+ // GitConfigPath is the path to the Git configuration file
34+ GitConfigPath string
35+ // OcmConfigPath is the path to the OCM configuration file
36+ // +optional
37+ OcmConfigPath string
38+ // ClusterProviders is a list of cluster providers to include in the deployment
39+ // +optional
40+ ClusterProviders []string
41+ // ServiceProviders is a list of service providers to include in the deployment
42+ // +optional
43+ ServiceProviders []string
44+ // PlatformServices is a list of platform services to include in the deployment
45+ // +optional
46+ PlatformServices []string
47+ // ImagePullSecrets is a list of image pull secrets to include in the deployment
48+ // +optional
49+ ImagePullSecrets []string
50+
51+ // Internals
52+ // tempDir is a temporary directory used for processing
53+ tempDir string
54+ // templatesDir is the directory into which the templates resource are downloaded
55+ // (a subdirectory of tempDir)
4256 templatesDir string
43- gitRepoDir string
57+ // gitRepoDir is the directory into which the deployment repository is cloned
58+ // (a subdirectory of tempDir)
59+ gitRepoDir string
4460
61+ // compGetter is the OCM component getter used to fetch components and resources
4562 compGetter * ocmcli.ComponentGetter
46- gitConfig * gitconfig.Config
47- gitRepo * git.Repository
63+ // gitConfig is the parsed Git configuration
64+ gitConfig * gitconfig.Config
65+ // gitRepo is the cloned Git repository
66+ gitRepo * git.Repository
4867}
4968
69+ // NewDeploymentRepoManager creates a new DeploymentRepoManager with the specified parameters.
5070func NewDeploymentRepoManager (componentLocation , templateResourceLocation , deploymentRepository , deploymentRepositoryBranch , gitConfigPath string ) * DeploymentRepoManager {
5171 return & DeploymentRepoManager {
5272 ComponentLocation : componentLocation ,
@@ -57,31 +77,37 @@ func NewDeploymentRepoManager(componentLocation, templateResourceLocation, deplo
5777 }
5878}
5979
80+ // WithOcmConfig sets the OCM configuration file path.
6081func (m * DeploymentRepoManager ) WithOcmConfig (ocmConfigPath string ) * DeploymentRepoManager {
6182 m .OcmConfigPath = ocmConfigPath
6283 return m
6384}
6485
86+ // WithClusterProviders sets the list of cluster providers to include in the deployment.
6587func (m * DeploymentRepoManager ) WithClusterProviders (clusterProviders []string ) * DeploymentRepoManager {
6688 m .ClusterProviders = clusterProviders
6789 return m
6890}
6991
92+ // WithServiceProviders sets the list of service providers to include in the deployment.
7093func (m * DeploymentRepoManager ) WithServiceProviders (serviceProviders []string ) * DeploymentRepoManager {
7194 m .ServiceProviders = serviceProviders
7295 return m
7396}
7497
98+ // WithPlatformServices sets the list of platform services to include in the deployment.
7599func (m * DeploymentRepoManager ) WithPlatformServices (platformServices []string ) * DeploymentRepoManager {
76100 m .PlatformServices = platformServices
77101 return m
78102}
79103
104+ // WithImagePullSecrets sets the list of image pull secrets to include in the deployment.
80105func (m * DeploymentRepoManager ) WithImagePullSecrets (imagePullSecrets []string ) * DeploymentRepoManager {
81106 m .ImagePullSecrets = imagePullSecrets
82107 return m
83108}
84109
110+ // Complete initializes the DeploymentRepoManager by setting up temporary directories, downloading components and templates, and cloning the deployment repository.
85111func (m * DeploymentRepoManager ) Complete (ctx context.Context ) (* DeploymentRepoManager , error ) {
86112 var err error
87113
@@ -134,14 +160,6 @@ func (m *DeploymentRepoManager) Complete(ctx context.Context) (*DeploymentRepoMa
134160 return m , fmt .Errorf ("invalid git config: %w" , err )
135161 }
136162
137- cloneOptions := & git.CloneOptions {
138- URL : m .DeploymentRepository ,
139- Progress : GitLogWriter {},
140- }
141- if err = m .gitConfig .ConfigureCloneOptions (cloneOptions ); err != nil {
142- return m , fmt .Errorf ("failed to configure git clone options: %w" , err )
143- }
144-
145163 logger .Infof ("Cloning deployment repository %s" , m .DeploymentRepository )
146164
147165 m .gitRepo , err = CloneRepo (m .DeploymentRepository , m .gitRepoDir , m .gitConfig )
@@ -159,6 +177,7 @@ func (m *DeploymentRepoManager) Complete(ctx context.Context) (*DeploymentRepoMa
159177 return m , nil
160178}
161179
180+ // Cleanup removes temporary directories created during processing.
162181func (m * DeploymentRepoManager ) Cleanup () {
163182 if m .tempDir != "" {
164183 log .GetLogger ().Tracef ("Removing temp dir: %s" , m .tempDir )
@@ -168,6 +187,7 @@ func (m *DeploymentRepoManager) Cleanup() {
168187 }
169188}
170189
190+ // ApplyTemplates applies the templates from the templates directory to the deployment repository.
171191func (m * DeploymentRepoManager ) ApplyTemplates (ctx context.Context ) error {
172192 logger := log .GetLogger ()
173193
@@ -199,6 +219,7 @@ func (m *DeploymentRepoManager) ApplyTemplates(ctx context.Context) error {
199219 return nil
200220}
201221
222+ // ApplyProviders applies the specified providers to the deployment repository.
202223func (m * DeploymentRepoManager ) ApplyProviders (ctx context.Context ) error {
203224 logger := log .GetLogger ()
204225
@@ -213,6 +234,8 @@ func (m *DeploymentRepoManager) ApplyProviders(ctx context.Context) error {
213234 return nil
214235}
215236
237+ // CommitAndPushChanges commits all changes in the deployment repository and pushes them to the remote repository.
238+ // If there are no changes to commit, it does nothing.
216239func (m * DeploymentRepoManager ) CommitAndPushChanges (_ context.Context ) error {
217240 logger := log .GetLogger ()
218241
0 commit comments