Skip to content

Commit 3f51764

Browse files
committed
add extra manifests
1 parent 758c9a3 commit 3f51764

File tree

2 files changed

+77
-55
lines changed

2 files changed

+77
-55
lines changed

cmd/manageDeploymentRepo.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import (
1717
)
1818

1919
const (
20-
FlagGitConfig = "git-config"
21-
FlagOcmConfig = "ocm-config"
22-
FlagKubeConfig = "kubeconfig"
20+
FlagGitConfig = "git-config"
21+
FlagOcmConfig = "ocm-config"
22+
FlagKubeConfig = "kubeconfig"
23+
FlagExtraManifestDir = "extra-manifest-dir"
2324
)
2425

2526
type LogWriter struct{}
@@ -69,6 +70,7 @@ openmcp-bootstrapper manageDeploymentRepo <configFile>`,
6970
targetCluster,
7071
cmd.Flag(FlagGitConfig).Value.String(),
7172
cmd.Flag(FlagOcmConfig).Value.String(),
73+
cmd.Flag(FlagExtraManifestDir).Value.String(),
7274
).Initialize(cmd.Context())
7375

7476
defer func() {
@@ -94,6 +96,11 @@ openmcp-bootstrapper manageDeploymentRepo <configFile>`,
9496
return fmt.Errorf("failed to apply custom resource definitions: %w", err)
9597
}
9698

