mirror of https://github.com/portainer/portainer
fix(edge): edge stack pending when yaml file is under same root folder of edge configs [BE-11620] (#447)
parent
1b83542d41
commit
5d568a3f32
|
@ -44,11 +44,10 @@ func deduplicate(dirEntries []DirEntry) []DirEntry {
|
||||||
|
|
||||||
// FilterDirForPerDevConfigs filers the given dirEntries, returns entries for the given device
|
// FilterDirForPerDevConfigs filers the given dirEntries, returns entries for the given device
|
||||||
// For given configPath A/B/C, return entries:
|
// For given configPath A/B/C, return entries:
|
||||||
// 1. all entries outside of dir A
|
// 1. all entries outside of dir A/B/C
|
||||||
// 2. dir entries A, A/B, A/B/C
|
// 2. For filterType file:
|
||||||
// 3. For filterType file:
|
|
||||||
// file entries: A/B/C/<deviceName> and A/B/C/<deviceName>.*
|
// file entries: A/B/C/<deviceName> and A/B/C/<deviceName>.*
|
||||||
// 4. For filterType dir:
|
// 3. For filterType dir:
|
||||||
// dir entry: A/B/C/<deviceName>
|
// dir entry: A/B/C/<deviceName>
|
||||||
// all entries: A/B/C/<deviceName>/*
|
// all entries: A/B/C/<deviceName>/*
|
||||||
func FilterDirForPerDevConfigs(dirEntries []DirEntry, deviceName, configPath string, filterType portainer.PerDevConfigsFilterType) []DirEntry {
|
func FilterDirForPerDevConfigs(dirEntries []DirEntry, deviceName, configPath string, filterType portainer.PerDevConfigsFilterType) []DirEntry {
|
||||||
|
@ -66,12 +65,7 @@ func FilterDirForPerDevConfigs(dirEntries []DirEntry, deviceName, configPath str
|
||||||
func shouldIncludeEntry(dirEntry DirEntry, deviceName, configPath string, filterType portainer.PerDevConfigsFilterType) bool {
|
func shouldIncludeEntry(dirEntry DirEntry, deviceName, configPath string, filterType portainer.PerDevConfigsFilterType) bool {
|
||||||
|
|
||||||
// Include all entries outside of dir A
|
// Include all entries outside of dir A
|
||||||
if !isInConfigRootDir(dirEntry, configPath) {
|
if !isInConfigDir(dirEntry, configPath) {
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include dir entries A, A/B, A/B/C
|
|
||||||
if isParentDir(dirEntry, configPath) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,21 +84,9 @@ func shouldIncludeEntry(dirEntry DirEntry, deviceName, configPath string, filter
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInConfigRootDir(dirEntry DirEntry, configPath string) bool {
|
func isInConfigDir(dirEntry DirEntry, configPath string) bool {
|
||||||
// get the first element of the configPath
|
// return true if entry name starts with "A/B"
|
||||||
rootDir := strings.Split(configPath, string(os.PathSeparator))[0]
|
return strings.HasPrefix(dirEntry.Name, appendTailSeparator(configPath))
|
||||||
|
|
||||||
// return true if entry name starts with "A/"
|
|
||||||
return strings.HasPrefix(dirEntry.Name, appendTailSeparator(rootDir))
|
|
||||||
}
|
|
||||||
|
|
||||||
func isParentDir(dirEntry DirEntry, configPath string) bool {
|
|
||||||
if dirEntry.IsFile {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// return true for dir entries A, A/B, A/B/C
|
|
||||||
return strings.HasPrefix(appendTailSeparator(configPath), appendTailSeparator(dirEntry.Name))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldIncludeFile(dirEntry DirEntry, deviceName, configPath string) bool {
|
func shouldIncludeFile(dirEntry DirEntry, deviceName, configPath string) bool {
|
||||||
|
|
|
@ -90,3 +90,24 @@ func TestMultiFilterDirForPerDevConfigs(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsInConfigDir(t *testing.T) {
|
||||||
|
f := func(dirEntry DirEntry, configPath string, expect bool) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
actual := isInConfigDir(dirEntry, configPath)
|
||||||
|
assert.Equal(t, expect, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
f(DirEntry{Name: "edge-configs"}, "edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edge-configs_backup"}, "edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edge-configs/standalone-edge-agent-standard"}, "edge-configs", true)
|
||||||
|
f(DirEntry{Name: "parent/edge-configs/"}, "edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edgestacktest"}, "edgestacktest/edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edgestacktest/edgeconfigs-test.yaml"}, "edgestacktest/edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edgestacktest/file1.conf"}, "edgestacktest/edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edgeconfigs-test.yaml"}, "edgestacktest/edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edgestacktest/edge-configs"}, "edgestacktest/edge-configs", false)
|
||||||
|
f(DirEntry{Name: "edgestacktest/edge-configs/standalone-edge-agent-async"}, "edgestacktest/edge-configs", true)
|
||||||
|
f(DirEntry{Name: "edgestacktest/edge-configs/abc.txt"}, "edgestacktest/edge-configs", true)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue