Skip to content

Commit bcb443d

Browse files
authored
🐛 Propagate AutoUpdate to all runtimes + avoid reinstalling deps (#5510)
This change fixes a number of things from our latest release: * Removes hardcoded `AutoUpdate` setting and uses the config * Avoids re-installing already installed dependencies * Propagates the setting `AutoUpdate` to all runtimes created with a parent via `NewRuntimeFrom()` --------- Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
1 parent df4aaa6 commit bcb443d

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

explorer/scan/discovery_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ func TestDiscoverAssets(t *testing.T) {
140140
}
141141
}
142142

143+
runtime := providers.Coordinator.NewRuntime()
144+
assert.Nil(t, providers.SetDefaultRuntime(runtime))
145+
runtime.AutoUpdate = providers.UpdateProvidersConfig{
146+
Enabled: true,
147+
RefreshInterval: 60 * 60,
148+
}
149+
143150
t.Run("normal", func(t *testing.T) {
144151
inv := getInventory()
145152
discoveredAssets, err := DiscoverAssets(context.Background(), inv, nil, recording.Null{})

providers-sdk/v1/testutils/testutils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func Local() llx.Runtime {
221221
schema.Add(mockprovider.Config.Name, mockSchema)
222222

223223
runtime := providers.Coordinator.NewRuntime()
224+
_ = providers.SetDefaultRuntime(runtime)
225+
runtime.AutoUpdate = providers.UpdateProvidersConfig{
226+
Enabled: false,
227+
RefreshInterval: 60 * 60,
228+
}
224229

225230
provider := &providers.RunningProvider{
226231
Name: osconf.Config.Name,

providers/coordinator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ func (c *coordinator) newRuntime() *Runtime {
108108
providers: map[string]*ConnectedProvider{},
109109
recording: recording.Null{},
110110
shutdownTimeout: defaultShutdownTimeout,
111+
AutoUpdate: UpdateProvidersConfig{
112+
Enabled: true,
113+
},
111114
}
112115

113116
c.mutex.Lock()
@@ -123,6 +126,7 @@ func (c *coordinator) newRuntime() *Runtime {
123126
func (c *coordinator) NewRuntimeFrom(parent *Runtime) *Runtime {
124127
res := c.NewRuntime()
125128
res.UpstreamConfig = parent.UpstreamConfig
129+
res.AutoUpdate = parent.AutoUpdate
126130
res.recording = parent.Recording()
127131
for k, v := range parent.providers {
128132
res.providers[k] = v

providers/providers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ func installDependencies(provider *Provider, existing Providers) error {
493493

494494
// Check if dependency is already installed
495495
depProvider := existing.Lookup(dependencyLookup)
496-
if depProvider == nil {
497-
continue
496+
if depProvider != nil {
497+
continue // exist
498498
}
499499

500500
upstreamDep := DefaultProviders.Lookup(dependencyLookup)

providers/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (r *Runtime) providerForAsset(asset *inventory.Asset) (*Provider, error) {
181181
conn.Type = inventory.ConnBackendToType(conn.Backend)
182182
}
183183

184-
provider, err := EnsureProvider(ProviderLookup{ConnType: conn.Type}, true, r.coordinator.Providers())
184+
provider, err := EnsureProvider(ProviderLookup{ConnType: conn.Type}, r.AutoUpdate.Enabled, r.coordinator.Providers())
185185
if err != nil {
186186
errs.Add(err)
187187
continue

0 commit comments

Comments
 (0)