99+
err = deploymentRepoManager.ApplyExtraManifests(cmd.Context())
100+
if err != nil {
101+
return fmt.Errorf("failed to apply extra manifests: %w", err)
102+
}
103+
97104
err = deploymentRepoManager.UpdateResourcesKustomization()
98105
if err != nil {
99106
return fmt.Errorf("failed to update resources kustomization: %w", err)
@@ -119,6 +126,7 @@ func init() {
119126
manageDeploymentRepoCmd.Flags().String(FlagOcmConfig, "", "ocm configuration file")
120127
manageDeploymentRepoCmd.Flags().String(FlagGitConfig, "", "Git configuration file")
121128
manageDeploymentRepoCmd.Flags().String(FlagKubeConfig, "", "Kubernetes configuration file")
129+
manageDeploymentRepoCmd.Flags().String(FlagExtraManifestDir, "", "Directory containing extra manifests to apply")
122130

123131
if err := manageDeploymentRepoCmd.MarkFlagRequired(FlagGitConfig); err != nil {
124132
panic(err)

internal/deployment-repo/deploymentRepoManager.go

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ const (
2626
FluxCDKustomizationControllerResourceName = "fluxcd-kustomize-controller"
2727
FluxCDHelmControllerResourceName = "fluxcd-helm-controller"
2828

29-
EnvsDirectoryName = "envs"
30-
ResourcesDirectoryName = "resources"
31-
OpenMCPDirectoryName = "openmcp"
32-
FluxCDDirectoryName = "fluxcd"
33-
CRDsDirectoryName = "crds"
29+
EnvsDirectoryName = "envs"
30+
ResourcesDirectoryName = "resources"
31+
OpenMCPDirectoryName = "openmcp"
32+
FluxCDDirectoryName = "fluxcd"
33+
CRDsDirectoryName = "crds"
34+
ExtraManifestsDirectory = "extra"
3435
)
3536

3637
// DeploymentRepoManager manages the deployment repository by applying templates and committing changes.
@@ -43,11 +44,15 @@ type DeploymentRepoManager struct {
4344
// +optional
4445
OcmConfigPath string
4546

47+
// Config is the bootstrapper configuration
4648
Config *config.BootstrapperConfig
4749

4850
// TargetCluster is the Kubernetes cluster to which the deployment will be applied
4951
TargetCluster *clusters.Cluster
5052

53+
// ExtraManifestDir is an optional directory containing extra manifests to be added to the deployment repository
54+
ExtraManifestDir string
55+
5156
// Internals
5257
// workDir is a temporary directory used for processing
5358
workDir string
@@ -69,16 +74,18 @@ type DeploymentRepoManager struct {
6974
// fluxcdCV is the component version of the fluxcd source controller component
7075
fluxcdCV *ocmcli.ComponentVersion
7176
// crdFiles is a list of CRD files downloaded from the openmcp-operator component
72-
crdFiles []string
77+
crdFiles []string
78+
extraManifests []string
7379
}
7480

7581
// NewDeploymentRepoManager creates a new DeploymentRepoManager with the specified parameters.
76-
func NewDeploymentRepoManager(config *config.BootstrapperConfig, targetCluster *clusters.Cluster, gitConfigPath, ocmConfigPath string) *DeploymentRepoManager {
82+
func NewDeploymentRepoManager(config *config.BootstrapperConfig, targetCluster *clusters.Cluster, gitConfigPath, ocmConfigPath, extraManifestDir string) *DeploymentRepoManager {
7783
return &DeploymentRepoManager{
78-
Config: config,
79-
TargetCluster: targetCluster,
80-
GitConfigPath: gitConfigPath,
81-
OcmConfigPath: ocmConfigPath,
84+
Config: config,
85+
TargetCluster: targetCluster,
86+
GitConfigPath: gitConfigPath,
87+
OcmConfigPath: ocmConfigPath,
88+
ExtraManifestDir: extraManifestDir,
8289
}
8390
}
8491

@@ -243,39 +250,6 @@ func (m *DeploymentRepoManager) ApplyTemplates(ctx context.Context) error {
243250
return fmt.Errorf("failed to apply templates from directory %s: %w", m.templatesDir, err)
244251
}
245252

246-
/*
247-
workTree, err := m.gitRepo.Worktree()
248-
if err != nil {
249-
return fmt.Errorf("failed to get worktree: %w", err)
250-
}
251-
252-
workTreePath := filepath.Join(ResourcesDirectoryName, OpenMCPDirectoryName, "extra")
253-
254-
for _, manifest := range m.Config.OpenMCPOperator.Manifests {
255-
workTreeFile := filepath.Join(workTreePath, manifest.Name+".yaml")
256-
logger.Infof("Applying openmcp-operator manifest %s to deployment repository", manifest.Name)
257-
258-
manifestRaw, err := yaml.Marshal(manifest.ManifestParsed)
259-
if err != nil {
260-
return fmt.Errorf("failed to marshal openmcp-operator manifest %s: %w", manifest.Name, err)
261-
}
262-
263-
err = os.MkdirAll(filepath.Join(m.gitRepoDir, workTreePath), 0755)
264-
if err != nil {
265-
return fmt.Errorf("failed to create directory %s in deployment repository: %w", workTreePath, err)
266-
}
267-
268-
err = os.WriteFile(filepath.Join(m.gitRepoDir, workTreeFile), manifestRaw, 0o644)
269-
if err != nil {
270-
return fmt.Errorf("failed to write openmcp-operator manifest %s to deployment repository: %w", manifest.Name, err)
271-
}
272-
_, err = workTree.Add(workTreePath)
273-
if err != nil {
274-
return fmt.Errorf("failed to add openmcp-operator manifest %s to git index: %w", manifest.Name, err)
275-
}
276-
}
277-
*/
278-
279253
return nil
280254
}
281255

@@ -378,15 +352,57 @@ func (m *DeploymentRepoManager) ApplyCustomResourceDefinitions(ctx context.Conte
378352
return nil
379353
}
380354

355+
// ApplyExtraManifests copies extra manifests from the specified directory to the deployment repository and stages them for commit.
356+
func (m *DeploymentRepoManager) ApplyExtraManifests(_ context.Context) error {
357+
logger := log.GetLogger()
358+
if len(m.ExtraManifestDir) == 0 {
359+
logger.Infof("No extra manifest directory specified, skipping")
360+
return nil
361+
}
362+
363+
// if an extra manifest directory is specified, copy its contents to the deployment repository
364+
logger.Infof("Applying extra manifests from %s to deployment repository", m.ExtraManifestDir)
365+
err := util.CopyDir(m.ExtraManifestDir, filepath.Join(m.gitRepoDir, ResourcesDirectoryName, OpenMCPDirectoryName, ExtraManifestsDirectory))
366+
if err != nil {
367+
return fmt.Errorf("failed to copy extra manifests from %s to deployment repository: %w", m.ExtraManifestDir, err)
368+
}
369+
workTree, err := m.gitRepo.Worktree()
370+
if err != nil {
371+
return fmt.Errorf("failed to get worktree: %w", err)
372+
}
373+
_, err = workTree.Add(filepath.Join(ResourcesDirectoryName, OpenMCPDirectoryName, ExtraManifestsDirectory))
374+
if err != nil {
375+
return fmt.Errorf("failed to add extra manifests to git index: %w", err)
376+
}
377+
378+
entries, err := os.ReadDir(m.ExtraManifestDir)
379+
if err != nil {
380+
return fmt.Errorf("failed to read extra manifest directory: %w", err)
381+
}
382+
383+
m.extraManifests = make([]string, 0)
384+
for _, entry := range entries {
385+
if !entry.IsDir() {
386+
fileName := entry.Name()
387+
// Check if file has .yaml or .yml extension
388+
if filepath.Ext(fileName) == ".yaml" || filepath.Ext(fileName) == ".yml" {
389+
m.extraManifests = append(m.extraManifests, fileName)
390+
logger.Tracef("Added extra manifest: %s", fileName)
391+
}
392+
}
393+
}
394+
395+
return nil
396+
}
397+
381398
func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
382399
logger := log.GetLogger()
383400
files := make([]string, 0,
384401
len(m.Config.Providers.ClusterProviders)+
385402
len(m.Config.Providers.ServiceProviders)+
386403
len(m.Config.Providers.PlatformServices)+
387-
len(m.crdFiles))
388-
389-
// len(m.Config.OpenMCPOperator.Manifests))
404+
len(m.crdFiles)+
405+
len(m.extraManifests))
390406

391407
for _, crdFile := range m.crdFiles {
392408
files = append(files, filepath.Join(CRDsDirectoryName, filepath.Base(crdFile)))
@@ -404,11 +420,9 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
404420
files = append(files, filepath.Join("platform-services", platformService+".yaml"))
405421
}
406422

407-
/*
408-
for _, manifest := range m.Config.OpenMCPOperator.Manifests {
409-
files = append(files, filepath.Join("extra", manifest.Name+".yaml"))
410-
}
411-
*/
423+
for _, manifest := range m.extraManifests {
424+
files = append(files, filepath.Join(ExtraManifestsDirectory, filepath.Base(manifest)))
425+
}
412426

413427
// open resources root customization
414428
resourcesRootKustomizationPath := filepath.Join(ResourcesDirectoryName, OpenMCPDirectoryName, "kustomization.yaml")

0 commit comments

Comments
 (0)