Skip to content

Commit 4e78539

Browse files
committed
Merge branch 'main' into add-govulncheck
2 parents 1a275bf + 5f2f6b3 commit 4e78539

File tree

6 files changed

+141
-31
lines changed

6 files changed

+141
-31
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ require (
8181
go.uber.org/multierr v1.11.0
8282
go.uber.org/zap v1.27.0
8383
golang.org/x/mod v0.29.0
84-
golang.org/x/sync v0.17.0
84+
golang.org/x/sync v0.18.0
8585
google.golang.org/protobuf v1.36.10
8686
)
8787

@@ -382,9 +382,9 @@ require (
382382
github.com/vardius/message-bus v1.1.5
383383
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0 // indirect
384384
go.opentelemetry.io/otel/sdk/metric v1.38.0
385-
golang.org/x/crypto v0.43.0 // indirect
386-
golang.org/x/net v0.46.0 // indirect
387-
golang.org/x/sys v0.37.0 // indirect
388-
golang.org/x/text v0.30.0 // indirect
385+
golang.org/x/crypto v0.45.0 // indirect
386+
golang.org/x/net v0.47.0 // indirect
387+
golang.org/x/sys v0.38.0 // indirect
388+
golang.org/x/text v0.31.0 // indirect
389389
google.golang.org/grpc v1.76.0
390390
)

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
10071007
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
10081008
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
10091009
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
1010-
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
1011-
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
1010+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
1011+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
10121012
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
10131013
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
10141014
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -1053,8 +1053,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
10531053
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
10541054
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
10551055
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
1056-
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
1057-
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
1056+
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
1057+
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
10581058
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
10591059
golang.org/x/oauth2 v0.32.0 h1:jsCblLleRMDrxMN29H3z/k1KliIvpLgCkE6R8FXXNgY=
10601060
golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
@@ -1070,8 +1070,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
10701070
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
10711071
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
10721072
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
1073-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
1074-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
1073+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
1074+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
10751075
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
10761076
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
10771077
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1101,8 +1101,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11011101
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11021102
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11031103
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1104-
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
1105-
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
1104+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
1105+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
11061106
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
11071107
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 h1:LvzTn0GQhWuvKH/kVRS3R3bVAsdQWI7hvfLHGgh9+lU=
11081108
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8/go.mod h1:Pi4ztBfryZoJEkyFTI5/Ocsu2jXyDr6iSdgJiYE/uwE=
@@ -1114,8 +1114,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
11141114
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
11151115
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
11161116
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
1117-
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
1118-
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
1117+
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
1118+
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
11191119
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
11201120
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
11211121
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
@@ -1125,8 +1125,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
11251125
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
11261126
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
11271127
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
1128-
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
1129-
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
1128+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
1129+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
11301130
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
11311131
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
11321132
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
// Regular expression to match invalid characters in paths.
4848
// It matches whitespace, control characters, non-printable characters, and specific Unicode characters.
4949
regexInvalidPath = "\\s|[[:cntrl:]]|[[:space:]]|[[^:print:]]|ㅤ|\\.\\.|\\*"
50-
regexLabelPattern = "^[a-zA-Z0-9]([a-zA-Z0-9-_]{0,254}[a-zA-Z0-9])?$"
50+
regexLabelPattern = "^[a-zA-Z0-9]([a-zA-Z0-9-_.]{0,254}[a-zA-Z0-9])?$"
5151
)
5252

5353
var viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))

