@@ -65,6 +65,7 @@ import (
65
65
"github.com/gravitational/teleport/api/client/webclient"
66
66
"github.com/gravitational/teleport/api/constants"
67
67
apidefaults "github.com/gravitational/teleport/api/defaults"
68
+ autoupdatepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
68
69
mfav1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/mfa/v1"
69
70
notificationsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/notifications/v1"
70
71
"github.com/gravitational/teleport/api/mfa"
@@ -130,6 +131,8 @@ const (
130
131
// DefaultFeatureWatchInterval is the default time in which the feature watcher
131
132
// should ping the auth server to check for updated features
132
133
DefaultFeatureWatchInterval = time .Minute * 5
134
+ // DefaultAgentUpdateJitterSeconds is the default jitter agents should wait before updating.
135
+ DefaultAgentUpdateJitterSeconds = 60
133
136
)
134
137
135
138
// healthCheckAppServerFunc defines a function used to perform a health check
@@ -1547,27 +1550,19 @@ func (h *Handler) find(w http.ResponseWriter, r *http.Request, p httprouter.Para
1547
1550
if err != nil && ! trace .IsNotFound (err ) && ! trace .IsNotImplemented (err ) {
1548
1551
h .logger .ErrorContext (r .Context (), "failed to receive AutoUpdateConfig" , "error" , err )
1549
1552
}
1550
- // If we can't get the AU config or tools AU are not configured, we default to "disabled".
1551
- // This ensures we fail open and don't accidentally update agents if something is going wrong.
1552
- // If we want to enable AUs by default, it would be better to create a default "autoupdate_config" resource
1553
- // than changing this logic.
1554
- if autoUpdateConfig .GetSpec ().GetTools () == nil {
1555
- response .AutoUpdate .ToolsMode = autoupdate .ToolsUpdateModeDisabled
1556
- } else {
1557
- response .AutoUpdate .ToolsMode = autoUpdateConfig .GetSpec ().GetTools ().GetMode ()
1558
- }
1559
1553
1560
1554
autoUpdateVersion , err := h .cfg .AccessPoint .GetAutoUpdateVersion (r .Context ())
1561
1555
// TODO(vapopov) DELETE IN v18.0.0 check of IsNotImplemented, must be backported to all latest supported versions.
1562
1556
if err != nil && ! trace .IsNotFound (err ) && ! trace .IsNotImplemented (err ) {
1563
1557
h .logger .ErrorContext (r .Context (), "failed to receive AutoUpdateVersion" , "error" , err )
1564
1558
}
1565
- // If we can't get the AU version or tools AU version is not specified, we default to the current proxy version.
1566
- // This ensures we always advertise a version compatible with the cluster.
1567
- if autoUpdateVersion .GetSpec ().GetTools () == nil {
1568
- response .AutoUpdate .ToolsVersion = api .Version
1569
- } else {
1570
- response .AutoUpdate .ToolsVersion = autoUpdateVersion .GetSpec ().GetTools ().GetTargetVersion ()
1559
+
1560
+ response .AutoUpdate = webclient.AutoUpdateSettings {
1561
+ ToolsMode : getToolsMode (autoUpdateConfig ),
1562
+ ToolsVersion : getToolsVersion (autoUpdateVersion ),
1563
+ AgentUpdateJitterSeconds : DefaultAgentUpdateJitterSeconds ,
1564
+ AgentVersion : getAgentVersion (autoUpdateVersion ),
1565
+ AgentAutoUpdate : agentShouldUpdate (autoUpdateConfig , autoUpdateVersion ),
1571
1566
}
1572
1567
1573
1568
return response , nil
@@ -5122,3 +5117,64 @@ func readEtagFromAppHash(fs http.FileSystem) (string, error) {
5122
5117
5123
5118
return etag , nil
5124
5119
}
5120
+
5121
+ func getToolsMode (config * autoupdatepb.AutoUpdateConfig ) string {
5122
+ // If we can't get the AU config or if AUs are not configured, we default to "disabled".
5123
+ // This ensures we fail open and don't accidentally update agents if something is going wrong.
5124
+ // If we want to enable AUs by default, it would be better to create a default "autoupdate_config" resource
5125
+ // than changing this logic.
5126
+ if config .GetSpec ().GetTools () == nil {
5127
+ return autoupdate .ToolsUpdateModeDisabled
5128
+ }
5129
+ return config .GetSpec ().GetTools ().GetMode ()
5130
+ }
5131
+
5132
+ func getToolsVersion (version * autoupdatepb.AutoUpdateVersion ) string {
5133
+ // If we can't get the AU version or tools AU version is not specified, we default to the current proxy version.
5134
+ // This ensures we always advertise a version compatible with the cluster.
5135
+ if version .GetSpec ().GetTools () == nil {
5136
+ return api .Version
5137
+ }
5138
+ return version .GetSpec ().GetTools ().GetTargetVersion ()
5139
+ }
5140
+
5141
+ func getAgentVersion (version * autoupdatepb.AutoUpdateVersion ) string {
5142
+ // If we can't get the AU version or tools AU version is not specified, we default to the current proxy version.
5143
+ // This ensures we always advertise a version compatible with the cluster.
5144
+ // TODO: read the version from the autoupdate_agent_rollout when the resource is implemented
5145
+ if version .GetSpec ().GetAgents () == nil {
5146
+ return api .Version
5147
+ }
5148
+
5149
+ return version .GetSpec ().GetAgents ().GetTargetVersion ()
5150
+ }
5151
+
5152
+ func agentShouldUpdate (config * autoupdatepb.AutoUpdateConfig , version * autoupdatepb.AutoUpdateVersion ) bool {
5153
+ // TODO: read the data from the autoupdate_agent_rollout when the resource is implemented
5154
+
5155
+ // If we can't get the AU config or if AUs are not configured, we default to "disabled".
5156
+ // This ensures we fail open and don't accidentally update agents if something is going wrong.
5157
+ // If we want to enable AUs by default, it would be better to create a default "autoupdate_config" resource
5158
+ // than changing this logic.
5159
+ if config .GetSpec ().GetAgents () == nil {
5160
+ return false
5161
+ }
5162
+ if version .GetSpec ().GetAgents () == nil {
5163
+ return false
5164
+ }
5165
+ configMode := config .GetSpec ().GetAgents ().GetMode ()
5166
+ versionMode := version .GetSpec ().GetAgents ().GetMode ()
5167
+
5168
+ // We update only if both version and config agent modes are "enabled"
5169
+ if configMode != autoupdate .AgentsUpdateModeEnabled || versionMode != autoupdate .AgentsUpdateModeEnabled {
5170
+ return false
5171
+ }
5172
+
5173
+ scheduleName := version .GetSpec ().GetAgents ().GetSchedule ()
5174
+ if scheduleName == autoupdate .AgentsScheduleImmediate {
5175
+ return true
5176
+ }
5177
+
5178
+ // TODO: add support for the regular schedule name as we implement groups and autoupdate_agent_rollout
5179
+ return false
5180
+ }
0 commit comments