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 unmanaged option to file proto #964

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
366 changes: 188 additions & 178 deletions api/grpc/mpi/v1/files.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/grpc/mpi/v1/files.pb.validate.go

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

4 changes: 3 additions & 1 deletion api/grpc/mpi/v1/files.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ message File {
}
// Optional action
optional FileAction action = 2;
// Unmanaged files will not be modified
bool unmanaged = 3;
}

// Represents the get file request
Expand Down Expand Up @@ -290,4 +292,4 @@ message AttributeTypeAndValue {

// The value associated with the attribute.
string value = 2 [(buf.validate.field).string.min_len = 1];
}
}
1 change: 1 addition & 0 deletions docs/proto/protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Represents meta data about a file
| ----- | ---- | ----- | ----------- |
| file_meta | [FileMeta](#mpi-v1-FileMeta) | | Meta information about the file, the name (including path) and hash |
| action | [File.FileAction](#mpi-v1-File-FileAction) | optional | Optional action |
| unmanaged | [bool](#bool) | | Unmanaged files will not be modified |



Expand Down
5 changes: 5 additions & 0 deletions internal/file/file_manager_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ func (fms *FileManagerService) DetermineFileActions(currentFiles, modifiedFiles
currentFile, ok := currentFiles[file.GetFileMeta().GetName()]
// default to unchanged action
file.Action = &unchangedAction

// if file is unmanaged, action is set to unchanged so file is skipped when performing actions
if file.GetUnmanaged() {
continue
}
// if file doesn't exist in the current files, file has been added
// set file action
if !ok {
Expand Down
14 changes: 14 additions & 0 deletions internal/file/file_manager_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {

addTestFileName := tempDir + "/nginx_add.conf"

unmanagedFile := helpers.CreateFileWithErrorCheck(t, tempDir, "nginx_unmanaged.conf")
defer helpers.RemoveFileWithErrorCheck(t, unmanagedFile.Name())
unmanagedFileContent := []byte("test unmanaged file")
unmanagedErr := os.WriteFile(unmanagedFile.Name(), unmanagedFileContent, 0o600)
require.NoError(t, unmanagedErr)

tests := []struct {
expectedError error
modifiedFiles map[string]*mpi.File
Expand All @@ -479,6 +485,10 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
updateTestFile.Name(): {
FileMeta: protos.FileMeta(updateTestFile.Name(), files.GenerateHash(updatedFileContent)),
},
unmanagedFile.Name(): {
FileMeta: protos.FileMeta(unmanagedFile.Name(), files.GenerateHash(unmanagedFileContent)),
Unmanaged: true,
},
},
currentFiles: map[string]*mpi.File{
deleteTestFile.Name(): {
Expand All @@ -487,6 +497,10 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
updateTestFile.Name(): {
FileMeta: protos.FileMeta(updateTestFile.Name(), files.GenerateHash(fileContent)),
},
unmanagedFile.Name(): {
FileMeta: protos.FileMeta(unmanagedFile.Name(), files.GenerateHash(fileContent)),
Unmanaged: true,
},
},
expectedCache: map[string]*mpi.File{
deleteTestFile.Name(): {
Expand Down