Skip to content

Commit 8aaea20

Browse files
committed
run kustomize
1 parent 84a8f2d commit 8aaea20

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

cmd/manageDeploymentRepo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@ var manageDeploymentRepoCmd = &cobra.Command{
3232
Short: "Updates the openMCP deployment specification in the specified Git repository",
3333
Long: `Updates the openMCP deployment specification in the specified Git repository.
3434
The update is based on the specified component version.
35-
openmcp-bootstrapper manageDeploymentRepo <componentLocation> <templateResourceLocation> <deploymentRepository> <deploymentRepositoryBranch>`,
36-
Args: cobra.ExactArgs(4),
35+
openmcp-bootstrapper manageDeploymentRepo <componentLocation> <templateResourceLocation> <deploymentRepository> <deploymentRepositoryBranch> <targetKubeconfigPath>`,
36+
Args: cobra.ExactArgs(5),
3737
ArgAliases: []string{
3838
"componentLocation",
3939
"templateResourceLocation",
4040
"deploymentRepository",
4141
"deploymentRepositoryBranch",
42+
"targetKubeconfigPath",
4243
},
4344
Example: ` openmcp-bootstrapper manageDeploymentRepo "ghcr.io/openmcp-project/components//github.com/openmcp-project/openmcp:${OPENMCP_VERSION}" templates "https://github.com/${GITHUB_USER}/deployment-repo.git" incoming-branch`,
4445
RunE: func(cmd *cobra.Command, args []string) error {
4546
componentLocation := args[0]
4647
templateResourceLocation := args[1]
4748
deploymentRepository := args[2]
4849
deploymentRepositoryBranch := args[3]
50+
targetClusterKubeconfigPath := args[4]
4951

5052
logger := log.GetLogger()
5153

@@ -82,6 +84,7 @@ openmcp-bootstrapper manageDeploymentRepo <componentLocation> <templateResourceL
8284
deploymentRepository,
8385
deploymentRepositoryBranch,
8486
cmd.Flag(FlagGitConfig).Value.String(),
87+
targetClusterKubeconfigPath,
8588
).WithOcmConfig(cmd.Flag(FlagOcmConfig).Value.String()).
8689
WithClusterProviders(clusterProviders).
8790
WithServiceProviders(serviceProviders).
@@ -121,6 +124,11 @@ openmcp-bootstrapper manageDeploymentRepo <componentLocation> <templateResourceL
121124
return fmt.Errorf("failed to commit and push changes: %w", err)
122125
}
123126

127+
err = deploymentRepoManager.RunKustomizeAndApply(cmd.Context())
128+
if err != nil {
129+
return fmt.Errorf("failed to run kustomize and apply: %w", err)
130+
}
131+
124132
return nil
125133
},
126134
}

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.25.0
55
require (
66
github.com/Masterminds/sprig/v3 v3.3.0
77
github.com/fluxcd/kustomize-controller/api v1.6.1
8+
github.com/fluxcd/pkg/apis/meta v1.12.0
89
github.com/go-git/go-billy/v5 v5.6.2
910
github.com/go-git/go-git/v5 v5.16.2
1011
github.com/openmcp-project/controller-utils v0.19.0
@@ -17,6 +18,7 @@ require (
1718
sigs.k8s.io/controller-runtime v0.22.0
1819
sigs.k8s.io/kustomize v2.0.3+incompatible
1920
sigs.k8s.io/kustomize/api v0.20.1
21+
sigs.k8s.io/kustomize/kyaml v0.20.1
2022
sigs.k8s.io/yaml v1.6.0
2123
)
2224

@@ -27,6 +29,7 @@ require (
2729
github.com/Microsoft/go-winio v0.6.2 // indirect
2830
github.com/ProtonMail/go-crypto v1.1.6 // indirect
2931
github.com/beorn7/perks v1.0.1 // indirect
32+
github.com/blang/semver/v4 v4.0.0 // indirect
3033
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3134
github.com/cloudflare/circl v1.6.1 // indirect
3235
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
@@ -35,7 +38,6 @@ require (
3538
github.com/emirpasic/gods v1.18.1 // indirect
3639
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
3740
github.com/fluxcd/pkg/apis/kustomize v1.12.0 // indirect
38-
github.com/fluxcd/pkg/apis/meta v1.12.0 // indirect
3941
github.com/fsnotify/fsnotify v1.9.0 // indirect
4042
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
4143
github.com/go-errors/errors v1.4.2 // indirect
@@ -61,6 +63,7 @@ require (
6163
github.com/mitchellh/reflectwalk v1.0.2 // indirect
6264
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6365
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
66+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
6467
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6568
github.com/pjbgf/sha1cd v0.3.2 // indirect
6669
github.com/pkg/errors v0.9.1 // indirect
@@ -76,6 +79,7 @@ require (
7679
github.com/spf13/pflag v1.0.9 // indirect
7780
github.com/x448/float16 v0.8.4 // indirect
7881
github.com/xanzy/ssh-agent v0.3.3 // indirect
82+
github.com/xlab/treeprint v1.2.0 // indirect
7983
go.yaml.in/yaml/v2 v2.4.2 // indirect
8084
go.yaml.in/yaml/v3 v3.0.4 // indirect
8185
golang.org/x/crypto v0.41.0 // indirect
@@ -97,7 +101,6 @@ require (
97101
k8s.io/klog/v2 v2.130.1 // indirect
98102
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
99103
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
100-
sigs.k8s.io/kustomize/kyaml v0.20.1 // indirect
101104
sigs.k8s.io/randfill v1.0.0 // indirect
102105
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
103106
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
1717
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
1818
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1919
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
20+
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
21+
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
2022
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
2123
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2224
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
@@ -128,6 +130,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
128130
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
129131
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8=
130132
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
133+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
134+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
131135
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
132136
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
133137
github.com/onsi/ginkgo/v2 v2.25.2 h1:hepmgwx1D+llZleKQDMEvy8vIlCxMGt7W5ZxDjIEhsw=
@@ -183,6 +187,8 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
183187
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
184188
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
185189
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
190+
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
191+
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
186192
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
187193
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
188194
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=

internal/deployment-repo/deploymentRepoManager.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1822
const (
@@ -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.
456495
func (m *DeploymentRepoManager) CommitAndPushChanges(_ context.Context) error {

0 commit comments

Comments
 (0)