Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of detached bundles #5785

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/5785.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/bundle: Use manifest hash at bundle load time
5 changes: 5 additions & 0 deletions .changelog/5785.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/runtime: Automatically enable all configured detached components

Since they are explicitly configured there should be no need to enable
them twice. This just defaults detached components to be enabled and one
needs to explicitly disable them.
16 changes: 12 additions & 4 deletions go/runtime/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
type Bundle struct {
Manifest *Manifest
Data map[string][]byte

// manifestHash is the original manifest hash of the bundle at time the bundle was loaded.
manifestHash hash.Hash
}

// Validate validates the runtime bundle for well-formedness.
Expand Down Expand Up @@ -277,6 +280,9 @@
return fmt.Errorf("runtime/bundle: failed to write bundle: %w", err)
}

// Update the manifest hash.
bnd.manifestHash = bnd.Manifest.Hash()
peternose marked this conversation as resolved.
Show resolved Hide resolved

return nil
}

Expand All @@ -298,12 +304,12 @@
case false:
// DATADIR/runtimes/bundles/manifestHash
subDir = filepath.Join(ExplodedPath(dataDir),
bnd.Manifest.Hash().String(),
bnd.manifestHash.String(),
)
case true:
// DATADIR/runtimes/bundles/detached/manifestHash
subDir = filepath.Join(DetachedExplodedPath(dataDir),
bnd.Manifest.Hash().String(),
bnd.manifestHash.String(),
)
}

Expand Down Expand Up @@ -378,6 +384,7 @@
func (bnd *Bundle) Close() error {
bnd.Manifest = nil
bnd.Data = nil
bnd.manifestHash.Empty()

Check warning on line 387 in go/runtime/bundle/bundle.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/bundle/bundle.go#L387

Added line #L387 was not covered by tests
return nil
}

Expand Down Expand Up @@ -436,8 +443,9 @@

// Ensure the bundle is well-formed.
bnd := &Bundle{
Manifest: &manifest,
Data: data,
Manifest: &manifest,
Data: data,
manifestHash: manifest.Hash(),
}
if err = bnd.Validate(); err != nil {
return nil, err
Expand Down
56 changes: 56 additions & 0 deletions go/runtime/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package config

import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
)

func TestComponentConfig(t *testing.T) {
require := require.New(t)

cfg := Config{
Components: []ComponentConfig{
{
ID: component.ID{Kind: component.ROFL, Name: "foo-test"},
Disabled: false,
},
},
}

compCfg, ok := cfg.GetComponent(component.ID{Kind: component.ROFL, Name: "foo-test"})
require.True(ok)
require.EqualValues(compCfg.ID.Kind, component.ROFL)
peternose marked this conversation as resolved.
Show resolved Hide resolved
require.EqualValues(compCfg.ID.Name, "foo-test")
require.False(compCfg.Disabled)

compCfg, ok = cfg.GetComponent(component.ID{Kind: component.ROFL, Name: "does-not-exist"})
require.False(ok)
require.EqualValues(compCfg, ComponentConfig{})

// Deserialization.
yamlCfg := `
components:
- rofl.foo-test
- id: rofl.another
disabled: true
`
var decCfg Config
err := yaml.Unmarshal([]byte(yamlCfg), &decCfg)
require.NoError(err, "yaml.Unmarshal")

compCfg, ok = decCfg.GetComponent(component.ID{Kind: component.ROFL, Name: "foo-test"})
require.True(ok)
require.EqualValues(compCfg.ID.Kind, component.ROFL)
require.EqualValues(compCfg.ID.Name, "foo-test")
require.False(compCfg.Disabled)

compCfg, ok = decCfg.GetComponent(component.ID{Kind: component.ROFL, Name: "another"})
require.True(ok)
require.EqualValues(compCfg.ID.Kind, component.ROFL)
require.EqualValues(compCfg.ID.Name, "another")
require.True(compCfg.Disabled)
}
9 changes: 7 additions & 2 deletions go/runtime/registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@
}

rtBnd := &runtimeHost.RuntimeBundle{
Bundle: bnd,
ExplodedDataDir: dataDir,
Bundle: bnd,
ExplodedDataDir: dataDir,
ExplodedDetachedDirs: make(map[component.ID]string),
}

// Merge in detached components.
Expand Down Expand Up @@ -321,6 +322,10 @@
if config.GlobalConfig.Mode != config.ModeCompute {
enabled = false
}
// Detached components are explicit and they should be enabled by default.
if _, ok := rtBnd.ExplodedDetachedDirs[comp.ID()]; ok {
enabled = true

Check warning on line 327 in go/runtime/registry/config.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/registry/config.go#L327

Added line #L327 was not covered by tests
}

// Check for any overrides in the node configuration.
compCfg, ok := config.GlobalConfig.Runtime.GetComponent(comp.ID())
Expand Down
Loading