Skip to content

Commit

Permalink
Replace ToolsMode with ToolsAutoUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Oct 25, 2024
1 parent 66c34a6 commit 4edd36a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions api/client/webclient/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ type ProxySettings struct {
type AutoUpdateSettings struct {
// ToolsVersion defines the version of {tsh, tctl} for client auto update.
ToolsVersion string `json:"tools_version"`
// ToolsMode defines mode client auto update feature `enabled|disabled`.
ToolsMode string `json:"tools_mode"`
// ToolsAutoUpdate indicates if the requesting tools client should be updated.
ToolsAutoUpdate bool `json:"tools_auto_update"`
}

// KubeProxySettings is kubernetes proxy settings
Expand Down
3 changes: 1 addition & 2 deletions lib/autoupdate/tools/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (

"github.com/gravitational/teleport/api/client/webclient"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/types/autoupdate"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/packaging"
)
Expand Down Expand Up @@ -196,7 +195,7 @@ func (u *Updater) CheckRemote(ctx context.Context, proxyAddr string) (version st
}

switch {
case resp.AutoUpdate.ToolsMode != autoupdate.ToolsUpdateModeEnabled || resp.AutoUpdate.ToolsVersion == "":
case !resp.AutoUpdate.ToolsAutoUpdate || resp.AutoUpdate.ToolsVersion == "":
return toolsVersion, true, nil
case u.localVersion == resp.AutoUpdate.ToolsVersion:
return resp.AutoUpdate.ToolsVersion, false, nil
Expand Down
6 changes: 2 additions & 4 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,10 +1551,8 @@ func (h *Handler) find(w http.ResponseWriter, r *http.Request, p httprouter.Para
// This ensures we fail open and don't accidentally update agents if something is going wrong.
// If we want to enable AUs by default, it would be better to create a default "autoupdate_config" resource
// than changing this logic.
if autoUpdateConfig.GetSpec().GetTools() == nil {
response.AutoUpdate.ToolsMode = autoupdate.ToolsUpdateModeDisabled
} else {
response.AutoUpdate.ToolsMode = autoUpdateConfig.GetSpec().GetTools().GetMode()
if autoUpdateConfig.GetSpec().GetTools() != nil {
response.AutoUpdate.ToolsAutoUpdate = autoUpdateConfig.GetSpec().GetTools().GetMode() == autoupdate.ToolsUpdateModeEnabled
}

autoUpdateVersion, err := h.cfg.AccessPoint.GetAutoUpdateVersion(r.Context())
Expand Down
24 changes: 12 additions & 12 deletions lib/web/apiserver_ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ func TestPing_autoUpdateResources(t *testing.T) {
{
name: "resources not defined",
expected: webclient.AutoUpdateSettings{
ToolsVersion: api.Version,
ToolsMode: autoupdate.ToolsUpdateModeDisabled,
ToolsVersion: api.Version,
ToolsAutoUpdate: false,
},
},
{
Expand All @@ -317,8 +317,8 @@ func TestPing_autoUpdateResources(t *testing.T) {
},
},
expected: webclient.AutoUpdateSettings{
ToolsMode: autoupdate.ToolsUpdateModeEnabled,
ToolsVersion: api.Version,
ToolsAutoUpdate: true,
ToolsVersion: api.Version,
},
cleanup: true,
},
Expand All @@ -327,8 +327,8 @@ func TestPing_autoUpdateResources(t *testing.T) {
config: &autoupdatev1pb.AutoUpdateConfigSpec{},
version: &autoupdatev1pb.AutoUpdateVersionSpec{},
expected: webclient.AutoUpdateSettings{
ToolsVersion: api.Version,
ToolsMode: autoupdate.ToolsUpdateModeDisabled,
ToolsVersion: api.Version,
ToolsAutoUpdate: false,
},
cleanup: true,
},
Expand All @@ -340,8 +340,8 @@ func TestPing_autoUpdateResources(t *testing.T) {
},
},
expected: webclient.AutoUpdateSettings{
ToolsVersion: "1.2.3",
ToolsMode: autoupdate.ToolsUpdateModeDisabled,
ToolsVersion: "1.2.3",
ToolsAutoUpdate: false,
},
cleanup: true,
},
Expand All @@ -358,8 +358,8 @@ func TestPing_autoUpdateResources(t *testing.T) {
},
},
expected: webclient.AutoUpdateSettings{
ToolsMode: autoupdate.ToolsUpdateModeEnabled,
ToolsVersion: "1.2.3",
ToolsAutoUpdate: true,
ToolsVersion: "1.2.3",
},
},
{
Expand All @@ -375,8 +375,8 @@ func TestPing_autoUpdateResources(t *testing.T) {
},
},
expected: webclient.AutoUpdateSettings{
ToolsMode: autoupdate.ToolsUpdateModeDisabled,
ToolsVersion: "3.2.1",
ToolsAutoUpdate: false,
ToolsVersion: "3.2.1",
},
},
}
Expand Down

0 comments on commit 4edd36a

Please sign in to comment.