Skip to content

Commit 0c953b4

Browse files
authored
fix(enterprise/coderd): make primary workspace proxy always be updatd now (#11499)
1 parent fb29af6 commit 0c953b4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

enterprise/coderd/workspaceproxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ func convertRegion(proxy database.WorkspaceProxy, status proxyhealth.ProxyStatus
930930
}
931931

932932
func convertProxy(p database.WorkspaceProxy, status proxyhealth.ProxyStatus) codersdk.WorkspaceProxy {
933+
now := dbtime.Now()
933934
if p.IsPrimary() {
934935
// Primary is always healthy since the primary serves the api that this
935936
// is returned from.
@@ -939,8 +940,11 @@ func convertProxy(p database.WorkspaceProxy, status proxyhealth.ProxyStatus) cod
939940
ProxyHost: u.Host,
940941
Status: proxyhealth.Healthy,
941942
Report: codersdk.ProxyHealthReport{},
942-
CheckedAt: time.Now(),
943+
CheckedAt: now,
943944
}
945+
// For primary, created at / updated at are always 'now'
946+
p.CreatedAt = now
947+
p.UpdatedAt = now
944948
}
945949
if status.Status == "" {
946950
status.Status = proxyhealth.Unknown

enterprise/coderd/workspaceproxy_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/coder/coder/v2/coderd/coderdtest"
2020
"github.com/coder/coder/v2/coderd/database"
2121
"github.com/coder/coder/v2/coderd/database/dbtestutil"
22+
"github.com/coder/coder/v2/coderd/database/dbtime"
2223
"github.com/coder/coder/v2/coderd/workspaceapps"
2324
"github.com/coder/coder/v2/codersdk"
2425
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
@@ -93,11 +94,16 @@ func TestRegions(t *testing.T) {
9394
deploymentID, err := db.GetDeploymentID(ctx)
9495
require.NoError(t, err, "get deployment ID")
9596

97+
// The default proxy is always called "primary".
98+
primary, err := client.WorkspaceProxyByName(ctx, "primary")
99+
require.NoError(t, err)
100+
96101
const proxyName = "hello"
97102
_ = coderdenttest.NewWorkspaceProxy(t, api, client, &coderdenttest.ProxyOptions{
98103
Name: proxyName,
99104
AppHostname: appHostname + ".proxy",
100105
})
106+
approxCreateTime := dbtime.Now()
101107
proxy, err := db.GetWorkspaceProxyByName(ctx, proxyName)
102108
require.NoError(t, err)
103109

@@ -135,7 +141,7 @@ func TestRegions(t *testing.T) {
135141
require.NoError(t, err)
136142
require.Len(t, regions, 2)
137143

138-
// Region 0 is the primary require.Len(t, regions, 1)
144+
// Region 0 is the primary
139145
require.NotEqual(t, uuid.Nil, regions[0].ID)
140146
require.Equal(t, regions[0].ID.String(), deploymentID)
141147
require.Equal(t, "primary", regions[0].Name)
@@ -145,6 +151,11 @@ func TestRegions(t *testing.T) {
145151
require.Equal(t, client.URL.String(), regions[0].PathAppURL)
146152
require.Equal(t, appHostname, regions[0].WildcardHostname)
147153

154+
// Ensure non-zero fields of the default proxy
155+
require.NotZero(t, primary.Name)
156+
require.NotZero(t, primary.CreatedAt)
157+
require.NotZero(t, primary.UpdatedAt)
158+
148159
// Region 1 is the proxy.
149160
require.NotEqual(t, uuid.Nil, regions[1].ID)
150161
require.Equal(t, proxy.ID, regions[1].ID)
@@ -154,6 +165,11 @@ func TestRegions(t *testing.T) {
154165
require.True(t, regions[1].Healthy)
155166
require.Equal(t, proxy.Url, regions[1].PathAppURL)
156167
require.Equal(t, proxy.WildcardHostname, regions[1].WildcardHostname)
168+
169+
// Unfortunately need to wait to assert createdAt/updatedAt
170+
<-time.After(testutil.WaitShort / 10)
171+
require.WithinDuration(t, approxCreateTime, proxy.CreatedAt, testutil.WaitShort/10)
172+
require.WithinDuration(t, approxCreateTime, proxy.UpdatedAt, testutil.WaitShort/10)
157173
})
158174

159175
t.Run("RequireAuth", func(t *testing.T) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy