Skip to content

Commit

Permalink
node-installer: add test for kata config
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerdev committed Dec 16, 2024
1 parent 791c49f commit 52c7848
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions nodeinstaller/internal/config/kata_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package config

import "github.com/pelletier/go-toml/v2"

// KataRuntimeConfig is the configuration for the Kata runtime.
// Source: https://github.com/kata-containers/kata-containers/blob/4029d154ba0c26fcf4a8f9371275f802e3ef522c/src/runtime/pkg/katautils/config.go
// This is a simplified version of the actual configuration.
Expand All @@ -14,6 +16,11 @@ type KataRuntimeConfig struct {
Runtime KataRuntime
}

// Marshal encodes the configuration as TOML.
func (k *KataRuntimeConfig) Marshal() ([]byte, error) {
return toml.Marshal(k)
}

// Image is the configuration for the image.
type Image map[string]any

Expand Down
40 changes: 40 additions & 0 deletions nodeinstaller/internal/config/kata_runtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

package config_test

import (
"testing"

"github.com/edgelesssys/contrast/internal/platforms"
"github.com/edgelesssys/contrast/nodeinstaller/internal/constants"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestKataConfig(t *testing.T) {
// This is a regression test that ensures the `agent.kata` section is not optimized away. Empty
// section and no section are handled differently by Kata, so we make sure that this section is
// always present.
for _, platform := range platforms.All() {
t.Run(platform.String(), func(t *testing.T) {
require := require.New(t)
assert := assert.New(t)
cfg, err := constants.KataRuntimeConfig("/", platform, "", false)
require.NoError(err)
configBytes, err := cfg.Marshal()
require.NoError(err)
assert.Contains(string(configBytes), "[Agent.kata]")
assert.Contains(string(configBytes), "[Runtime]")

switch platform {
case platforms.K3sQEMUSNP, platforms.K3sQEMUTDX, platforms.MetalQEMUSNP, platforms.MetalQEMUTDX, platforms.RKE2QEMUTDX:
assert.Contains(string(configBytes), "[Hypervisor.qemu]")
case platforms.AKSCloudHypervisorSNP:
assert.Contains(string(configBytes), "[Hypervisor.clh]")
default:
assert.Fail("missing hypervisor test expectations")
}
})
}
}
2 changes: 1 addition & 1 deletion nodeinstaller/node-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func containerdRuntimeConfig(basePath, configPath string, platform platforms.Pla
if err != nil {
return fmt.Errorf("generating kata runtime config: %w", err)
}
rawConfig, err := toml.Marshal(kataRuntimeConfig)
rawConfig, err := kataRuntimeConfig.Marshal()
if err != nil {
return fmt.Errorf("marshaling kata runtime config: %w", err)
}
Expand Down

0 comments on commit 52c7848

Please sign in to comment.