Skip to content

Commit 8cc48ad

Browse files
authored
Merge pull request #63 from PDOK/PDOK-18407-atom-rewrite-fix
Pdok 18407 atom rewrite fix
2 parents e7a320f + 6babe00 commit 8cc48ad

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

internal/controller/middleware.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func (r *AtomReconciler) mutateStripPrefixMiddleware(atom *pdoknlv3.Atom, middle
3434
Prefixes: []string{atom.Spec.Service.BaseURL.Path + "/"}},
3535
}
3636

37+
for _, ingressRouteURL := range atom.Spec.IngressRouteURLs {
38+
middleware.Spec.StripPrefix.Prefixes = append(middleware.Spec.StripPrefix.Prefixes, ingressRouteURL.URL.Path+"/")
39+
}
40+
3741
if err := smoothutil.EnsureSetGVK(r.Client, middleware, middleware); err != nil {
3842
return err
3943
}
@@ -101,7 +105,7 @@ func (r *AtomReconciler) mutateDownloadLinkMiddleware(atom *pdoknlv3.Atom, prefi
101105
middleware.Spec = traefikiov1alpha1.MiddlewareSpec{
102106
ReplacePathRegex: &dynamic.ReplacePathRegex{
103107
Regex: getDownloadLinkRegex(ingressRouteURLs, files),
104-
Replacement: "/" + prefix + "/$1",
108+
Replacement: "/" + prefix + "/$2",
105109
},
106110
}
107111

@@ -112,17 +116,12 @@ func (r *AtomReconciler) mutateDownloadLinkMiddleware(atom *pdoknlv3.Atom, prefi
112116
}
113117

114118
func getDownloadLinkRegex(ingressRouteURLs smoothoperatormodel.IngressRouteURLs, files []string) string {
115-
if len(ingressRouteURLs) == 1 {
116-
return "^" + ingressRouteURLs[0].URL.JoinPath("downloads", "("+strings.Join(files, "|")+")").Path
117-
}
118-
119119
paths := []string{}
120120
for _, ingressRouteURL := range ingressRouteURLs {
121121
paths = append(paths, ingressRouteURL.URL.Path)
122122
}
123123

124124
return "^(" + strings.Join(paths, "|") + ")/downloads/" + "(" + strings.Join(files, "|") + ")"
125-
126125
}
127126

128127
func getDownloadLinkGroups(links []pdoknlv3.DownloadLink) map[string]struct {

internal/controller/test_data/maximum-atom/expected-output/middleware-downloads-0.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ metadata:
1616
spec:
1717
replacePathRegex:
1818
regex: ^(/path|/path/other)/downloads/(index.json|file-1.ext)
19-
replacement: /container/prefix-1/$1
19+
replacement: /container/prefix-1/$2

internal/controller/test_data/maximum-atom/expected-output/middleware-downloads-1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ metadata:
1616
spec:
1717
replacePathRegex:
1818
regex: ^(/path|/path/other)/downloads/(file-2.ext)
19-
replacement: /container/prefix-2/$1
19+
replacement: /container/prefix-2/$2

internal/controller/test_data/maximum-atom/expected-output/middleware-downloads-2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ metadata:
1616
spec:
1717
replacePathRegex:
1818
regex: ^(/path|/path/other)/downloads/(file-3.ext|file-4.ext)
19-
replacement: /container/prefix-3/$1
19+
replacement: /container/prefix-3/$2

internal/controller/test_data/maximum-atom/expected-output/middleware-prefixstrip.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ spec:
1717
stripPrefix:
1818
prefixes:
1919
- /path/
20+
- /path/
21+
- /path/other/

internal/controller/test_data/minimal-atom/expected-output/middleware-downloads-0.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ metadata:
1515
controller: true
1616
spec:
1717
replacePathRegex:
18-
regex: ^/path/downloads/(file.ext)
19-
replacement: /container/prefix/$1
18+
regex: ^(/path)/downloads/(file.ext)
19+
replacement: /container/prefix/$2

0 commit comments

Comments
 (0)