Skip to content

Commit

Permalink
fix: use embedded when command path not found (#371)
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan authored Jun 27, 2024
1 parent f39bd94 commit cf9d488
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/jobs/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (
k8sCommandFolder = "kubernetes"
configCommandsFolder = "config"

commandPath = "commands/kubernetes"
configPath = "commands/config"
k8sFsCommandPath = "commands/kubernetes"
configFsCommandPath = "commands/config"
)

type Collector interface {
Expand Down Expand Up @@ -393,7 +393,7 @@ func loadCommands(paths []string, AddCheckFunc AddChecks) (map[string][]any, map
func getEmbeddedCommands(commandsFileSystem embed.FS, nodeConfigFileSystem embed.FS, AddCheckFunc AddChecks) (map[string][]any, map[string]string) {
commands := make(map[string][]any)
configs := make(map[string]string)
err := fs.WalkDir(commandsFileSystem, commandPath, func(path string, d fs.DirEntry, err error) error {
err := fs.WalkDir(commandsFileSystem, k8sFsCommandPath, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand All @@ -419,7 +419,7 @@ func getEmbeddedCommands(commandsFileSystem embed.FS, nodeConfigFileSystem embed
if err != nil {
return map[string][]any{}, map[string]string{}
}
err = fs.WalkDir(nodeConfigFileSystem, configPath, func(path string, d fs.DirEntry, err error) error {
err = fs.WalkDir(nodeConfigFileSystem, configFsCommandPath, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand Down Expand Up @@ -558,14 +558,14 @@ func (jb *jobCollector) GetCollectorArgs() (CollectorArgs, error) {
var configMap map[string]string
var commandMap map[string][]any
if len(jb.specCommandIds) > 0 {
if len(commandPath) > 0 {
if len(jb.commandPaths) > 0 {
commandMap, configMap = loadCommands(jb.commandPaths, AddChecksByCheckId)
} else {
commandMap, configMap = getEmbeddedCommands(jb.commandsFileSystem, jb.nodeConfigFileSystem, AddChecksByCheckId)
}
nodeCommands = filterCommandBySpecId(commandMap, jb.specCommandIds)
} else {
if len(commandPath) > 0 {
if len(jb.commandPaths) > 0 {
commandMap, configMap = loadCommands(jb.commandPaths, AddChecksByPlatform)
} else {
commandMap, configMap = getEmbeddedCommands(jb.commandsFileSystem, jb.nodeConfigFileSystem, AddChecksByPlatform)
Expand Down

0 comments on commit cf9d488

Please sign in to comment.