Skip to content

Commit

Permalink
app: backend: Add flag for watching plugins changes
Browse files Browse the repository at this point in the history
This change creates a CLI flag in the backend + desktop for watching
changes to the plugins or their directory.

Stops watching for plugin changes in the container image.

Fixes: #2894

Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
  • Loading branch information
skoeva authored and illume committed Feb 26, 2025
1 parent d5dd926 commit 91ffcee
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ USER headlamp
EXPOSE 4466

ENV HEADLAMP_STATIC_PLUGINS_DIR=/headlamp/static-plugins
ENTRYPOINT ["/headlamp/headlamp-server", "-html-static-dir", "/headlamp/frontend", "-plugins-dir", "/headlamp/plugins"]
ENTRYPOINT ["/headlamp/headlamp-server", "-html-static-dir", "/headlamp/frontend", "-plugins-dir", "/headlamp/plugins", "-watch-plugins-changes", "false"]
7 changes: 7 additions & 0 deletions app/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const args = yargs(hideBin(process.argv))
describe: 'Disable use of GPU. For people who may have buggy graphics drivers',
type: 'boolean',
},
'watch-plugins-changes': {
describe: 'Reloads plugins when there are changes to them or their directory',
type: 'boolean',
},
})
.positional('kubeconfig', {
describe:
Expand Down Expand Up @@ -551,6 +555,9 @@ async function startServer(flags: string[] = []): Promise<ChildProcessWithoutNul
if (!!proxyUrls && proxyUrls.length > 0) {
serverArgs = serverArgs.concat(['--proxy-urls', proxyUrls.join(',')]);
}
if (args.watchPluginsChanges) {
serverArgs.push('--watch-plugins-changes');
}

const bundledPlugins = path.join(process.resourcesPath, '.plugins');

Expand Down
3 changes: 2 additions & 1 deletion backend/cmd/headlamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type HeadlampConfig struct {
insecure bool
enableHelm bool
enableDynamicClusters bool
watchPluginsChanges bool
port uint
kubeConfigPath string
staticDir string
Expand Down Expand Up @@ -355,7 +356,7 @@ func createHeadlampHandler(config *HeadlampConfig) http.Handler {

plugins.PopulatePluginsCache(config.staticPluginDir, config.pluginDir, config.cache)

if !config.useInCluster {
if !config.useInCluster && config.watchPluginsChanges {
// in-cluster mode is unlikely to want reloading plugins.
pluginEventChan := make(chan string)
go plugins.Watch(config.pluginDir, pluginEventChan)
Expand Down
1 change: 1 addition & 0 deletions backend/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func main() {
proxyURLs: strings.Split(conf.ProxyURLs, ","),
enableHelm: conf.EnableHelm,
enableDynamicClusters: conf.EnableDynamicClusters,
watchPluginsChanges: conf.WatchPluginsChanges,
cache: cache,
kubeConfigStore: kubeConfigStore,
multiplexer: multiplexer,
Expand Down
2 changes: 2 additions & 0 deletions backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
EnableHelm bool `koanf:"enable-helm"`
EnableDynamicClusters bool `koanf:"enable-dynamic-clusters"`
ListenAddr string `koanf:"listen-addr"`
WatchPluginsChanges bool `koanf:"watch-plugins-changes"`
Port uint `koanf:"port"`
KubeConfigPath string `koanf:"kubeconfig"`
StaticDir string `koanf:"html-static-dir"`
Expand Down Expand Up @@ -154,6 +155,7 @@ func flagset() *flag.FlagSet {
f.Bool("dev", false, "Allow connections from other origins")
f.Bool("insecure-ssl", false, "Accept/Ignore all server SSL certificates")
f.Bool("enable-dynamic-clusters", false, "Enable dynamic clusters, which stores stateless clusters in the frontend.")
f.Bool("watch-plugins-changes", true, "Reloads plugins when there are changes to them or their directory")

f.String("kubeconfig", "", "Absolute path to the kubeconfig file")
f.String("html-static-dir", "", "Static HTML directory to serve")
Expand Down

0 comments on commit 91ffcee

Please sign in to comment.