@@ -8,11 +8,15 @@ import (
88
99 "github.com/go-git/go-billy/v5"
1010 "github.com/go-git/go-git/v5"
11+ "github.com/openmcp-project/controller-utils/pkg/clusters"
12+ "k8s.io/apimachinery/pkg/runtime"
1113
1214 gitconfig "github.com/openmcp-project/bootstrapper/internal/git-config"
1315 "github.com/openmcp-project/bootstrapper/internal/log"
1416 ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
1517 "github.com/openmcp-project/bootstrapper/internal/util"
18+ "sigs.k8s.io/kustomize/api/krusty"
19+ "sigs.k8s.io/kustomize/kyaml/filesys"
1620)
1721
1822const (
@@ -58,6 +62,8 @@ type DeploymentRepoManager struct {
5862 // +optional
5963 ImagePullSecrets []string
6064
65+ TargetClusterKubeconfigPath string
66+
6167 // Internals
6268 // tempDir is a temporary directory used for processing
6369 tempDir string
@@ -83,17 +89,20 @@ type DeploymentRepoManager struct {
8389 fluxcdCV * ocmcli.ComponentVersion
8490
8591 crdFiles []string
92+
93+ targetCluster * clusters.Cluster
8694}
8795
8896// NewDeploymentRepoManager creates a new DeploymentRepoManager with the specified parameters.
89- func NewDeploymentRepoManager (componentLocation , fluxTemplateResourceLocation , openmcpTemplateResourceLocation , deploymentRepository , deploymentRepositoryBranch , gitConfigPath string ) * DeploymentRepoManager {
97+ func NewDeploymentRepoManager (componentLocation , fluxTemplateResourceLocation , openmcpTemplateResourceLocation , deploymentRepository , deploymentRepositoryBranch , gitConfigPath , targetClusterKubeconfigPath string ) * DeploymentRepoManager {
9098 return & DeploymentRepoManager {
9199 ComponentLocation : componentLocation ,
92100 FluxTemplateResourceLocation : fluxTemplateResourceLocation ,
93101 OpenMMCPTemplateResourceLocation : openmcpTemplateResourceLocation ,
94102 DeploymentRepository : deploymentRepository ,
95103 DeploymentRepositoryBranch : deploymentRepositoryBranch ,
96104 GitConfigPath : gitConfigPath ,
105+ TargetClusterKubeconfigPath : targetClusterKubeconfigPath ,
97106 }
98107}
99108
@@ -206,7 +215,17 @@ func (m *DeploymentRepoManager) Complete(ctx context.Context) (*DeploymentRepoMa
206215 if err != nil {
207216 return m , fmt .Errorf ("failed to checkout or create branch %s: %w" , m .DeploymentRepositoryBranch , err )
208217 }
209-
218+
219+ m .targetCluster = clusters .New ("platform" ).WithConfigPath (m .TargetClusterKubeconfigPath )
220+ err = m .targetCluster .InitializeRESTConfig ()
221+ if err != nil {
222+ return m , fmt .Errorf ("failed to initialize target cluster REST config: %w" , err )
223+ }
224+ err = m .targetCluster .InitializeClient (runtime .NewScheme ())
225+ if err != nil {
226+ return m , fmt .Errorf ("failed to initialize target cluster client: %w" , err )
227+ }
228+
210229 return m , nil
211230}
212231
@@ -451,6 +470,26 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
451470 return nil
452471}
453472
473+ func (m * DeploymentRepoManager ) RunKustomizeAndApply (ctx context.Context ) error {
474+ fs := filesys .MakeFsOnDisk ()
475+ opts := krusty .MakeDefaultOptions ()
476+ kustomizer := krusty .MakeKustomizer (opts )
477+ resourceMap , err := kustomizer .Run (fs , filepath .Join (m .gitRepoDir , RepoEnvsDir , m .DeploymentRepositoryBranch ))
478+ if err != nil {
479+ return fmt .Errorf ("failed to run kustomize: %w" , err )
480+ }
481+ resourcesYAML , err := resourceMap .AsYaml ()
482+ if err != nil {
483+ return fmt .Errorf ("failed to convert kustomized resources to YAML: %w" , err )
484+ }
485+
486+ err = util .ApplyManifests (ctx , m .targetCluster , resourcesYAML )
487+ if err != nil {
488+ return fmt .Errorf ("failed to apply kustomized resources to cluster: %w" , err )
489+ }
490+ return nil
491+ }
492+
454493// CommitAndPushChanges commits all changes in the deployment repository and pushes them to the remote repository.
455494// If there are no changes to commit, it does nothing.
456495func (m * DeploymentRepoManager ) CommitAndPushChanges (_ context.Context ) error {
0 commit comments