-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run autoupdate_agent_rollout controller
- Loading branch information
Showing
6 changed files
with
169 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package rolloutcontroller | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"time" | ||
|
||
"github.com/jonboulle/clockwork" | ||
|
||
"github.com/gravitational/teleport/api/utils/retryutils" | ||
"github.com/gravitational/teleport/lib/utils/interval" | ||
) | ||
|
||
const ( | ||
reconcilerPeriod = time.Minute | ||
) | ||
|
||
// Controller wakes up every minute to reconcile the autoupdate_agent_rollout resource. | ||
// See the reconciler godoc for more details about the reconciliation process. | ||
// We currently wake up every minute, in the future we might decide to also watch for events | ||
// (from autoupdate_config and autoupdate_version changefeed) to react faster. | ||
type Controller struct { | ||
reconciler reconciler | ||
clock clockwork.Clock | ||
log *slog.Logger | ||
} | ||
|
||
// New creates a new Controller for the autoupdate_agent_rollout kind. | ||
func New(client Client, log *slog.Logger, clock clockwork.Clock) *Controller { | ||
return &Controller{ | ||
clock: clock, | ||
log: log, | ||
reconciler: reconciler{ | ||
clt: client, | ||
log: log, | ||
}, | ||
} | ||
} | ||
|
||
// Run the autoupdate_agent_rollout controller. This function returns only when its context is cancelled. | ||
func (c *Controller) Run(ctx context.Context) error { | ||
config := interval.Config{ | ||
Duration: reconcilerPeriod, | ||
FirstDuration: reconcilerPeriod, | ||
Jitter: retryutils.SeventhJitter, | ||
Clock: c.clock, | ||
} | ||
ticker := interval.New(config) | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
c.log.InfoContext(ctx, "Stopping autoupdate_agent_rollout controller", "reason", ctx.Err()) | ||
return ctx.Err() | ||
case <-ticker.Next(): | ||
c.log.DebugContext(ctx, "Reconciling autoupdate_agent_rollout") | ||
err := c.reconciler.reconcile(ctx) | ||
if err != nil { | ||
c.log.ErrorContext(ctx, "Failed to reconcile autoudpate_agent_controller", "error", err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters