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

fix 🐛(filesystem store): ignore path that do not exist instead of thr… #135

Merged
Merged
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
21 changes: 16 additions & 5 deletions pkg/store/kubeconfig_store_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import (
"strings"
"sync"

"github.com/danielfoehrkn/kubeswitch/types"
"github.com/karrick/godirwalk"
"github.com/sirupsen/logrus"

"github.com/danielfoehrkn/kubeswitch/types"
)

func NewFilesystemStore(kubeconfigName string, kubeconfigStore types.KubeconfigStore) (*FilesystemStore, error) {
func NewFilesystemStore(
kubeconfigName string,
kubeconfigStore types.KubeconfigStore,
) (*FilesystemStore, error) {
return &FilesystemStore{
Logger: logrus.New().WithField("store", types.StoreKindFilesystem),
KubeconfigStore: kubeconfigStore,
Expand Down Expand Up @@ -80,7 +84,11 @@ func (s *FilesystemStore) StartSearch(channel chan SearchResult) {
wg.Wait()
}

func (s *FilesystemStore) searchDirectory(wg *sync.WaitGroup, searchPath string, channel chan SearchResult) {
func (s *FilesystemStore) searchDirectory(
wg *sync.WaitGroup,
searchPath string,
channel chan SearchResult,
) {
defer wg.Done()

if err := godirwalk.Walk(searchPath, &godirwalk.Options{
Expand Down Expand Up @@ -138,7 +146,7 @@ func (s *FilesystemStore) VerifyKubeconfigPaths() error {

info, err := os.Stat(kubeconfigPath)
if os.IsNotExist(err) {
return fmt.Errorf("the configured kubeconfig directory %q does not exist", path)
continue
} else if err != nil {
return fmt.Errorf("failed to read from the configured kubeconfig directory %q: %v", path, err)
}
Expand All @@ -151,7 +159,10 @@ func (s *FilesystemStore) VerifyKubeconfigPaths() error {
}

if len(validKubeconfigDirectories) == 0 && len(validKubeconfigFilepaths) == 0 {
return fmt.Errorf("none of the %d specified kubeconfig path(s) exist. Either specifiy an existing path via flag '--kubeconfig-path' or in the switch config file", len(s.KubeconfigStore.Paths))
return fmt.Errorf(
"none of the %d specified kubeconfig path(s) exist. Either specifiy an existing path via flag '--kubeconfig-path' or in the switch config file",
len(s.KubeconfigStore.Paths),
)
}
s.kubeconfigDirectories = validKubeconfigDirectories
s.kubeconfigFilepaths = validKubeconfigFilepaths
Expand Down
Loading