Skip to content

Commit d03a45b

Browse files
authored
fix(functions): reload kong after edge runtime restart (#4990)
2 parents 3ea701e + 6352d9a commit d03a45b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

internal/functions/serve/serve.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ func restartEdgeRuntime(ctx context.Context, envFilePath string, noVerifyJWT *bo
117117
dbUrl := fmt.Sprintf("postgresql://postgres:postgres@%s:5432/postgres", utils.DbAliases[0])
118118
// 3. Serve and log to console
119119
fmt.Fprintln(os.Stderr, "Setting up Edge Functions runtime...")
120-
return ServeFunctions(ctx, envFilePath, noVerifyJWT, importMapPath, dbUrl, runtimeOption, fsys)
120+
if err := ServeFunctions(ctx, envFilePath, noVerifyJWT, importMapPath, dbUrl, runtimeOption, fsys); err != nil {
121+
return err
122+
}
123+
// 4. Reload Kong to refresh DNS cache for the new Edge Runtime container IP.
124+
if err := utils.DockerExecOnceWithStream(ctx, utils.KongId, "", nil, []string{"kong", "reload"}, os.Stderr, os.Stderr); err != nil {
125+
fmt.Fprintln(os.Stderr, "Warning: failed to reload Kong:", err)
126+
}
127+
return nil
121128
}
122129

123130
func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPath string, dbUrl string, runtimeOption RuntimeOption, fsys afero.Fs) error {

internal/functions/serve/serve_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ func TestServeCommand(t *testing.T) {
4545
Reply(http.StatusOK)
4646
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.EdgeRuntime.Image), containerId)
4747
require.NoError(t, apitest.MockDockerLogsStream(utils.Docker, containerId, 1, strings.NewReader("failed")))
48+
// Mock kong reload after edge runtime restart
49+
gock.New(utils.Docker.DaemonHost()).
50+
Post("/v" + utils.Docker.ClientVersion() + "/containers/supabase_kong_test/exec").
51+
Reply(http.StatusOK).
52+
JSON(container.ExecCreateResponse{ID: "kong-reload"})
53+
gock.New(utils.Docker.DaemonHost()).
54+
Post("/v" + utils.Docker.ClientVersion() + "/exec/kong-reload/start").
55+
Reply(http.StatusOK)
56+
gock.New(utils.Docker.DaemonHost()).
57+
Get("/v" + utils.Docker.ClientVersion() + "/exec/kong-reload/json").
58+
Reply(http.StatusOK).
59+
JSON(container.ExecInspect{ExitCode: 0})
4860
// Run test with timeout context
4961
err := Run(context.Background(), "", nil, "", RuntimeOption{}, fsys)
5062
// Check error

0 commit comments

Comments
 (0)