Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client AutoUpdate proto structure changes #47532

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
// ToolsAutoUpdate enables client auto update feature.
ToolsAutoUpdate bool `json:"tools_auto_update"`
// ToolsMode defines mode client auto update feature `enabled|disabled`.
ToolsMode string `json:"tools_mode"`
}

// KubeProxySettings is kubernetes proxy settings
Expand Down
305 changes: 251 additions & 54 deletions api/gen/proto/go/teleport/autoupdate/v1/autoupdate.pb.go

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions api/proto/teleport/autoupdate/v1/autoupdate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,26 @@ message AutoUpdateConfig {
// AutoUpdateConfigSpec encodes the parameters of the autoupdate config object.
message AutoUpdateConfigSpec {
// ToolsAutoupdate encodes the feature flag to enable/disable tools autoupdates.
// Deprecated: use AutoUpdateConfigTools instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this being used in prod? If no, we can reserve the field and continue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 let's reserve the fields and deprecate

bool tools_autoupdate = 1;

AutoUpdateConfigTools tools = 2;
}

// AutoUpdateConfigTools encodes the parameters for client tools auto updates.
message AutoUpdateConfigTools {
// Mode defines state of the client tools auto update.
ToolsMode mode = 1;
}

// ToolsMode type for client tools enabling state.
enum ToolsMode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enum ToolsMode {
enum ToolsUpdateMode {

// TOOLS_MODE_UNSPECIFIED is undefined mode.
TOOLS_MODE_UNSPECIFIED = 0;
// TOOLS_MODE_ENABLED client tools auto update is enabled.
TOOLS_MODE_ENABLED = 1;
// TOOLS_MODE_DISABLED client tools auto update is disabled.
TOOLS_MODE_DISABLED = 2;
}

// AutoUpdateVersion is a resource singleton with version required for
Expand All @@ -51,5 +70,14 @@ message AutoUpdateVersion {
// AutoUpdateVersionSpec encodes the parameters of the autoupdate versions.
message AutoUpdateVersionSpec {
// ToolsVersion is the semantic version required for tools autoupdates.
// Deprecated: use AutoUpdateVersionTools instead.
string tools_version = 1;

AutoUpdateVersionTools tools = 2;
}

// AutoUpdateVersionTools encodes the parameters for client tools auto updates.
message AutoUpdateVersionTools {
// TargetVersion is the semantic version required for tools autoupdates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the target version we want you to upgrade to or is it the version required for you to be able to update to something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vapopov what's the correct version here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tigrato TargetVersion is mandatory version for update, if mode is enabled so everyone who is connected to the cluster going to be updated to this version (except client tools executed with disabling env variable)

Copy link
Contributor

@tigrato tigrato Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename it to:

// TargetVersion specifies the semantic version required for tools to establish a connection with the cluster.

The way it's written today is misleading and reads as the version required for auto updates and not the target auto update version

string target_version = 1;
}
12 changes: 12 additions & 0 deletions api/types/autoupdate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ func ValidateAutoUpdateConfig(c *autoupdate.AutoUpdateConfig) error {

return nil
}

// ToolsModeToAPI transforms client tools mode enum to API string representation.
func ToolsModeToAPI(mode autoupdate.ToolsMode) string {
switch mode {
case autoupdate.ToolsMode_TOOLS_MODE_ENABLED:
return "enabled"
case autoupdate.ToolsMode_TOOLS_MODE_DISABLED:
return "disabled"
default:
return ""
}
}
12 changes: 7 additions & 5 deletions api/types/autoupdate/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ func ValidateAutoUpdateVersion(v *autoupdate.AutoUpdateVersion) error {
return trace.BadParameter("Spec is nil")
}

if v.Spec.ToolsVersion == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you no longer validate v.Spec.ToolsVersion. Is it used in prod? Should we keep it if not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we decided to rename before actual usage in prod, so this resource is not used previously

return trace.BadParameter("ToolsVersion is unset")
}
if _, err := semver.NewVersion(v.Spec.ToolsVersion); err != nil {
return trace.BadParameter("ToolsVersion is not a valid semantic version")
if v.Spec.Tools != nil {
if v.Spec.Tools.TargetVersion == "" {
return trace.BadParameter("TargetVersion is unset")
}
if _, err := semver.NewVersion(v.Spec.Tools.TargetVersion); err != nil {
return trace.BadParameter("TargetVersion is not a valid semantic version")
}
}

return nil
Expand Down
20 changes: 14 additions & 6 deletions api/types/autoupdate/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func TestNewAutoUpdateVersion(t *testing.T) {
{
name: "success tools autoupdate version",
spec: &autoupdate.AutoUpdateVersionSpec{
ToolsVersion: "1.2.3-dev",
Tools: &autoupdate.AutoUpdateVersionTools{
TargetVersion: "1.2.3-dev",
},
},
assertErr: func(t *testing.T, err error, a ...any) {
require.NoError(t, err)
Expand All @@ -53,26 +55,32 @@ func TestNewAutoUpdateVersion(t *testing.T) {
Name: types.MetaNameAutoUpdateVersion,
},
Spec: &autoupdate.AutoUpdateVersionSpec{
ToolsVersion: "1.2.3-dev",
Tools: &autoupdate.AutoUpdateVersionTools{
TargetVersion: "1.2.3-dev",
},
},
},
},
{
name: "invalid empty tools version",
spec: &autoupdate.AutoUpdateVersionSpec{
ToolsVersion: "",
Tools: &autoupdate.AutoUpdateVersionTools{
TargetVersion: "",
},
},
assertErr: func(t *testing.T, err error, a ...any) {
require.ErrorContains(t, err, "ToolsVersion is unset")
require.ErrorContains(t, err, "TargetVersion is unset")
},
},
{
name: "invalid semantic tools version",
spec: &autoupdate.AutoUpdateVersionSpec{
ToolsVersion: "17-0-0",
Tools: &autoupdate.AutoUpdateVersionTools{
TargetVersion: "17-0-0",
},
},
assertErr: func(t *testing.T, err error, a ...any) {
require.ErrorContains(t, err, "ToolsVersion is not a valid semantic version")
require.ErrorContains(t, err, "TargetVersion is not a valid semantic version")
},
},
{
Expand Down
5 changes: 3 additions & 2 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import (
"github.com/gravitational/teleport/api/mfa"
apitracing "github.com/gravitational/teleport/api/observability/tracing"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/autoupdate"
apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/api/types/installers"
"github.com/gravitational/teleport/api/utils/keys"
Expand Down Expand Up @@ -1545,15 +1546,15 @@ func (h *Handler) find(w http.ResponseWriter, r *http.Request, p httprouter.Para
if err != nil && !trace.IsNotFound(err) && !trace.IsNotImplemented(err) {
h.logger.ErrorContext(r.Context(), "failed to receive AutoUpdateConfig", "error", err)
} else if err == nil {
response.AutoUpdate.ToolsAutoUpdate = autoUpdateConfig.GetSpec().GetToolsAutoupdate()
response.AutoUpdate.ToolsMode = autoupdate.ToolsModeToAPI(autoUpdateConfig.GetSpec().GetTools().GetMode())
}

autoUpdateVersion, err := h.cfg.AccessPoint.GetAutoUpdateVersion(r.Context())
// TODO(vapopov) DELETE IN v18.0.0 check of IsNotImplemented, must be backported to all latest supported versions.
if err != nil && !trace.IsNotFound(err) && !trace.IsNotImplemented(err) {
h.logger.ErrorContext(r.Context(), "failed to receive AutoUpdateVersion", "error", err)
} else if err == nil {
response.AutoUpdate.ToolsVersion = autoUpdateVersion.GetSpec().GetToolsVersion()
response.AutoUpdate.ToolsVersion = autoUpdateVersion.GetSpec().GetTools().GetTargetVersion()
}

return response, nil
Expand Down
50 changes: 37 additions & 13 deletions lib/web/apiserver_ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,28 +275,52 @@ func TestPing_autoUpdateResources(t *testing.T) {
expected: webclient.AutoUpdateSettings{},
},
{
name: "enable auto update",
config: &autoupdatev1pb.AutoUpdateConfigSpec{ToolsAutoupdate: true},
expected: webclient.AutoUpdateSettings{ToolsAutoUpdate: true},
name: "enable auto update",
config: &autoupdatev1pb.AutoUpdateConfigSpec{
Tools: &autoupdatev1pb.AutoUpdateConfigTools{
Mode: autoupdatev1pb.ToolsMode_TOOLS_MODE_ENABLED,
},
},
expected: webclient.AutoUpdateSettings{ToolsMode: "enabled"},
cleanup: true,
},
{
name: "set auto update version",
version: &autoupdatev1pb.AutoUpdateVersionSpec{ToolsVersion: "1.2.3"},
name: "set auto update version",
version: &autoupdatev1pb.AutoUpdateVersionSpec{
Tools: &autoupdatev1pb.AutoUpdateVersionTools{
TargetVersion: "1.2.3",
},
},
expected: webclient.AutoUpdateSettings{ToolsVersion: "1.2.3"},
cleanup: true,
},
{
name: "enable auto update and set version",
config: &autoupdatev1pb.AutoUpdateConfigSpec{ToolsAutoupdate: true},
version: &autoupdatev1pb.AutoUpdateVersionSpec{ToolsVersion: "1.2.3"},
expected: webclient.AutoUpdateSettings{ToolsAutoUpdate: true, ToolsVersion: "1.2.3"},
name: "enable auto update and set version",
config: &autoupdatev1pb.AutoUpdateConfigSpec{
Tools: &autoupdatev1pb.AutoUpdateConfigTools{
Mode: autoupdatev1pb.ToolsMode_TOOLS_MODE_ENABLED,
},
},
version: &autoupdatev1pb.AutoUpdateVersionSpec{
Tools: &autoupdatev1pb.AutoUpdateVersionTools{
TargetVersion: "1.2.3",
},
},
expected: webclient.AutoUpdateSettings{ToolsMode: "enabled", ToolsVersion: "1.2.3"},
},
{
name: "modify auto update config and version",
config: &autoupdatev1pb.AutoUpdateConfigSpec{ToolsAutoupdate: false},
version: &autoupdatev1pb.AutoUpdateVersionSpec{ToolsVersion: "3.2.1"},
expected: webclient.AutoUpdateSettings{ToolsAutoUpdate: false, ToolsVersion: "3.2.1"},
name: "modify auto update config and version",
config: &autoupdatev1pb.AutoUpdateConfigSpec{
Tools: &autoupdatev1pb.AutoUpdateConfigTools{
Mode: autoupdatev1pb.ToolsMode_TOOLS_MODE_DISABLED,
},
},
version: &autoupdatev1pb.AutoUpdateVersionSpec{
Tools: &autoupdatev1pb.AutoUpdateVersionTools{
TargetVersion: "3.2.1",
},
},
expected: webclient.AutoUpdateSettings{ToolsMode: "disabled", ToolsVersion: "3.2.1"},
},
}
for _, tc := range tests {
Expand Down
Loading