Skip to content

Commit

Permalink
Merge pull request #1939 from headlamp-k8s/remove-static-plugins
Browse files Browse the repository at this point in the history
backend: config: Change default plugins dir
  • Loading branch information
joaquimrocha authored May 8, 2024
2 parents e3b1b7a + e0b66e5 commit c03ca0b
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,17 @@ func flagset() *flag.FlagSet {

// Gets the default plugins-dir depending on platform.
func defaultPluginDir() string {
// These are the folders we use for the default plugin-dir.
// - the passed in pluginDir if it's not empty.
// - "./.plugins" if it exists.
// This is the folder we use for the default plugin-dir:
// - ~/.config/Headlamp/plugins exists or it can be made
// - "./.plugins" if the ~/.config/Headlamp/plugins can't be made.
// Windows: %APPDATA%\Headlamp\Config\plugins
// (for example, C:\Users\USERNAME\AppData\Roaming\Headlamp\Config\plugins)
pluginDirDefault := "./.plugins"

if folderExists(pluginDirDefault) {
return pluginDirDefault
}

// https://www.npmjs.com/package/env-paths
// https://pkg.go.dev/os#UserConfigDir
userConfigDir, err := os.UserConfigDir()
if err != nil {
logger.Log(logger.LevelError, nil, err, "getting user config dir")

return pluginDirDefault
return ""
}

pluginsConfigDir := filepath.Join(userConfigDir, "Headlamp", "plugins")
Expand All @@ -207,22 +198,12 @@ func defaultPluginDir() string {
if err != nil {
logger.Log(logger.LevelError, nil, err, "creating plugins directory")

return pluginDirDefault
return ""
}

return pluginsConfigDir
}

// folderExists(path) returns true if the folder exists.
func folderExists(path string) bool {
info, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}

return info.IsDir()
}

func GetDefaultKubeConfigPath() string {
user, err := user.Current()
if err != nil {
Expand Down

0 comments on commit c03ca0b

Please sign in to comment.