internal/config/config_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,56 @@ func TestValidateLabel(t *testing.T) {
15601560
input: "label 123",
15611561
expected: false,
15621562
},
1563+
{
1564+
name: "Test 9: Valid label - cluster id",
1565+
input: "73623aef-1d5b-4f6b-b73d-5561c36851cc",
1566+
expected: true,
1567+
},
1568+
{
1569+
name: "Test 10: Valid label - installation name",
1570+
input: "my-release-nginx-ingress-controller",
1571+
expected: true,
1572+
},
1573+
{
1574+
name: "Test 11: Valid label - product",
1575+
input: "nic",
1576+
expected: true,
1577+
},
1578+
{
1579+
name: "Test 12: Valid label - version",
1580+
input: "5.3.0",
1581+
expected: true,
1582+
},
1583+
{
1584+
name: "Test 13: Valid label - version snapshot",
1585+
input: "5.3.0-SNAPSHOT",
1586+
expected: true,
1587+
},
1588+
{
1589+
name: "Test 14: Invalid label - newlines",
1590+
input: "label-2\n\n",
1591+
expected: false,
1592+
},
1593+
{
1594+
name: "Test 15: Valid label - only numbers",
1595+
input: "1234567",
1596+
expected: true,
1597+
},
1598+
{
1599+
name: "Test 16: Invalid label - start and end with .",
1600+
input: ".label.",
1601+
expected: false,
1602+
},
1603+
{
1604+
name: "Test 17: Invalid label - lots of blank spaces",
1605+
input: " label",
1606+
expected: false,
1607+
},
1608+
{
1609+
name: "Test 18: Invalid label - start and end with blank space",
1610+
input: " label ",
1611+
expected: false,
1612+
},
15631613
}
15641614

