-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
🐛 (API - External Plugins): Fix external plugin discovery on Linux #3247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -171,26 +171,44 @@ func parseExternalPluginArgs() (args []string) { | |||||
return args | ||||||
} | ||||||
|
||||||
// isHostSupported checks whether the host system is supported or not. | ||||||
func isHostSupported(host string) bool { | ||||||
for _, platform := range supportedPlatforms { | ||||||
if host == platform { | ||||||
return true | ||||||
} | ||||||
} | ||||||
return false | ||||||
} | ||||||
|
||||||
// getPluginsRoot detects the host system and gets the plugins root based on the host. | ||||||
func getPluginsRoot(host string) (pluginsRoot string, err error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /hold
Suggested change
Can we first remove the return since it is not used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @camilamacedo86 this function is assigned to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is fine as it is . We can re-check in a follow up either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you @camilamacedo86, always happy to help! |
||||||
if !isHostSupported(host) { | ||||||
// freebsd, openbsd, windows... | ||||||
return "", fmt.Errorf("host not supported: %v", host) | ||||||
} | ||||||
|
||||||
pluginsRelativePath := filepath.Join("kubebuilder", "plugins") | ||||||
if xdgHome := os.Getenv("XDG_CONFIG_HOME"); xdgHome != "" { | ||||||
return filepath.Join(xdgHome, pluginsRelativePath), nil | ||||||
} | ||||||
|
||||||
switch host { | ||||||
case "darwin": | ||||||
logrus.Debugf("Detected host is macOS.") | ||||||
pluginsRoot = filepath.Join("Library", "Application Support", "kubebuilder", "plugins") | ||||||
pluginsRoot = filepath.Join("Library", "Application Support", pluginsRelativePath) | ||||||
case "linux": | ||||||
logrus.Debugf("Detected host is Linux.") | ||||||
pluginsRoot = filepath.Join(".config", "kubebuilder", "plugins") | ||||||
default: | ||||||
// freebsd, openbsd, windows... | ||||||
return "", fmt.Errorf("Host not supported: %v", host) | ||||||
pluginsRoot = filepath.Join(".config", pluginsRelativePath) | ||||||
} | ||||||
userHomeDir, err := getHomeDir() | ||||||
|
||||||
userHomeDir, err := os.UserHomeDir() | ||||||
if err != nil { | ||||||
return "", fmt.Errorf("error retrieving home dir: %v", err) | ||||||
} | ||||||
pluginsRoot = filepath.Join(userHomeDir, pluginsRoot) | ||||||
|
||||||
return pluginsRoot, nil | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method expects a return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the reason I have replaced There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do not return this values then we should remove them from the signature. |
||||||
return | ||||||
} | ||||||
|
||||||
// DiscoverExternalPlugins discovers the external plugins in the plugins root directory | ||||||
|
@@ -286,16 +304,3 @@ func DiscoverExternalPlugins(fs afero.Fs) (ps []plugin.Plugin, err error) { | |||||
func isPluginExectuable(mode fs.FileMode) bool { | ||||||
return mode&0111 != 0 | ||||||
} | ||||||
|
||||||
// getHomeDir returns $XDG_CONFIG_HOME if set, otherwise $HOME. | ||||||
func getHomeDir() (string, error) { | ||||||
var err error | ||||||
xdgHome := os.Getenv("XDG_CONFIG_HOME") | ||||||
if xdgHome == "" { | ||||||
xdgHome, err = os.UserHomeDir() | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
} | ||||||
return xdgHome, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evansheng @rashmigottipati could you please give a hand to review this one?