@@ -8,12 +8,7 @@ import (
88
99 "github.com/go-git/go-billy/v5"
1010 "github.com/go-git/go-git/v5"
11- "github.com/go-logr/logr"
1211 "github.com/openmcp-project/controller-utils/pkg/clusters"
13- "k8s.io/apimachinery/pkg/runtime"
14- controllerruntime "sigs.k8s.io/controller-runtime"
15- "sigs.k8s.io/yaml"
16-
1712 "sigs.k8s.io/kustomize/api/krusty"
1813 "sigs.k8s.io/kustomize/kyaml/filesys"
1914
@@ -48,6 +43,9 @@ type DeploymentRepoManager struct {
4843
4944 Config * DeploymentRepoConfig
5045
46+ // TargetCluster is the Kubernetes cluster to which the deployment will be applied
47+ TargetCluster * clusters.Cluster
48+
5149 // Internals
5250 // workDir is a temporary directory used for processing
5351 workDir string
@@ -70,14 +68,13 @@ type DeploymentRepoManager struct {
7068 fluxcdCV * ocmcli.ComponentVersion
7169 // crdFiles is a list of CRD files downloaded from the openmcp-operator component
7270 crdFiles []string
73- // targetCluster is the Kubernetes cluster to which the deployment will be applied
74- targetCluster * clusters.Cluster
7571}
7672
7773// NewDeploymentRepoManager creates a new DeploymentRepoManager with the specified parameters.
78- func NewDeploymentRepoManager (config * DeploymentRepoConfig , gitConfigPath , ocmConfigPath string ) * DeploymentRepoManager {
74+ func NewDeploymentRepoManager (config * DeploymentRepoConfig , targetCluster * clusters. Cluster , gitConfigPath , ocmConfigPath string ) * DeploymentRepoManager {
7975 return & DeploymentRepoManager {
8076 Config : config ,
77+ TargetCluster : targetCluster ,
8178 GitConfigPath : gitConfigPath ,
8279 OcmConfigPath : ocmConfigPath ,
8380 }
@@ -164,21 +161,6 @@ func (m *DeploymentRepoManager) Initialize(ctx context.Context) (*DeploymentRepo
164161 return m , fmt .Errorf ("failed to checkout or create branch %s: %w" , m .Config .DeploymentRepository .RepoBranch , err )
165162 }
166163
167- logger .Infof ("Creating kubernets client for target cluster from kubeconfig %s" , m .Config .TargetCluster .KubeconfigPath )
168-
169- // disable controller-runtime logging
170- controllerruntime .SetLogger (logr .Discard ())
171-
172- m .targetCluster = clusters .New ("platform" ).WithConfigPath (m .Config .TargetCluster .KubeconfigPath )
173- err = m .targetCluster .InitializeRESTConfig ()
174- if err != nil {
175- return m , fmt .Errorf ("failed to initialize target cluster REST config: %w" , err )
176- }
177- err = m .targetCluster .InitializeClient (runtime .NewScheme ())
178- if err != nil {
179- return m , fmt .Errorf ("failed to initialize target cluster client: %w" , err )
180- }
181-
182164 return m , nil
183165}
184166
@@ -259,36 +241,38 @@ func (m *DeploymentRepoManager) ApplyTemplates(ctx context.Context) error {
259241 return fmt .Errorf ("failed to apply templates from directory %s: %w" , m .templatesDir , err )
260242 }
261243
262- workTree , err := m .gitRepo .Worktree ()
263- if err != nil {
264- return fmt .Errorf ("failed to get worktree: %w" , err )
265- }
266-
267- workTreePath := filepath .Join (ResourcesDirectoryName , OpenMCPDirectoryName , "extra" )
268-
269- for _ , manifest := range m .Config .OpenMCPOperator .Manifests {
270- workTreeFile := filepath .Join (workTreePath , manifest .Name + ".yaml" )
271- logger .Infof ("Applying openmcp-operator manifest %s to deployment repository" , manifest .Name )
272-
273- manifestRaw , err := yaml .Marshal (manifest .ManifestParsed )
244+ /*
245+ workTree, err := m.gitRepo.Worktree()
274246 if err != nil {
275- return fmt .Errorf ("failed to marshal openmcp-operator manifest %s : %w" , manifest . Name , err )
247+ return fmt.Errorf("failed to get worktree : %w", err)
276248 }
277249
278- err = os .MkdirAll (filepath .Join (m .gitRepoDir , workTreePath ), 0755 )
279- if err != nil {
280- return fmt .Errorf ("failed to create directory %s in deployment repository: %w" , workTreePath , err )
281- }
282-
283- err = os .WriteFile (filepath .Join (m .gitRepoDir , workTreeFile ), manifestRaw , 0o644 )
284- if err != nil {
285- return fmt .Errorf ("failed to write openmcp-operator manifest %s to deployment repository: %w" , manifest .Name , err )
286- }
287- _ , err = workTree .Add (workTreePath )
288- if err != nil {
289- return fmt .Errorf ("failed to add openmcp-operator manifest %s to git index: %w" , manifest .Name , err )
290- }
291- }
250+ workTreePath := filepath.Join(ResourcesDirectoryName, OpenMCPDirectoryName, "extra")
251+
252+ for _, manifest := range m.Config.OpenMCPOperator.Manifests {
253+ workTreeFile := filepath.Join(workTreePath, manifest.Name+".yaml")
254+ logger.Infof("Applying openmcp-operator manifest %s to deployment repository", manifest.Name)
255+
256+ manifestRaw, err := yaml.Marshal(manifest.ManifestParsed)
257+ if err != nil {
258+ return fmt.Errorf("failed to marshal openmcp-operator manifest %s: %w", manifest.Name, err)
259+ }
260+
261+ err = os.MkdirAll(filepath.Join(m.gitRepoDir, workTreePath), 0755)
262+ if err != nil {
263+ return fmt.Errorf("failed to create directory %s in deployment repository: %w", workTreePath, err)
264+ }
265+
266+ err = os.WriteFile(filepath.Join(m.gitRepoDir, workTreeFile), manifestRaw, 0o644)
267+ if err != nil {
268+ return fmt.Errorf("failed to write openmcp-operator manifest %s to deployment repository: %w", manifest.Name, err)
269+ }
270+ _, err = workTree.Add(workTreePath)
271+ if err != nil {
272+ return fmt.Errorf("failed to add openmcp-operator manifest %s to git index: %w", manifest.Name, err)
273+ }
274+ }
275+ */
292276
293277 return nil
294278}
@@ -398,8 +382,9 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
398382 len (m .Config .Providers .ClusterProviders )+
399383 len (m .Config .Providers .ServiceProviders )+
400384 len (m .Config .Providers .PlatformServices )+
401- len (m .crdFiles )+
402- len (m .Config .OpenMCPOperator .Manifests ))
385+ len (m .crdFiles ))
386+
387+ //len(m.Config.OpenMCPOperator.Manifests))
403388
404389 for _ , crdFile := range m .crdFiles {
405390 files = append (files , filepath .Join (CRDsDirectoryName , filepath .Base (crdFile )))
@@ -417,9 +402,11 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
417402 files = append (files , filepath .Join ("platform-services" , platformService + ".yaml" ))
418403 }
419404
420- for _ , manifest := range m .Config .OpenMCPOperator .Manifests {
421- files = append (files , filepath .Join ("extra" , manifest .Name + ".yaml" ))
422- }
405+ /*
406+ for _, manifest := range m.Config.OpenMCPOperator.Manifests {
407+ files = append(files, filepath.Join("extra", manifest.Name+".yaml"))
408+ }
409+ */
423410
424411 // open resources root customization
425412 resourcesRootKustomizationPath := filepath .Join (ResourcesDirectoryName , OpenMCPDirectoryName , "kustomization.yaml" )
@@ -484,7 +471,7 @@ func (m *DeploymentRepoManager) RunKustomizeAndApply(ctx context.Context) error
484471 }
485472
486473 logger .Infof ("Applying kustomized resources to target cluster" )
487- err = util .ApplyManifests (ctx , m .targetCluster , resourcesYAML )
474+ err = util .ApplyManifests (ctx , m .TargetCluster , resourcesYAML )
488475 if err != nil {
489476 return fmt .Errorf ("failed to apply kustomized resources to cluster: %w" , err )
490477 }
0 commit comments