Skip to content

Commit 7c3d04f

Browse files
authored
Merge pull request #1563 from aamoyel/kustomize-sanitized
fix(kustomize-artifact): add sanitized revision to avoid invalid char…
2 parents cda25da + 0a870b5 commit 7c3d04f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/flux_source.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ func prepareFileSystemWithFluxSource(source sourcev1.Source, logger logr.Logger)
5252
// Update status with the reconciliation progress.
5353
// revision := source.GetArtifact().Revision
5454

55+
// Sanitize revision string by replacing invalid filesystem characters
56+
// Git artifact revisions contain characters like '/', ':', '@' which are not valid in directory names
57+
sanitizedRevision := strings.NewReplacer("/", "-", ":", "-", "@", "-").Replace(source.GetArtifact().Revision)
58+
5559
// Create tmp dir.
56-
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("kustomization-%s", source.GetArtifact().Revision))
60+
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("kustomization-%s", sanitizedRevision))
5761
if err != nil {
5862
err = fmt.Errorf("prepareFileSystemWithFluxSource: tmp dir error: %w", err)
5963
return "", err
@@ -130,13 +134,19 @@ func getReferencedFluxSourceFromURL(hc *configv1beta1.HelmChart) (*corev1.Object
130134
const repoURLParts = 2
131135
parts := strings.SplitN(hc.RepositoryURL, "://", repoURLParts)
132136
if len(parts) != repoURLParts {
133-
return nil, "", fmt.Errorf("incorrect format: %q. Expected format sourceKind://sourceNamespace/sourceName/sourcePath", hc.RepositoryURL)
137+
return nil, "", fmt.Errorf(
138+
"incorrect format: %q. Expected format sourceKind://sourceNamespace/sourceName/sourcePath",
139+
hc.RepositoryURL,
140+
)
134141
}
135142

136143
sourceKind := parts[0]
137144
remainingParts := strings.Split(parts[1], "/")
138145
if len(remainingParts) < 3 { //nolint: mnd // expected namespace, name and path
139-
return nil, "", fmt.Errorf("incorrect format: %q. Expected format sourceKind://sourceNamespace/sourceName/sourcePath", hc.RepositoryURL)
146+
return nil, "", fmt.Errorf(
147+
"incorrect format: %q. Expected format sourceKind://sourceNamespace/sourceName/sourcePath",
148+
hc.RepositoryURL,
149+
)
140150
}
141151

142152
sourceNamespace := remainingParts[0]

0 commit comments

Comments
 (0)