Skip to content

Commit a1c9856

Browse files
committed
fix(runtime): retry incomplete materialization
1 parent 2d5f793 commit a1c9856

7 files changed

Lines changed: 39 additions & 195 deletions

File tree

apps/druid/adapters/cli/client/dev.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func runDevServer() error {
132132
}
133133
auth := devAuth{runtimeID: devRuntimeID, ownerID: devOwnerID}
134134
if devAuthJWKSURL != "" {
135-
auth.user, err = coreservices.NewAuthorizer(devAuthJWKSURL, "")
135+
auth.user, err = coreservices.NewAuthorizer([]string{devAuthJWKSURL}, "")
136136
if err != nil {
137137
return err
138138
}

apps/druid/adapters/cli/daemon.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func runRuntimeDaemon() error {
148148
return err
149149
}
150150

151-
authorizer, err := services.NewAuthorizer(runtimeAuthJWKSURL, "")
151+
authorizer, err := services.NewAuthorizer(buildJWKSURLs([]string{runtimeAuthJWKSURL}), "")
152152
if err != nil {
153153
return err
154154
}
@@ -269,3 +269,22 @@ func listenRuntimeDaemon(app *fiber.App, stateDir string) error {
269269
logger.Log().Info("Starting runtime daemon", zap.String("socket", runtimeSocket), zap.String("stateDir", stateDir))
270270
return app.Listener(listener)
271271
}
272+
273+
func buildJWKSURLs(values []string) []string {
274+
urls := make([]string, 0, len(values))
275+
seen := make(map[string]struct{}, len(values))
276+
277+
for _, url := range values {
278+
url = strings.TrimSpace(url)
279+
if url == "" {
280+
continue
281+
}
282+
if _, ok := seen[url]; ok {
283+
continue
284+
}
285+
seen[url] = struct{}{}
286+
urls = append(urls, url)
287+
}
288+
289+
return urls
290+
}

apps/druid/adapters/cli/serve.go

Lines changed: 0 additions & 179 deletions
This file was deleted.

apps/druid/adapters/cli/worker_pull.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ func loadWorkerRegistryStore() *registry.CredentialStore {
101101
if len(config.Registries) == 0 {
102102
_ = viper.UnmarshalKey("registries", &config.Registries)
103103
}
104+
if len(config.Registries) == 0 {
105+
if path := viper.ConfigFileUsed(); path != "" {
106+
if raw, err := os.ReadFile(path); err == nil {
107+
_ = json.Unmarshal(raw, &config)
108+
}
109+
}
110+
}
104111
return registry.NewCredentialStore(config.Registries)
105112
}
106113

apps/druid/core/services/runtime_supervisor.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,6 @@ func (s *RuntimeSupervisor) EnsureWithOwner(artifact string, name string, ownerI
143143
}
144144
}
145145
if runtimeScroll.ScrollYAML == "" {
146-
if runtimeScroll.Status == domain.RuntimeScrollStatusError {
147-
if ownerID != "" && runtimeScroll.OwnerID != ownerID {
148-
runtimeScroll.OwnerID = ownerID
149-
if err := s.store.UpdateScroll(runtimeScroll); err != nil {
150-
return nil, err
151-
}
152-
}
153-
return runtimeScroll, nil
154-
}
155146
if artifact == "" {
156147
artifact = runtimeScroll.Artifact
157148
}

apps/druid/core/services/runtime_supervisor_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ app_version: "1.0"
2828
serve: start
2929
commands:
3030
start:
31+
run: restart
3132
procedures:
3233
- image: alpine:3.20
3334
command: ["true"]
@@ -459,7 +460,7 @@ func TestRuntimeSupervisorCreateUsesRequestedNamespaceForRoot(t *testing.T) {
459460
}
460461
}
461462

462-
func TestRuntimeSupervisorEnsureMaterializationFailureIsRemembered(t *testing.T) {
463+
func TestRuntimeSupervisorEnsureRetriesIncompleteMaterializationFailure(t *testing.T) {
463464
store := newTestStateStore(t)
464465
callbacks := NewWorkerCallbackManager()
465466
backend := &fakeWorkerBackend{callbacks: callbacks, workerErr: errors.New("pull image failed")}
@@ -481,12 +482,15 @@ func TestRuntimeSupervisorEnsureMaterializationFailureIsRemembered(t *testing.T)
481482
t.Fatalf("failed scroll = %#v", failed)
482483
}
483484

485+
backend.workerErr = nil
486+
backend.scrollYAML = cachedScrollYAML("start")
487+
backend.digest = "sha256:recovered"
484488
runtimeScroll, err := supervisor.Ensure("registry.local/missing:1.0", "broken-scroll", nil)
485489
if err != nil {
486-
t.Fatalf("second Ensure error = %v, want remembered runtime scroll", err)
490+
t.Fatalf("second Ensure error = %v, want recovery", err)
487491
}
488-
if runtimeScroll.Status != domain.RuntimeScrollStatusError || backend.spawnCount != 1 {
489-
t.Fatalf("runtimeScroll=%#v spawnCount=%d, want remembered error and no respawn", runtimeScroll, backend.spawnCount)
492+
if runtimeScroll.Status != domain.RuntimeScrollStatusCreated || runtimeScroll.ScrollYAML == "" || runtimeScroll.ArtifactDigest != "sha256:recovered" || backend.spawnCount != 2 {
493+
t.Fatalf("runtimeScroll=%#v spawnCount=%d, want recovered materialization", runtimeScroll, backend.spawnCount)
490494
}
491495
}
492496

@@ -1005,6 +1009,7 @@ app_version: "2.0"
10051009
serve: start
10061010
commands:
10071011
start:
1012+
run: restart
10081013
procedures:
10091014
- image: alpine:3.20
10101015
command: ["true"]

internal/core/services/authorizer_service_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/gofiber/fiber/v2"
1515
"github.com/golang-jwt/jwt/v4"
16+
"github.com/highcard-dev/daemon/internal/core/ports"
1617
)
1718

1819
func TestAuthorizerService_CheckHeaderAcceptsMultipleJWKS(t *testing.T) {
@@ -76,7 +77,7 @@ func TestAuthorizerService_CheckHeaderRejectsWrongSub(t *testing.T) {
7677
}
7778

7879
func checkAuthorizationHeader(authorizer interface {
79-
CheckHeader(*fiber.Ctx) (*time.Time, error)
80+
CheckHeader(*fiber.Ctx) (*ports.AuthContext, error)
8081
}, token string) error {
8182
app := fiber.New()
8283
var authErr error

0 commit comments

Comments
 (0)