detached 3f8d983

refactor(labels): replace raw gordon.* strings with domain constants

commit
3f8d9833c7d7db393e2f6d65785b62da23b29b0f
author
bnema · · 2026-02-24 21:46 UTC
parent
b86c85a
signature
unsigned
4 files · +43 -14
M internal/adapters/out/docker/runtime.go +3 -3
@@ -1016,8 +1016,8 @@ func (r *Runtime) CreateVolume(ctx context.Context, volumeName string) error {
10161016 _, err := r.client.VolumeCreate(ctx, volume.CreateOptions{
10171017 Name: volumeName,
10181018 Labels: map[string]string{
1019- "gordon.managed": "true",
1020- "gordon.created": "auto",
1019+ domain.LabelManaged: "true",
1020+ domain.LabelCreated: "auto",
10211021 },
10221022 })
10231023 if err != nil {
@@ -1142,7 +1142,7 @@ func (r *Runtime) CreateNetwork(ctx context.Context, name string, options map[st
11421142 createOptions := network.CreateOptions{
11431143 Driver: driver,
11441144 Labels: map[string]string{
1145- "gordon.managed": "true",
1145+ domain.LabelManaged: "true",
11461146 },
11471147 }
11481148
@@ -1016,8 +1016,8 @@ func (r *Runtime) CreateVolume(ctx context.Context, volumeName string) error {
1016 _, err := r.client.VolumeCreate(ctx, volume.CreateOptions{1016 _, err := r.client.VolumeCreate(ctx, volume.CreateOptions{
1017 Name: volumeName,1017 Name: volumeName,
1018 Labels: map[string]string{1018 Labels: map[string]string{
1019- "gordon.managed": "true",1019+ domain.LabelManaged: "true",
1020- "gordon.created": "auto",1020+ domain.LabelCreated: "auto",
1021 },1021 },
1022 })1022 })
1023 if err != nil {1023 if err != nil {
@@ -1142,7 +1142,7 @@ func (r *Runtime) CreateNetwork(ctx context.Context, name string, options map[st
1142 createOptions := network.CreateOptions{1142 createOptions := network.CreateOptions{
1143 Driver: driver,1143 Driver: driver,
1144 Labels: map[string]string{1144 Labels: map[string]string{
1145- "gordon.managed": "true",1145+ domain.LabelManaged: "true",
1146 },1146 },
1147 }1147 }
1148 1148
A internal/domain/labels_test.go +29 -0
@@ -0,0 +1,29 @@
1+package domain_test
2+
3+import (
4+ "testing"
5+
6+ "github.com/bnema/gordon/internal/domain"
7+)
8+
9+// TestLabelConstantsValues guards against accidental value changes that
10+// would silently break container discovery.
11+func TestLabelConstantsValues(t *testing.T) {
12+ tests := []struct {
13+ constant string
14+ expected string
15+ }{
16+ {domain.LabelDomain, "gordon.domain"},
17+ {domain.LabelImage, "gordon.image"},
18+ {domain.LabelManaged, "gordon.managed"},
19+ {domain.LabelRoute, "gordon.route"},
20+ {domain.LabelAttachment, "gordon.attachment"},
21+ {domain.LabelAttachedTo, "gordon.attached-to"},
22+ {domain.LabelCreated, "gordon.created"},
23+ }
24+ for _, tt := range tests {
25+ if tt.constant != tt.expected {
26+ t.Errorf("constant value changed: got %q, want %q", tt.constant, tt.expected)
27+ }
28+ }
29+}
@@ -0,0 +1,29 @@
1+package domain_test
2+
3+import (
4+ "testing"
5+
6+ "github.com/bnema/gordon/internal/domain"
7+)
8+
9+// TestLabelConstantsValues guards against accidental value changes that
10+// would silently break container discovery.
11+func TestLabelConstantsValues(t *testing.T) {
12+ tests := []struct {
13+ constant string
14+ expected string
15+ }{
16+ {domain.LabelDomain, "gordon.domain"},
17+ {domain.LabelImage, "gordon.image"},
18+ {domain.LabelManaged, "gordon.managed"},
19+ {domain.LabelRoute, "gordon.route"},
20+ {domain.LabelAttachment, "gordon.attachment"},
21+ {domain.LabelAttachedTo, "gordon.attached-to"},
22+ {domain.LabelCreated, "gordon.created"},
23+ }
24+ for _, tt := range tests {
25+ if tt.constant != tt.expected {
26+ t.Errorf("constant value changed: got %q, want %q", tt.constant, tt.expected)
27+ }
28+ }
29+}
M internal/usecase/container/events.go +2 -2
@@ -111,7 +111,7 @@ func (h *ConfigReloadHandler) Handle(ctx context.Context, event domain.Event) er
111111
112112 activeRoutes := make(map[string]*domain.Container)
113113 for _, container := range currentContainers {
114- if route, exists := container.Labels["gordon.route"]; exists {
114+ if route, exists := container.Labels[domain.LabelRoute]; exists {
115115 activeRoutes[route] = container
116116 }
117117 }
@@ -119,7 +119,7 @@ func (h *ConfigReloadHandler) Handle(ctx context.Context, event domain.Event) er
119119 routes := h.configSvc.GetRoutes(ctx)
120120 for _, route := range routes {
121121 if container, exists := activeRoutes[route.Domain]; exists {
122- currentImage := container.Labels["gordon.image"]
122+ currentImage := container.Labels[domain.LabelImage]
123123 if currentImage != route.Image {
124124 log.Info().
125125 Str("domain", route.Domain).
@@ -111,7 +111,7 @@ func (h *ConfigReloadHandler) Handle(ctx context.Context, event domain.Event) er
111 111
112 activeRoutes := make(map[string]*domain.Container)112 activeRoutes := make(map[string]*domain.Container)
113 for _, container := range currentContainers {113 for _, container := range currentContainers {
114- if route, exists := container.Labels["gordon.route"]; exists {114+ if route, exists := container.Labels[domain.LabelRoute]; exists {
115 activeRoutes[route] = container115 activeRoutes[route] = container
116 }116 }
117 }117 }
@@ -119,7 +119,7 @@ func (h *ConfigReloadHandler) Handle(ctx context.Context, event domain.Event) er
119 routes := h.configSvc.GetRoutes(ctx)119 routes := h.configSvc.GetRoutes(ctx)
120 for _, route := range routes {120 for _, route := range routes {
121 if container, exists := activeRoutes[route.Domain]; exists {121 if container, exists := activeRoutes[route.Domain]; exists {
122- currentImage := container.Labels["gordon.image"]122+ currentImage := container.Labels[domain.LabelImage]
123 if currentImage != route.Image {123 if currentImage != route.Image {
124 log.Info().124 log.Info().
125 Str("domain", route.Domain).125 Str("domain", route.Domain).
M internal/usecase/container/service.go +9 -9
@@ -219,10 +219,10 @@ func (s *Service) buildContainerConfig(containerDomain, image, actualImageRef st
219219 NetworkMode: networkName,
220220 Hostname: containerDomain,
221221 Labels: map[string]string{
222- "gordon.domain": containerDomain,
223- "gordon.image": image,
224- "gordon.managed": "true",
225- "gordon.route": containerDomain,
222+ domain.LabelDomain: containerDomain,
223+ domain.LabelImage: image,
224+ domain.LabelManaged: "true",
225+ domain.LabelRoute: containerDomain,
226226 },
227227 AutoRemove: false,
228228 }
@@ -905,7 +905,7 @@ func (s *Service) SyncContainers(ctx context.Context) error {
905905 managed := make(map[string]*domain.Container)
906906 for _, c := range allContainers {
907907 if c.Labels != nil {
908- if d, ok := c.Labels["gordon.domain"]; ok && c.Labels["gordon.managed"] == "true" {
908+ if d, ok := c.Labels[domain.LabelDomain]; ok && c.Labels[domain.LabelManaged] == "true" {
909909 managed[d] = c
910910 }
911911 }
@@ -1875,10 +1875,10 @@ func (s *Service) deployAttachedService(ctx context.Context, ownerDomain, servic
18751875 Volumes: volumes,
18761876 NetworkMode: networkName, // Same network as main app
18771877 Labels: map[string]string{
1878- "gordon.managed": "true",
1879- "gordon.attachment": "true",
1880- "gordon.attached-to": ownerDomain,
1881- "gordon.image": serviceImage,
1878+ domain.LabelManaged: "true",
1879+ domain.LabelAttachment: "true",
1880+ domain.LabelAttachedTo: ownerDomain,
1881+ domain.LabelImage: serviceImage,
18821882 },
18831883 }
18841884
@@ -219,10 +219,10 @@ func (s *Service) buildContainerConfig(containerDomain, image, actualImageRef st
219 NetworkMode: networkName,219 NetworkMode: networkName,
220 Hostname: containerDomain,220 Hostname: containerDomain,
221 Labels: map[string]string{221 Labels: map[string]string{
222- "gordon.domain": containerDomain,222+ domain.LabelDomain: containerDomain,
223- "gordon.image": image,223+ domain.LabelImage: image,
224- "gordon.managed": "true",224+ domain.LabelManaged: "true",
225- "gordon.route": containerDomain,225+ domain.LabelRoute: containerDomain,
226 },226 },
227 AutoRemove: false,227 AutoRemove: false,
228 }228 }
@@ -905,7 +905,7 @@ func (s *Service) SyncContainers(ctx context.Context) error {
905 managed := make(map[string]*domain.Container)905 managed := make(map[string]*domain.Container)
906 for _, c := range allContainers {906 for _, c := range allContainers {
907 if c.Labels != nil {907 if c.Labels != nil {
908- if d, ok := c.Labels["gordon.domain"]; ok && c.Labels["gordon.managed"] == "true" {908+ if d, ok := c.Labels[domain.LabelDomain]; ok && c.Labels[domain.LabelManaged] == "true" {
909 managed[d] = c909 managed[d] = c
910 }910 }
911 }911 }
@@ -1875,10 +1875,10 @@ func (s *Service) deployAttachedService(ctx context.Context, ownerDomain, servic
1875 Volumes: volumes,1875 Volumes: volumes,
1876 NetworkMode: networkName, // Same network as main app1876 NetworkMode: networkName, // Same network as main app
1877 Labels: map[string]string{1877 Labels: map[string]string{
1878- "gordon.managed": "true",1878+ domain.LabelManaged: "true",
1879- "gordon.attachment": "true",1879+ domain.LabelAttachment: "true",
1880- "gordon.attached-to": ownerDomain,1880+ domain.LabelAttachedTo: ownerDomain,
1881- "gordon.image": serviceImage,1881+ domain.LabelImage: serviceImage,
1882 },1882 },
1883 }1883 }
1884 1884

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close