Skip to content

Commit ace12df

Browse files
Merge pull request #66 from hhftechnology/traefik-int
Traefik int
2 parents b9ad838 + b04321f commit ace12df

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ name: Build and Push Docker Image
33
on:
44
push:
55
branches:
6-
- main
7-
- master
8-
- dev
6+
- traefik-int
97
paths:
108
- 'Dockerfile'
119
- 'go.mod'

services/config_generator.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func extractBaseName(id string) string {
304304
return id
305305
}
306306

307+
// processResourcesWithServices processes resources with their assigned services
307308
// processResourcesWithServices processes resources with their assigned services
308309
func (cg *ConfigGenerator) processResourcesWithServices(config *TraefikConfig) error {
309310
activeDSConfig, err := cg.configManager.GetActiveDataSourceConfig()
@@ -445,27 +446,22 @@ func (cg *ConfigGenerator) processResourcesWithServices(config *TraefikConfig) e
445446
}
446447
}
447448

448-
// Find the section where serviceReference is set
449-
var serviceReference string
450-
if mapValueDataEntry.CustomServiceID.Valid && mapValueDataEntry.CustomServiceID.String != "" {
451-
// Extract base name without any suffixes
452-
baseName := normalizeServiceID(mapValueDataEntry.CustomServiceID.String)
453-
// Always add the file provider for custom services
454-
serviceReference = fmt.Sprintf("%s@file", baseName)
455-
} else {
456-
// For Docker environments when using Traefik API, prefer docker provider
457-
providerSuffix := "docker"
458-
459-
// If not using Traefik API as data source, use http provider
460-
if activeDSConfig.Type != models.TraefikAPI {
461-
providerSuffix = "http"
462-
}
463-
464-
// Extract base name without any suffixes
465-
baseName := normalizeServiceID(info.ServiceID)
466-
// Add the appropriate provider suffix
467-
serviceReference = fmt.Sprintf("%s@%s", baseName, providerSuffix)
468-
}
449+
var serviceReference string
450+
if mapValueDataEntry.CustomServiceID.Valid && mapValueDataEntry.CustomServiceID.String != "" {
451+
baseName := normalizeServiceID(mapValueDataEntry.CustomServiceID.String)
452+
serviceReference = fmt.Sprintf("%s@file", baseName)
453+
} else {
454+
if strings.Contains(info.ServiceID, "@") {
455+
serviceReference = info.ServiceID
456+
} else {
457+
providerSuffix := "docker"
458+
if activeDSConfig.Type != models.TraefikAPI {
459+
providerSuffix = "http"
460+
}
461+
baseName := normalizeServiceID(info.ServiceID)
462+
serviceReference = fmt.Sprintf("%s@%s", baseName, providerSuffix)
463+
}
464+
}
469465

470466
log.Printf("Resource %s (HTTP): Router service set to %s. (SourceType: %s, ActiveDS: %s, CustomSvc: %s)",
471467
info.ID,
@@ -474,9 +470,13 @@ if mapValueDataEntry.CustomServiceID.Valid && mapValueDataEntry.CustomServiceID.
474470
activeDSConfig.Type,
475471
mapValueDataEntry.CustomServiceID.String)
476472

477-
// Make sure we don't have duplicated suffixes in router ID
478473
routerIDBase := extractBaseName(info.ID)
479-
routerIDForTraefik := fmt.Sprintf("%s-auth", routerIDBase)
474+
var routerIDForTraefik string
475+
if strings.HasSuffix(routerIDBase, "-auth") {
476+
routerIDForTraefik = routerIDBase
477+
} else {
478+
routerIDForTraefik = fmt.Sprintf("%s-auth", routerIDBase)
479+
}
480480

481481
routerConfig := map[string]interface{}{
482482
"rule": fmt.Sprintf("Host(`%s`)", info.Host),

0 commit comments

Comments
 (0)