Skip to content

Commit 05a2937

Browse files
committed
Update plugin load_db to support air gapped environments
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 427fc6e commit 05a2937

4 files changed

Lines changed: 62 additions & 2 deletions

File tree

k8s/cloud/public/base/plugin_db_updater_job.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ spec:
4040
volumeMounts:
4141
- name: certs
4242
mountPath: /certs
43+
- name: plugin-configs
44+
mountPath: /plugins
4345
env:
4446
- name: PL_POSTGRES_USERNAME
4547
valueFrom:
@@ -63,6 +65,8 @@ spec:
6365
key: PL_PLUGIN_SERVICE
6466
- name: PL_PLUGIN_REPO
6567
value: "pixie-io/pixie-plugin"
68+
- name: PL_PLUGIN_DIR
69+
value: "/plugins"
6670
restartPolicy: Never
6771
volumes:
6872
- name: pl-db-secrets
@@ -71,6 +75,15 @@ spec:
7175
- name: certs
7276
secret:
7377
secretName: service-tls-certs
78+
# For airgapped installs, create this ConfigMap with plugin YAML files:
79+
# kubectl create configmap pl-plugin-configs --from-file=plugins/
80+
# Where plugins/ has subdirectories per plugin containing plugin.yaml
81+
# and retention.yaml. If the ConfigMap doesn't exist, the job falls
82+
# back to fetching from GitHub.
83+
- name: plugin-configs
84+
configMap:
85+
name: pl-plugin-configs
86+
optional: true
7487
backoffLimit: 1
7588
parallelism: 1
7689
completions: 1

src/cloud/indexer/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ go_library(
4444
],
4545
)
4646

47+
# Dummy chan
4748
pl_go_binary(
4849
name = "indexer_server",
4950
embed = [":indexer_lib"],

src/cloud/indexer/indexer_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func init() {
5151

5252
pflag.String("md_index_name", "", "The elastic index name for metadata.")
5353
pflag.String("md_index_max_age", "", "The amount of time before rolling over the elastic index as a string, eg '30d'")
54-
pflag.String("md_index_delete_after", "", "The amount of time after rollover to delete old elastic indices, as a string, eg '30d'")
54+
pflag.String("md_index_delete_after", "", "The amount of time after rollover to delete old elastic indices, as a string, eg '30d'.")
5555
pflag.Int("md_index_replicas", 4, "The number of replicas to setup for the metadata index.")
5656
pflag.Bool("md_manual_index_management", false, "Skip creation of managed elastic indices. Requires manually deploying an elastic index with md_index_name")
5757
}

src/cloud/plugin/load_db/main.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"fmt"
2727
"io"
2828
"net/http"
29+
"os"
2930
"path/filepath"
3031

3132
"github.com/blang/semver"
@@ -56,6 +57,7 @@ const githubArchiveTmpl = "https://api.github.com/repos/%s/tarball"
5657
// bazel run //src/cloud/plugin/load_db:push_plugin_db_updater_image
5758
func init() {
5859
pflag.String("plugin_repo", "pixie-io/pixie-plugin", "The name of the plugin repo.")
60+
pflag.String("plugin_dir", "", "Local directory containing plugin configs. When set, plugins are loaded from this directory instead of fetching from GitHub. Expected structure: <plugin_dir>/<plugin_name>/{plugin.yaml,retention.yaml}")
5961
pflag.String("plugin_service", "plugin-service.plc.svc.cluster.local:50600", "The plugin service url (load balancer/list is ok)")
6062
pflag.String("domain_name", "dev.withpixie.dev", "The domain name of Pixie Cloud")
6163
}
@@ -92,11 +94,55 @@ type configSet struct {
9294
var configsByPath = make(map[string]*configSet)
9395

9496
func loadPlugins(db *sqlx.DB) {
97+
pluginDir := viper.GetString("plugin_dir")
98+
if pluginDir != "" {
99+
if loadPluginsFromDir(pluginDir, db) {
100+
log.Infof("Loaded plugins from local directory: %s", pluginDir)
101+
return
102+
}
103+
log.Infof("Plugin directory %s is empty or missing, falling back to GitHub", pluginDir)
104+
}
105+
95106
pluginRepo := viper.GetString("plugin_repo")
96107
if pluginRepo == "" {
97-
log.Fatal("Must specify --plugin_repo")
108+
log.Fatal("Must specify --plugin_repo or --plugin_dir")
98109
}
99110

111+
loadPluginsFromGitHub(pluginRepo, db)
112+
}
113+
114+
// loadPluginsFromDir walks a local directory for plugin YAML files.
115+
// Returns true if any files were found and processed.
116+
func loadPluginsFromDir(dir string, db *sqlx.DB) bool {
117+
info, err := os.Stat(dir)
118+
if err != nil || !info.IsDir() {
119+
return false
120+
}
121+
122+
found := false
123+
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
124+
if err != nil {
125+
return err
126+
}
127+
if info.IsDir() {
128+
return nil
129+
}
130+
f, err := os.Open(path)
131+
if err != nil {
132+
return fmt.Errorf("failed to open %s: %w", path, err)
133+
}
134+
defer f.Close()
135+
found = true
136+
processFile(path, f, db)
137+
return nil
138+
})
139+
if err != nil {
140+
log.WithError(err).Fatal("Failed to read plugin directory")
141+
}
142+
return found
143+
}
144+
145+
func loadPluginsFromGitHub(pluginRepo string, db *sqlx.DB) {
100146
client := http.Client{}
101147
req, err := http.NewRequest("GET", fmt.Sprintf(githubArchiveTmpl, pluginRepo), nil)
102148
if err != nil {

0 commit comments

Comments
 (0)