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

node-installer: add test for kata config #1074

Merged
merged 1 commit into from
Dec 16, 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
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