Skip to content

Commit caa24f0

Browse files
blacksailsashutosh-narkar
authored andcommitted
plugins/discovery: Fix discovery erasing persistence_directory config
Before this change, if a discovery bundle didn't contain configuration for `persistence_directory`, this would be deleted from the manager's configuration. When enabling persistence of the discovery bundle this doesn't make much sense, as the first discovery bundle would erase the persistence settings. This change ensures that discovery never erases `persistence_directory`. Signed-off-by: Benjamin Nørgaard <[email protected]>
1 parent 58e52ee commit caa24f0

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

docs/content/management-discovery.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,10 @@ the discovery bundle itself is persisted. The discovered configuration that is g
300300
policies contained in the discovery bundle will **NOT** be persisted.
301301

302302
{{< info >}}
303-
By default, the discovery bundle is persisted under the current working directory of the OPA process (e.g., `./.opa/bundles/<discovery.name>/bundle.tar.gz`).
303+
The discovery bundle is persisted at
304+
`<persistence_directory>/bundles/<discovery.name>/bundle.tar.gz`. By default
305+
`persistence_directory` is `.opa` in the working directory of the OPA process.
306+
If `persistence_directory` is changed through discovery this will not affect
307+
where the discovery plugin will store the discovery bundles, the boot
308+
configuration will always be used.
304309
{{< /info >}}

plugins/discovery/discovery_test.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,8 @@ func TestReconfigureWithUpdates(t *testing.T) {
10531053
"key": "some_private_key",
10541054
"scope": "write"
10551055
}
1056-
}
1056+
},
1057+
"persistence_directory": "test"
10571058
}`), "test-id", inmem.New())
10581059
if err != nil {
10591060
t.Fatal(err)
@@ -1063,6 +1064,7 @@ func TestReconfigureWithUpdates(t *testing.T) {
10631064
if err != nil {
10641065
t.Fatal(err)
10651066
}
1067+
originalConfig := disco.config
10661068

10671069
initialBundle := makeDataBundle(1, `
10681070
{
@@ -1079,7 +1081,6 @@ func TestReconfigureWithUpdates(t *testing.T) {
10791081
t.Fatalf("Unexpected error %v", err)
10801082
}
10811083

1082-
originalConfig := disco.config
10831084
// update the discovery configuration and check
10841085
// the boot configuration is not overwritten
10851086
updatedBundle := makeDataBundle(2, `
@@ -1346,6 +1347,40 @@ func TestReconfigureWithUpdates(t *testing.T) {
13461347
if err != nil {
13471348
t.Fatalf("Unexpected error %v", err)
13481349
}
1350+
1351+
// check that not setting persistence_directory doesn't remove boot config
1352+
updatedBundle = makeDataBundle(13, `
1353+
{
1354+
"config": {}
1355+
}
1356+
`)
1357+
1358+
err = disco.reconfigure(ctx, download.Update{Bundle: updatedBundle})
1359+
if err != nil {
1360+
t.Fatalf("Unexpected error %v", err)
1361+
}
1362+
1363+
if manager.Config.PersistenceDirectory == nil {
1364+
t.Fatal("Erased persistence directory configuration")
1365+
}
1366+
1367+
// update persistence directory
1368+
updatedBundle = makeDataBundle(14, `
1369+
{
1370+
"config": {
1371+
"persistence_directory": "my_bundles"
1372+
}
1373+
}
1374+
`)
1375+
1376+
err = disco.reconfigure(ctx, download.Update{Bundle: updatedBundle})
1377+
if err != nil {
1378+
t.Fatalf("Unexpected error %v", err)
1379+
}
1380+
1381+
if manager.Config.PersistenceDirectory == nil || *manager.Config.PersistenceDirectory != "my_bundles" {
1382+
t.Fatal("Did not update persistence directory")
1383+
}
13491384
}
13501385

13511386
func TestProcessBundleWithSigning(t *testing.T) {

plugins/plugins.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,11 @@ func (m *Manager) Reconfigure(config *config.Config) error {
691691
}
692692
}
693693

694+
// don't erase persistence directory
695+
if config.PersistenceDirectory == nil {
696+
config.PersistenceDirectory = m.Config.PersistenceDirectory
697+
}
698+
694699
m.Config = config
695700
m.interQueryBuiltinCacheConfig = interQueryBuiltinCacheConfig
696701
for name, client := range services {

0 commit comments

Comments
 (0)