Skip to content

Commit f7696b9

Browse files
committed
update
1 parent 35d1c8a commit f7696b9

File tree

4 files changed

+15
-83
lines changed

4 files changed

+15
-83
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/fluxcd/pkg/apis/meta v1.12.0
99
github.com/go-git/go-billy/v5 v5.6.2
1010
github.com/go-git/go-git/v5 v5.16.2
11+
github.com/go-logr/logr v1.4.3
1112
github.com/openmcp-project/controller-utils v0.19.0
1213
github.com/sirupsen/logrus v1.9.3
1314
github.com/spf13/cobra v1.9.1
@@ -42,7 +43,6 @@ require (
4243
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
4344
github.com/go-errors/errors v1.4.2 // indirect
4445
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
45-
github.com/go-logr/logr v1.4.3 // indirect
4646
github.com/go-openapi/jsonpointer v0.21.0 // indirect
4747
github.com/go-openapi/jsonreference v0.21.0 // indirect
4848
github.com/go-openapi/swag v0.23.0 // indirect

internal/deployment-repo/deploymentRepoManager.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88

99
"github.com/go-git/go-billy/v5"
1010
"github.com/go-git/go-git/v5"
11+
"github.com/go-logr/logr"
1112
"github.com/openmcp-project/controller-utils/pkg/clusters"
1213
"k8s.io/apimachinery/pkg/runtime"
14+
controllerruntime "sigs.k8s.io/controller-runtime"
1315

1416
"sigs.k8s.io/kustomize/api/krusty"
1517
"sigs.k8s.io/kustomize/kyaml/filesys"
@@ -163,6 +165,9 @@ func (m *DeploymentRepoManager) Initialize(ctx context.Context) (*DeploymentRepo
163165

164166
logger.Infof("Creating kubernets client for target cluster from kubeconfig %s", m.Config.TargetCluster.KubeconfigPath)
165167

168+
// disable controller-runtime logging
169+
controllerruntime.SetLogger(logr.Discard())
170+
166171
m.targetCluster = clusters.New("platform").WithConfigPath(m.Config.TargetCluster.KubeconfigPath)
167172
err = m.targetCluster.InitializeRESTConfig()
168173
if err != nil {
@@ -222,10 +227,10 @@ func (m *DeploymentRepoManager) ApplyTemplates(ctx context.Context) error {
222227
"config": m.Config.OpenMCPOperator.ConfigParsed,
223228
}
224229

225-
templateInput["fluxCDEnvPath"] = "./envs/" + m.Config.Environment + "/fluxcd"
230+
templateInput["fluxCDEnvPath"] = "./" + EnvsDirectoryName + "/" + m.Config.Environment + "/" + FluxCDDirectoryName
226231
templateInput["gitRepoEnvBranch"] = m.Config.DeploymentRepository.RepoBranch
227-
templateInput["fluxCDResourcesPath"] = "../../../resources/fluxcd"
228-
templateInput["openMCPResourcesPath"] = "../../../resources/openmcp"
232+
templateInput["fluxCDResourcesPath"] = "../../../" + ResourcesDirectoryName + "/" + FluxCDDirectoryName
233+
templateInput["openMCPResourcesPath"] = "../../../" + ResourcesDirectoryName + "/" + OpenMCPDirectoryName
229234
templateInput["git"] = map[string]interface{}{
230235
"repoUrl": m.Config.DeploymentRepository.RepoURL,
231236
"mainBranch": m.Config.DeploymentRepository.RepoBranch,
@@ -395,7 +400,8 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
395400
}
396401
}(fileInWorkTree)
397402

398-
resourcesRootKustomization, err := ParseKustomizationFromFile(fileInWorkTree)
403+
kustomization := &KubernetesKustomization{}
404+
err = kustomization.ParseFromFile(fileInWorkTree)
399405
if err != nil {
400406
return fmt.Errorf("failed to parse resources root kustomization: %w", err)
401407
}
@@ -406,9 +412,9 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
406412
}
407413

408414
logger.Debugf("Adding files to resources root kustomization: %v", files)
409-
AddResourcesToKustomization(resourcesRootKustomization, files)
415+
kustomization.AddResources(files)
410416

411-
err = WriteKustomizationToFile(fileInWorkTree, resourcesRootKustomization)
417+
err = kustomization.WriteToFile(fileInWorkTree)
412418
if err != nil {
413419
return fmt.Errorf("failed to write resources root kustomization: %w", err)
414420
}

internal/deployment-repo/kustomization.go

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"os"
87

98
fluxk "github.com/fluxcd/kustomize-controller/api/v1"
109
"github.com/openmcp-project/controller-utils/pkg/clusters"
@@ -100,77 +99,3 @@ func (k *FluxKustomization) ApplyToCluster(ctx context.Context, cluster *cluster
10099

101100
return util.ApplyManifests(ctx, cluster, kMarshaled)
102101
}
103-
104-
/////////////////==========================================================================================
105-
106-
func ParseKustomization(path string) (*ktypes.Kustomization, error) {
107-
kustomizationRaw, err := os.ReadFile(path)
108-
if err != nil {
109-
return nil, fmt.Errorf("failed to read kustomization file: %w", err)
110-
}
111-
112-
kustomization := &ktypes.Kustomization{}
113-
err = yaml.Unmarshal(kustomizationRaw, kustomization)
114-
if err != nil {
115-
return nil, fmt.Errorf("failed to unmarshal kustomization file: %w", err)
116-
}
117-
118-
return kustomization, nil
119-
}
120-
121-
func ParseKustomizationFromFile(file io.Reader) (*ktypes.Kustomization, error) {
122-
kustomizationRaw, err := io.ReadAll(file)
123-
if err != nil {
124-
return nil, fmt.Errorf("failed to read kustomization file: %w", err)
125-
}
126-
127-
kustomization := &ktypes.Kustomization{}
128-
err = yaml.Unmarshal(kustomizationRaw, kustomization)
129-
if err != nil {
130-
return nil, fmt.Errorf("failed to unmarshal kustomization file: %w", err)
131-
}
132-
133-
return kustomization, nil
134-
}
135-
136-
func AddResourceToKustomization(kustomization *ktypes.Kustomization, resource string) {
137-
if len(kustomization.Resources) == 0 {
138-
kustomization.Resources = make([]string, 0, 1)
139-
}
140-
kustomization.Resources = append(kustomization.Resources, resource)
141-
}
142-
143-
func AddResourcesToKustomization(kustomization *ktypes.Kustomization, resources []string) {
144-
if len(kustomization.Resources) == 0 {
145-
kustomization.Resources = make([]string, 0, len(resources))
146-
}
147-
kustomization.Resources = append(kustomization.Resources, resources...)
148-
}
149-
150-
func WriteKustomization(path string, kustomization *ktypes.Kustomization) error {
151-
kustomizationRaw, err := yaml.Marshal(kustomization)
152-
if err != nil {
153-
return fmt.Errorf("failed to marshal kustomization file: %w", err)
154-
}
155-
156-
err = os.WriteFile(path, kustomizationRaw, 0644)
157-
if err != nil {
158-
return fmt.Errorf("failed to write kustomization file: %w", err)
159-
}
160-
161-
return nil
162-
}
163-
164-
func WriteKustomizationToFile(file io.Writer, kustomization *ktypes.Kustomization) error {
165-
kustomizationRaw, err := yaml.Marshal(kustomization)
166-
if err != nil {
167-
return fmt.Errorf("failed to marshal kustomization file: %w", err)
168-
}
169-
170-
_, err = file.Write(kustomizationRaw)
171-
if err != nil {
172-
return fmt.Errorf("failed to write kustomization file: %w", err)
173-
}
174-
175-
return nil
176-
}

internal/util/kubernetes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"fmt"
77
"io"
88

9-
"github.com/openmcp-project/bootstrapper/internal/log"
109
"github.com/openmcp-project/controller-utils/pkg/clusters"
1110
apierrors "k8s.io/apimachinery/pkg/api/errors"
1211
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1312
"k8s.io/apimachinery/pkg/util/yaml"
1413
"sigs.k8s.io/controller-runtime/pkg/client"
14+
15+
"github.com/openmcp-project/bootstrapper/internal/log"
1516
)
1617

1718
func ApplyManifests(ctx context.Context, cluster *clusters.Cluster, manifests []byte) error {

0 commit comments

Comments
 (0)