Skip to content

Commit 3e4eb67

Browse files
author
Sunser
committed
Remove configurable state path
1 parent f508d0a commit 3e4eb67

8 files changed

Lines changed: 30 additions & 15 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
shell: bash
2727
run: echo "IMAGE_NAME=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
2828

29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
2932
- name: Set up Docker Buildx
3033
uses: docker/setup-buildx-action@v3
3134

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ ARG TARGETARCH
66
ARG TARGETVARIANT
77

88
WORKDIR /src
9-
RUN apk add --no-cache ca-certificates tzdata
109

1110
COPY go.mod ./
1211
COPY cmd ./cmd
@@ -25,9 +24,9 @@ RUN set -eux; \
2524

2625
FROM alpine:3.20
2726

27+
RUN apk add --no-cache ca-certificates tzdata
28+
2829
WORKDIR /app
29-
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
30-
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
3130
COPY --from=builder /out/ecs-controller ./ecs-controller
3231
COPY web ./web
3332

cmd/ecs-controller/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
const (
1919
configPath = "/data/settings.yaml"
20+
statePath = "/data/state.json"
2021
webDir = "/app/web"
2122
)
2223

@@ -31,9 +32,9 @@ func main() {
3132
}
3233
applog.SetLevel(cfg.Logging.Level)
3334

34-
state, err := monitor.OpenStateStore(cfg.Server.StatePath)
35+
state, err := monitor.OpenStateStore(statePath)
3536
if err != nil {
36-
applog.Error("state", "load failed", map[string]string{"path": cfg.Server.StatePath, "error": err.Error()})
37+
applog.Error("state", "load failed", map[string]string{"path": statePath, "error": err.Error()})
3738
os.Exit(1)
3839
}
3940

internal/config/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type ServerConfig struct {
2929
RefreshInterval time.Duration
3030
RequestTimeout time.Duration
3131
Password string
32-
StatePath string
3332
}
3433

3534
type DiscoveryConfig struct {
@@ -203,7 +202,6 @@ func defaultConfig() Config {
203202
Listen: ":8080",
204203
RefreshInterval: 5 * time.Minute,
205204
RequestTimeout: 20 * time.Second,
206-
StatePath: "/data/state.json",
207205
},
208206
Discovery: DiscoveryConfig{
209207
RegionRefreshInterval: 24 * time.Hour,
@@ -242,8 +240,6 @@ func applyServer(cfg *ServerConfig, key, value string) error {
242240
cfg.RequestTimeout = duration
243241
case "password":
244242
cfg.Password = scalar(value)
245-
case "state_path":
246-
cfg.StatePath = scalar(value)
247243
default:
248244
return fmt.Errorf("未知 server 字段 %q", key)
249245
}

internal/config/config_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ accounts:
4545
if cfg.Server.RefreshInterval != 5*time.Minute {
4646
t.Fatalf("refresh interval = %s, want 5m", cfg.Server.RefreshInterval)
4747
}
48-
if cfg.Server.StatePath != "/data/state.json" {
49-
t.Fatalf("state path = %q, want /data/state.json", cfg.Server.StatePath)
50-
}
5148
if cfg.KeepAlive.TrafficPolicy != "manual_only_when_exceeded" {
5249
t.Fatalf("traffic policy = %q", cfg.KeepAlive.TrafficPolicy)
5350
}
@@ -89,6 +86,25 @@ accounts:
8986
}
9087
}
9188

89+
func TestLoadBytesRejectsLegacyStatePath(t *testing.T) {
90+
_, err := config.LoadBytes([]byte(`
91+
server:
92+
password: "secret"
93+
state_path: "/data/state.json"
94+
accounts:
95+
- name: "cn"
96+
site: "china"
97+
access_key_id: "ak"
98+
access_key_secret: "sk"
99+
`))
100+
if err == nil {
101+
t.Fatal("LoadBytes() error = nil, want unknown state_path error")
102+
}
103+
if !strings.Contains(err.Error(), "state_path") {
104+
t.Fatalf("LoadBytes() error = %v, want state_path", err)
105+
}
106+
}
107+
92108
func TestLoadBytesRejectsMissingAccounts(t *testing.T) {
93109
_, err := config.LoadBytes([]byte(`
94110
server:

internal/config/write.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func renderGlobalSettings(original string, cfg Config) string {
4545
writeKeyValue(&builder, "refresh_interval", quote(formatDuration(cfg.Server.RefreshInterval.String())))
4646
writeKeyValue(&builder, "request_timeout", quote(formatDuration(cfg.Server.RequestTimeout.String())))
4747
writeKeyValue(&builder, "password", rawOrEnvPlaceholder(original, "server", "password", "EC_PASSWORD", cfg.Server.Password))
48-
writeKeyValue(&builder, "state_path", rawOrQuoted(original, "server", "state_path", cfg.Server.StatePath))
4948

5049
builder.WriteString("\ndiscovery:\n")
5150
writeKeyValue(&builder, "region_refresh_interval", quote(formatDuration(cfg.Discovery.RegionRefreshInterval.String())))

internal/config/write_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ server:
2222
refresh_interval: "5m"
2323
request_timeout: "20s"
2424
password: "${EC_PASSWORD}"
25-
state_path: "/data/state.json"
2625
2726
discovery:
2827
region_refresh_interval: "24h"
@@ -105,6 +104,9 @@ accounts:
105104
if strings.Contains(text, "instance_refresh_interval") {
106105
t.Fatalf("written config kept legacy instance_refresh_interval:\n%s", text)
107106
}
107+
if strings.Contains(text, "state_path") {
108+
t.Fatalf("written config kept legacy state_path:\n%s", text)
109+
}
108110

109111
reloaded, err := config.LoadFile(path)
110112
if err != nil {

internal/monitor/service_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ server:
141141
refresh_interval: "5m"
142142
request_timeout: "20s"
143143
password: "${EC_PASSWORD}"
144-
state_path: "/data/state.json"
145144
146145
discovery:
147146
region_refresh_interval: "24h"

0 commit comments

Comments
 (0)