Skip to content

Commit 35c4645

Browse files
committed
PPC: ghw: filter out namespaces dir
The previous code fails to run PPC when there is a namespace that has a suffix `nodes`. ensure filtering the namespace directory to allow PPC to work when such namespaces exist. Signed-off-by: Shereen Haj <shajmakh@redhat.com>
1 parent dcc17ff commit 35c4645

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pkg/performanceprofile/profilecreator/ghwhandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
func NewGHWHandler(mustGatherDirPath string, node *v1.Node) (*GHWHandler, error) {
3535
nodeName := node.GetName()
3636
nodePathSuffix := path.Join(nodes)
37-
nodepath, err := getMustGatherFullPathsWithFilter(mustGatherDirPath, nodePathSuffix, clusterScopedResources)
37+
nodepath, err := getMustGatherFullPathsWithFilter(mustGatherDirPath, nodePathSuffix, clusterScopedResources, namespaces)
3838
if err != nil {
3939
return nil, fmt.Errorf("can't obtain the node path %s: %v", nodeName, err)
4040
}

pkg/performanceprofile/profilecreator/mustgather.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,26 @@ const (
4242
yamlSuffix = ".yaml"
4343
// nodes defines the subpath, relative to top-level must-gather directory, on which we find node-specific data
4444
nodes = "nodes"
45+
// namespaces defines the subpath, relative to top-level must-gather directory, on which we find openshift namespace-specific data
46+
namespaces = "namespaces"
4547
// sysInfoFileName defines the name of the file where ghw snapshot is stored
4648
sysInfoFileName = "sysinfo.tgz"
4749
// configOCPInfra defines the sub path relative to ClusterScopedResources, on which OCP infrastructure object is
4850
configOCPInfra = "config.openshift.io/infrastructures"
4951
)
5052

51-
func getMustGatherFullPathsWithFilter(mustGatherPath string, suffix string, filter string) (string, error) {
53+
func getMustGatherFullPathsWithFilter(mustGatherPath string, suffix string, filters ...string) (string, error) {
5254
var paths []string
5355

54-
// don't assume directory names, only look for the suffix, filter out files having "filter" in their names
56+
// don't assume directory names, only look for the suffix, filter out files having "filters" in their names
5557
err := filepath.Walk(mustGatherPath, func(path string, info os.FileInfo, err error) error {
5658
if strings.HasSuffix(path, suffix) {
57-
if len(filter) == 0 || !strings.Contains(path, filter) {
58-
paths = append(paths, path)
59+
for _, f := range filters {
60+
if strings.Contains(path, f) {
61+
return nil
62+
}
5963
}
64+
paths = append(paths, path)
6065
}
6166
return nil
6267
})
@@ -68,14 +73,14 @@ func getMustGatherFullPathsWithFilter(mustGatherPath string, suffix string, filt
6873
}
6974
if len(paths) > 1 {
7075
Alert("Multiple matches for the specified must gather directory path: %s and suffix: %s", mustGatherPath, suffix)
71-
return "", fmt.Errorf("Multiple matches for the specified must gather directory path: %s and suffix: %s.\n Expected only one performance-addon-operator-must-gather* directory, please check the must-gather tarball", mustGatherPath, suffix)
76+
return "", fmt.Errorf("multiple matches for the specified must gather directory path: %s and suffix: %s.\n Expected only one performance-addon-operator-must-gather* directory, please check the must-gather tarball", mustGatherPath, suffix)
7277
}
7378
// returning one possible path
7479
return paths[0], err
7580
}
7681

7782
func getMustGatherFullPaths(mustGatherPath string, suffix string) (string, error) {
78-
return getMustGatherFullPathsWithFilter(mustGatherPath, suffix, "")
83+
return getMustGatherFullPathsWithFilter(mustGatherPath, suffix)
7984
}
8085

8186
func getNode(mustGatherDirPath, nodeName string) (*v1.Node, error) {

0 commit comments

Comments
 (0)