fix(preview): skip preview domains when resolving base route from config
When FindRoutesByImage falls back to route config, filter out domains containing the preview separator to prevent using a preview domain as the base for another preview (which produces double-separator names).
- commit
- 61e5cb144927e0dbb2f1edabbf0f2ec83e612a68
- author
- brice · · 2026-03-18 20:37 UTC
- committer
- brice · · 2026-03-18 19:49 UTC
- parent
- a3061c7
- signature
- unsigned
1 file · +7 -2
M internal/usecase/auto/preview/handler.go +7 -2
| @@ -3,6 +3,7 @@ package preview | |||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | 5 | "fmt" | |
| 6 | + | "strings" | |
| 6 | 7 | ||
| 7 | 8 | "github.com/bnema/zerowrap" | |
| 8 | 9 | ||
| @@ -62,12 +63,16 @@ func (h *AutoPreviewHandler) Handle(ctx context.Context, event domain.Event) err | |||
| 62 | 63 | previewConfig := h.config.GetPreviewConfig() | |
| 63 | 64 | previewName := ExtractPreviewName(payload.Reference, previewConfig.TagPatterns) | |
| 64 | 65 | ||
| 65 | - | // Resolve base route: labels first, then route config fallback | |
| 66 | + | // Resolve base route: labels first, then route config fallback. | |
| 67 | + | // When falling back to routes, skip preview domains (they contain the separator) | |
| 68 | + | // to avoid using a preview as the base for another preview. | |
| 66 | 69 | domains := collectDomains(labels) | |
| 67 | 70 | if len(domains) == 0 { | |
| 68 | 71 | routes := h.config.FindRoutesByImage(ctx, payload.Name) | |
| 69 | 72 | for _, r := range routes { | |
| 70 | - | domains = append(domains, r.Domain) | |
| 73 | + | if !strings.Contains(r.Domain, previewConfig.Separator) { | |
| 74 | + | domains = append(domains, r.Domain) | |
| 75 | + | } | |
| 71 | 76 | } | |
| 72 | 77 | } | |
| 73 | 78 | if len(domains) == 0 { | |
| @@ -3,6 +3,7 @@ package preview | |||||
| 3 | import ( | 3 | import ( | ||
| 4 | "context" | 4 | "context" | ||
| 5 | "fmt" | 5 | "fmt" | ||
| 6 | + | "strings" | |||
| 6 | 7 | ||||
| 7 | "github.com/bnema/zerowrap" | 8 | "github.com/bnema/zerowrap" | ||
| 8 | 9 | ||||
| @@ -62,12 +63,16 @@ func (h *AutoPreviewHandler) Handle(ctx context.Context, event domain.Event) err | |||||
| 62 | previewConfig := h.config.GetPreviewConfig() | 63 | previewConfig := h.config.GetPreviewConfig() | ||
| 63 | previewName := ExtractPreviewName(payload.Reference, previewConfig.TagPatterns) | 64 | previewName := ExtractPreviewName(payload.Reference, previewConfig.TagPatterns) | ||
| 64 | 65 | ||||
| 65 | - | // Resolve base route: labels first, then route config fallback | 66 | + | // Resolve base route: labels first, then route config fallback. |
| 67 | + | // When falling back to routes, skip preview domains (they contain the separator) | |||
| 68 | + | // to avoid using a preview as the base for another preview. | |||
| 66 | domains := collectDomains(labels) | 69 | domains := collectDomains(labels) | ||
| 67 | if len(domains) == 0 { | 70 | if len(domains) == 0 { | ||
| 68 | routes := h.config.FindRoutesByImage(ctx, payload.Name) | 71 | routes := h.config.FindRoutesByImage(ctx, payload.Name) | ||
| 69 | for _, r := range routes { | 72 | for _, r := range routes { | ||
| 70 | - | domains = append(domains, r.Domain) | 73 | + | if !strings.Contains(r.Domain, previewConfig.Separator) { |
| 74 | + | domains = append(domains, r.Domain) | |||
| 75 | + | } | |||
| 71 | } | 76 | } | ||
| 72 | } | 77 | } | ||
| 73 | if len(domains) == 0 { | 78 | if len(domains) == 0 { | ||