15651615
for _, tt := range tests {

internal/file/file_manager_service.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
177177

178178
fms.fileActions = diffFiles
179179

180+
slog.DebugContext(ctx, "Executing config apply file actions", "actions", diffFiles)
181+
180182
rollbackTempFilesErr := fms.backupFiles(ctx)
181183
if rollbackTempFilesErr != nil {
182184
return model.Error, rollbackTempFilesErr
@@ -382,24 +384,58 @@ func (fms *FileManagerService) DetermineFileActions(
382384
for _, modifiedFile := range modifiedFiles {
383385
fileName := modifiedFile.File.GetFileMeta().GetName()
384386
currentFile, ok := filesMap[fileName]
385-
// default to unchanged action
386387
modifiedFile.Action = model.Unchanged
387388

388-
// if file is unmanaged, action is set to unchanged so file is skipped when performing actions
389+
// If file is unmanaged, action is set to unchanged so file is skipped when performing actions.
389390
if modifiedFile.File.GetUnmanaged() {
390391
slog.DebugContext(ctx, "Skipping unmanaged file updates", "file_name", fileName)
391392
continue
392393
}
393-
// if file doesn't exist in the current files, file has been added
394-
// set file action
395-
if _, statErr := os.Stat(fileName); errors.Is(statErr, os.ErrNotExist) {
394+
395+
// If file currently exists on disk, is being tracked in manifest and file hash is different.
396+
// Treat it as a file update.
397+
if ok && modifiedFile.File.GetFileMeta().GetHash() != currentFile.GetFileMeta().GetHash() {
398+
slog.DebugContext(ctx, "Tracked file requires updating", "file_name", fileName)
399+
modifiedFile.Action = model.Update
400+
fileDiff[fileName] = modifiedFile
401+
402+
continue
403+
}
404+
405+
fileStats, statErr := os.Stat(fileName)
406+
407+
// If file doesn't exist on disk.
408+
// Treat it as adding a new file.
409+
if errors.Is(statErr, os.ErrNotExist) {
410+
slog.DebugContext(ctx, "New untracked file needs to be created", "file_name", fileName)
396411
modifiedFile.Action = model.Add
397412
fileDiff[fileName] = modifiedFile
398413

399414
continue
400-
// if file currently exists and file hash is different, file has been updated
401-
// copy contents, set file action
402-
} else if ok && modifiedFile.File.GetFileMeta().GetHash() != currentFile.GetFileMeta().GetHash() {
415+
}
416+
417+
// If there is an error other than not existing, return that error.
418+
if statErr != nil {
419+
return nil, fmt.Errorf("unable to stat file %s: %w", fileName, statErr)
420+
}
421+
422+
// If there is a directory with the same name, return an error.
423+
if fileStats.IsDir() {
424+
return nil, fmt.Errorf(
425+
"unable to create file %s since a directory with the same name already exists",
426+
fileName,
427+
)
428+
}
429+
430+
// If file already exists on disk but is not being tracked in manifest and the file hash is different.
431+
// Treat it as a file update.
432+
metadataOfFileOnDisk, err := files.FileMeta(fileName)
433+
if err != nil {
434+
return nil, fmt.Errorf("unable to get file metadata for %s: %w", fileName, err)
435+
}
436+
437+
if metadataOfFileOnDisk.GetHash() != modifiedFile.File.GetFileMeta().GetHash() {
438+
slog.DebugContext(ctx, "Untracked file requires updating", "file_name", fileName)
403439
modifiedFile.Action = model.Update
404440
fileDiff[fileName] = modifiedFile
405441
}

internal/file/file_manager_service_test.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,12 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
763763
modifiedFiles: map[string]*model.FileCache{
764764
addTestFile.Name(): {
765765
File: &mpi.File{
766-
FileMeta: protos.FileMeta(addTestFile.Name(), files.GenerateHash(fileContent)),
766+
FileMeta: protos.FileMeta(addTestFile.Name(), files.GenerateHash(addFileContent)),
767767
},
768768
},
769769
updateTestFile.Name(): {
770770
File: &mpi.File{
771-
FileMeta: protos.FileMeta(updateTestFile.Name(), files.GenerateHash(fileContent)),
771+
FileMeta: protos.FileMeta(updateTestFile.Name(), files.GenerateHash(updatedFileContent)),
772772
},
773773
},
774774
deleteTestFile.Name(): {
@@ -782,10 +782,10 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
782782
FileMeta: protos.FileMeta(deleteTestFile.Name(), files.GenerateHash(fileContent)),
783783
},
784784
updateTestFile.Name(): {
785-
FileMeta: protos.FileMeta(updateTestFile.Name(), files.GenerateHash(fileContent)),
785+
FileMeta: protos.FileMeta(updateTestFile.Name(), files.GenerateHash(updatedFileContent)),
786786
},
787787
addTestFile.Name(): {
788-
FileMeta: protos.FileMeta(addTestFile.Name(), files.GenerateHash(fileContent)),
788+
FileMeta: protos.FileMeta(addTestFile.Name(), files.GenerateHash(addFileContent)),
789789
},
790790
},
791791
expectedCache: make(map[string]*model.FileCache),
@@ -805,6 +805,24 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
805805
expectedContent: make(map[string][]byte),
806806
expectedError: nil,
807807
},
808+
{
809+
name: "Test 4: File is actually a directory",
810+
allowedDirs: []string{tempDir},
811+
modifiedFiles: map[string]*model.FileCache{
812+
tempDir: {
813+
File: &mpi.File{
814+
FileMeta: protos.FileMeta(tempDir, files.GenerateHash(fileContent)),
815+
},
816+
},
817+
},
818+
currentFiles: make(map[string]*mpi.File),
819+
expectedCache: map[string]*model.FileCache(nil),
820+
expectedContent: make(map[string][]byte),
821+
expectedError: fmt.Errorf(
822+
"unable to create file %s since a directory with the same name already exists",
823+
tempDir,
824+
),
825+
},
808826
}
809827

810828
for _, test := range tests {
@@ -828,7 +846,13 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
828846
test.currentFiles,
829847
test.modifiedFiles,
830848
)
831-
require.NoError(tt, fileActionErr)
849+
850+
if test.expectedError != nil {
851+
require.EqualError(tt, fileActionErr, test.expectedError.Error())
852+
} else {
853+
require.NoError(tt, fileActionErr)
854+
}
855+
832856
assert.Equal(tt, test.expectedCache, diff)
833857
})
834858
}

0 commit comments

Comments
 (0)