-
Notifications
You must be signed in to change notification settings - Fork 94
Update credential watcher to allow second credential watcher #1132
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
base: add-read-only-file-plugin
Are you sure you want to change the base?
Update credential watcher to allow second credential watcher #1132
Conversation
@@ -29,55 +32,74 @@ var emptyEvent = fsnotify.Event{ | |||
|
|||
type CredentialUpdateMessage struct { | |||
CorrelationID slog.Attr | |||
Conn *grpc.GrpcConnection | |||
SeverType command.ServerType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServerType
ch <- CredentialUpdateMessage{CorrelationID: logger.CorrelationIDAttr(newCtx)} | ||
ch <- CredentialUpdateMessage{ | ||
CorrelationID: logger.CorrelationIDAttr(newCtx), | ||
SeverType: cws.serverType, Conn: conn, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SeverType: cws.serverType, Conn: conn, | |
SeverType: cws.serverType, | |
Conn: conn, |
@@ -29,55 +32,74 @@ var emptyEvent = fsnotify.Event{ | |||
|
|||
type CredentialUpdateMessage struct { | |||
CorrelationID slog.Attr | |||
Conn *grpc.GrpcConnection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conn *grpc.GrpcConnection | |
grpcConnection *grpc.GrpcConnection |
commandSever := cws.agentConfig.Command | ||
|
||
if cws.serverType == model.Auxiliary { | ||
commandSever = cws.agentConfig.AuxiliaryCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commandServer
?
return | ||
} | ||
|
||
cws.watcher = watcher | ||
|
||
cws.watchFiles(ctx, credentialPaths(cws.agentConfig)) | ||
cws.watcherMutex.Lock() | ||
commandSever := cws.agentConfig.Command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commandServer
?
commandSever = cws.agentConfig.AuxiliaryCommand | ||
} | ||
|
||
cws.watchFiles(newCtx, credentialPaths(commandSever)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
commandSever = cws.agentConfig.AuxiliaryCommand | ||
} | ||
|
||
conn, err := grpc.NewGrpcConnection(newCtx, cws.agentConfig, commandSever) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -122,11 +122,13 @@ func FileMode(mode string) os.FileMode { | |||
func GenerateConfigVersion(fileSlice []*mpi.File) string { | |||
var hashes string | |||
|
|||
slices.SortFunc(fileSlice, func(a, b *mpi.File) int { | |||
files := make([]*mpi.File, len(fileSlice)) | |||
copy(files, fileSlice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reason for the copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition, files were being sorted while the other file plugin was reading them. I could use a lock but wasn't sure if locaking the nginxConfigContext files for everything was the best idea so thought copy would be better. Can change it though
case message := <-w.credentialUpdatesChannel: | ||
slog.DebugContext(ctx, "Received credential update event") | ||
newCtx := context.WithValue(ctx, logger.CorrelationIDContextKey, message.CorrelationID) | ||
case message := <-w.commandCredentialUpdatesChannel: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code being duplicated here?
Seems like the same code can be used for both messages coming from commandCredentialUpdatesChannel
or auxiliaryCredentialUpdatesChannel
.
Proposed changes
Updated credential watcher to allow a second credential watcher to be started to monitor auxiliary command sever.
Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)