@@ -171,26 +171,44 @@ func parseExternalPluginArgs() (args []string) {
171
171
return args
172
172
}
173
173
174
+ // isHostSupported checks whether the host system is supported or not.
175
+ func isHostSupported (host string ) bool {
176
+ for _ , platform := range supportedPlatforms {
177
+ if host == platform {
178
+ return true
179
+ }
180
+ }
181
+ return false
182
+ }
183
+
174
184
// getPluginsRoot detects the host system and gets the plugins root based on the host.
175
185
func getPluginsRoot (host string ) (pluginsRoot string , err error ) {
186
+ if ! isHostSupported (host ) {
187
+ // freebsd, openbsd, windows...
188
+ return "" , fmt .Errorf ("host not supported: %v" , host )
189
+ }
190
+
191
+ pluginsRelativePath := filepath .Join ("kubebuilder" , "plugins" )
192
+ if xdgHome := os .Getenv ("XDG_CONFIG_HOME" ); xdgHome != "" {
193
+ return filepath .Join (xdgHome , pluginsRelativePath ), nil
194
+ }
195
+
176
196
switch host {
177
197
case "darwin" :
178
198
logrus .Debugf ("Detected host is macOS." )
179
- pluginsRoot = filepath .Join ("Library" , "Application Support" , "kubebuilder" , "plugins" )
199
+ pluginsRoot = filepath .Join ("Library" , "Application Support" , pluginsRelativePath )
180
200
case "linux" :
181
201
logrus .Debugf ("Detected host is Linux." )
182
- pluginsRoot = filepath .Join (".config" , "kubebuilder" , "plugins" )
183
- default :
184
- // freebsd, openbsd, windows...
185
- return "" , fmt .Errorf ("Host not supported: %v" , host )
202
+ pluginsRoot = filepath .Join (".config" , pluginsRelativePath )
186
203
}
187
- userHomeDir , err := getHomeDir ()
204
+
205
+ userHomeDir , err := os .UserHomeDir ()
188
206
if err != nil {
189
207
return "" , fmt .Errorf ("error retrieving home dir: %v" , err )
190
208
}
191
209
pluginsRoot = filepath .Join (userHomeDir , pluginsRoot )
192
210
193
- return pluginsRoot , nil
211
+ return
194
212
}
195
213
196
214
// DiscoverExternalPlugins discovers the external plugins in the plugins root directory
@@ -286,16 +304,3 @@ func DiscoverExternalPlugins(fs afero.Fs) (ps []plugin.Plugin, err error) {
286
304
func isPluginExectuable (mode fs.FileMode ) bool {
287
305
return mode & 0111 != 0
288
306
}
289
-
290
- // getHomeDir returns $XDG_CONFIG_HOME if set, otherwise $HOME.
291
- func getHomeDir () (string , error ) {
292
- var err error
293
- xdgHome := os .Getenv ("XDG_CONFIG_HOME" )
294
- if xdgHome == "" {
295
- xdgHome , err = os .UserHomeDir ()
296
- if err != nil {
297
- return "" , err
298
- }
299
- }
300
- return xdgHome , nil
301
- }
0 commit comments