Skip to content

Commit

Permalink
Rename metadata field to 'role' (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson authored Jun 22, 2023
1 parent a18f3d2 commit 5d2ec15
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions fly/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/url"
"os"
"path"
"strconv"
"time"

"golang.org/x/exp/slog"
Expand Down Expand Up @@ -39,7 +38,7 @@ func NewEnvironment() *Environment {

func (e *Environment) Type() string { return "fly.io" }

func (e *Environment) SetPrimaryStatus(ctx context.Context, v bool) error {
func (e *Environment) SetPrimaryStatus(ctx context.Context, isPrimary bool) error {
appName := AppName()
if appName == "" {
slog.Info("cannot set primary status on host environment", slog.String("reason", "app name unavailable"))
Expand All @@ -52,8 +51,13 @@ func (e *Environment) SetPrimaryStatus(ctx context.Context, v bool) error {
return nil
}

role := "replica"
if isPrimary {
role = "primary"
}

reqBody, err := json.Marshal(postMetadataRequest{
Value: strconv.FormatBool(v),
Value: role,
})
if err != nil {
return fmt.Errorf("marshal metadata request body: %w", err)
Expand All @@ -62,7 +66,7 @@ func (e *Environment) SetPrimaryStatus(ctx context.Context, v bool) error {
u := url.URL{
Scheme: "http",
Host: "localhost",
Path: path.Join("/v1", "apps", appName, "machines", machineID, "metadata", "primary"),
Path: path.Join("/v1", "apps", appName, "machines", machineID, "metadata", "role"),
}
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(reqBody))
if err != nil {
Expand Down

0 comments on commit 5d2ec15

Please sign in to comment.