Skip to content

Commit

Permalink
autoupdate: reconcile rollout status and add strategy interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoShaka committed Dec 3, 2024
1 parent 76bfe76 commit 3ac5109
Show file tree
Hide file tree
Showing 9 changed files with 886 additions and 52 deletions.
80 changes: 57 additions & 23 deletions api/gen/proto/go/teleport/autoupdate/v1/autoupdate.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/proto/teleport/autoupdate/v1/autoupdate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ message AutoUpdateAgentRolloutStatusGroup {
google.protobuf.Timestamp last_update_time = 4;
// last_update_reason is the trigger for the last update
string last_update_reason = 5;
// config_days when the update can run. Supported values are "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" and "*"
repeated string config_days = 6;
// config_start_hour to initiate update
int32 config_start_hour = 7;
// config_wait_days after last group succeeds before this group can run. This can only be used when the strategy is "halt-on-failure".
int64 config_wait_days = 9;
}

// AutoUpdateAgentGroupState represents the agent group state. This state controls whether the agents from this group
Expand Down
8 changes: 4 additions & 4 deletions api/types/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ var validWeekdays = [7]time.Weekday{
time.Saturday,
}

// parseWeekday attempts to interpret a string as a time.Weekday. In the interest of flexibility,
// ParseWeekday attempts to interpret a string as a time.Weekday. In the interest of flexibility,
// parsing is case-insensitive and supports the common three-letter shorthand accepted by many
// common scheduling utilites (e.g. contab, systemd timers).
func parseWeekday(s string) (day time.Weekday, ok bool) {
func ParseWeekday(s string) (day time.Weekday, ok bool) {
for _, w := range validWeekdays {
if strings.EqualFold(w.String(), s) || strings.EqualFold(w.String()[:3], s) {
return w, true
Expand All @@ -75,7 +75,7 @@ func (w *AgentUpgradeWindow) generator(from time.Time) func() (start time.Time,

var weekdays []time.Weekday
for _, d := range w.Weekdays {
if p, ok := parseWeekday(d); ok {
if p, ok := ParseWeekday(d); ok {
weekdays = append(weekdays, p)
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func (m *ClusterMaintenanceConfigV1) CheckAndSetDefaults() error {
}

for _, day := range m.Spec.AgentUpgrades.Weekdays {
if _, ok := parseWeekday(day); !ok {
if _, ok := ParseWeekday(day); !ok {
return trace.BadParameter("invalid weekday in agent upgrade window: %q", day)
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/types/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestWeekdayParser(t *testing.T) {
}

for _, tt := range tts {
day, ok := parseWeekday(tt.input)
day, ok := ParseWeekday(tt.input)
if tt.fail {
require.False(t, ok)
continue
Expand Down
4 changes: 4 additions & 0 deletions lib/autoupdate/rollout/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ func NewController(client Client, log *slog.Logger, clock clockwork.Clock) (*Con
if clock == nil {
return nil, trace.BadParameter("missing clock")
}

return &Controller{
clock: clock,
log: log,
reconciler: reconciler{
clt: client,
log: log,
rolloutStrategies: []rolloutStrategy{
// TODO(hugoShaka): add the strategies here as we implement them
},
},
}, nil
}
Expand Down
Loading

0 comments on commit 3ac5109

Please sign in to comment.