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

Add token file watcher #979

Open
wants to merge 70 commits into
base: v3
Choose a base branch
from
Open

Add token file watcher #979

wants to merge 70 commits into from

Conversation

sean-breen
Copy link
Contributor

Proposed changes

  • Add a new watcher service CredentialWatcherService which will initially monitor the file pointed to by tokenpath option in agent conf.
  • When a write is detected to any of the files being watched, this will trigger a restart of the gRPC connection to the control plane. It also resets the FIle and Command Service clients to use this new connection.
  • During the reset, the Agent may become unavailable for a moment while the gRPC connection is being re-initiated.
  • Once the health message is received, the dataplane status should return to being available.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • I have run make install-tools and have attached any dependency changes to this pull request
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes
  • If applicable, I have updated any relevant documentation (README.md)
  • If applicable, I have tested my cross-platform changes on Ubuntu 22, Redhat 8, SUSE 15 and FreeBSD 13

@sean-breen sean-breen requested a review from a team as a code owner February 13, 2025 10:36
@github-actions github-actions bot added the chore Pull requests for routine tasks label Feb 13, 2025
internal/command/command_plugin_test.go Outdated Show resolved Hide resolved
internal/command/command_service.go Outdated Show resolved Hide resolved
internal/command/command_service.go Outdated Show resolved Hide resolved
func (w *Watcher) monitorWatchers(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case message := <-w.credentialUpdatesChannel:
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this watcher also need to be stopped during a config apply ? Or check if a config apply is in progress ?

@aphralG
Copy link
Contributor

aphralG commented Feb 19, 2025

Could the token path be added to the full config test internal/config/config_test.go

func (cp *CommandPlugin) processConnectionReset(ctx context.Context, msg *bus.Message) {
slog.DebugContext(ctx, "Command plugin received connection reset")
if newConnection, ok := msg.Data.(grpc.GrpcConnectionInterface); ok {
if !cp.commandService.IsConnected() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If its not connected should we still update the command service with the new connection & client?

internal/command/command_plugin.go Outdated Show resolved Hide resolved
internal/file/file_plugin.go Outdated Show resolved Hide resolved
@@ -212,7 +212,7 @@ func TestGrpc_Reconnection(t *testing.T) {
require.NoError(t, err)
mockManagementPlaneAPIAddress = net.JoinHostPort(ipAddress, ports["9093/tcp"][0].HostPort)

time.Sleep(5 * time.Second)
time.Sleep(10 * time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

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

internal/watcher/credentials/credential_watcher_service.go Outdated Show resolved Hide resolved
internal/watcher/credentials/credential_watcher_service.go Outdated Show resolved Hide resolved
internal/watcher/credentials/credential_watcher_service.go Outdated Show resolved Hide resolved
)

const (
Create = fsnotify.Create
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these constants 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.

Yes, they're used in isEventSkippable to check the type of the incoming FSNotify event

func isEventSkippable(event fsnotify.Event) bool {

internal/watcher/watcher_plugin.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Pull requests for routine tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants