Skip to content

Commit b616fab

Browse files
committed
update
1 parent 214dc41 commit b616fab

File tree

3 files changed

+59
-46
lines changed

3 files changed

+59
-46
lines changed

internal/deployment-repo/deploymentRepoManager.go

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2922
type 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.
5070
func 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.
6081
func (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.
6587
func (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.
7093
func (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.
7599
func (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.
80105
func (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.
85111
func (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.
162181
func (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.
171191
func (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.
202223
func (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.
216239
func (m *DeploymentRepoManager) CommitAndPushChanges(_ context.Context) error {
217240
logger := log.GetLogger()
218241

internal/deployment-repo/repo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import (
1515
"github.com/openmcp-project/bootstrapper/internal/log"
1616
)
1717

18+
// gitProgressWriter is a writer that logs Git progress messages.
1819
type gitProgressWriter struct{}
1920

2021
func (w gitProgressWriter) Write(p []byte) (n int, err error) {
2122
logger := log.GetLogger()
22-
logger.Trace(string(p))
23+
logger.Debugf("[Git] %s", string(p))
2324
return len(p), nil
2425
}
2526

internal/deployment-repo/templater.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type ProviderOptions struct {
121121
ImagePullSecrets []string
122122
}
123123

124+
// TemplateProviders templates the specified cluster providers, service providers, and platform services
124125
func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders, platformServices, imagePullSecrets []string, ocmGetter *ocmcli.ComponentGetter, repo *git.Repository) error {
125126
for _, cp := range clusterProviders {
126127
componentVersion, err := ocmGetter.GetReferencedComponentVersion(ctx, "cluster-provider-"+cp)
@@ -139,7 +140,7 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
139140
ImagePullSecrets: imagePullSecrets,
140141
}
141142

142-
err = TemplateClusterProvider(opts, repo)
143+
err = templateProvider(opts, clusterProviderTemplate, "cluster-providers", repo)
143144
if err != nil {
144145
return fmt.Errorf("failed to apply cluster provider %s: %w", cp, err)
145146
}
@@ -162,7 +163,7 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
162163
ImagePullSecrets: imagePullSecrets,
163164
}
164165

165-
err = TemplateServiceProvider(opts, repo)
166+
err = templateProvider(opts, serviceProviderTemplate, "service-providers", repo)
166167
if err != nil {
167168
return fmt.Errorf("failed to apply service provider %s: %w", sp, err)
168169
}
@@ -185,7 +186,7 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
185186
ImagePullSecrets: imagePullSecrets,
186187
}
187188

188-
err = TemplatePlatformService(opts, repo)
189+
err = templateProvider(opts, platformServiceTemplate, "platform-services", repo)
189190
if err != nil {
190191
return fmt.Errorf("failed to apply platform service %s: %w", ps, err)
191192
}
@@ -204,18 +205,6 @@ func getImageResource(cv *ocmcli.ComponentVersion) (*ocmcli.Resource, error) {
204205
return nil, fmt.Errorf("image resource not found for component %s", cv.Component.Name)
205206
}
206207

207-
func TemplateClusterProvider(options *ProviderOptions, repo *git.Repository) error {
208-
return templateProvider(options, clusterProviderTemplate, "cluster-providers", repo)
209-
}
210-
211-
func TemplateServiceProvider(options *ProviderOptions, repo *git.Repository) error {
212-
return templateProvider(options, serviceProviderTemplate, "service-providers", repo)
213-
}
214-
215-
func TemplatePlatformService(options *ProviderOptions, repo *git.Repository) error {
216-
return templateProvider(options, platformServiceTemplate, "platform-services", repo)
217-
}
218-
219208
func templateProvider(options *ProviderOptions, templateSource, dir string, repo *git.Repository) error {
220209
logger := log.GetLogger()
221210
providerPath := filepath.Join(dir, options.Name+".yaml")

0 commit comments

Comments
 (0)