Merge pull request #9988 from huoqifeng/annotation

initdata: add initdata annotation in hypervisor config
This commit is contained in:
Chengyu Zhu 2024-07-26 19:59:45 +08:00 committed by GitHub
commit 2a9ed19512
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 0 deletions

View File

@ -556,6 +556,9 @@ func addHypervisorConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig,
config.HypervisorConfig.SGXEPCSize = size config.HypervisorConfig.SGXEPCSize = size
} }
if initdata, ok := ocispec.Annotations[vcAnnotations.Initdata]; ok {
config.HypervisorConfig.Initdata = initdata
}
return nil return nil
} }

View File

@ -773,6 +773,12 @@ func TestAddRemoteHypervisorAnnotations(t *testing.T) {
ocispec.Annotations[vcAnnotations.DefaultMemory] = "1" ocispec.Annotations[vcAnnotations.DefaultMemory] = "1"
err = addAnnotations(ocispec, &sbConfig, runtimeConfig) err = addAnnotations(ocispec, &sbConfig, runtimeConfig)
assert.NoError(err) assert.NoError(err)
// When initdata specified, remote hypervisor annotations do have the annotation added.
ocispec.Annotations[vcAnnotations.Initdata] = "initdata"
err = addAnnotations(ocispec, &sbConfig, runtimeConfig)
assert.NoError(err)
assert.Equal(sbConfig.HypervisorConfig.Initdata, "initdata")
} }
func TestAddProtectedHypervisorAnnotations(t *testing.T) { func TestAddProtectedHypervisorAnnotations(t *testing.T) {
@ -860,6 +866,7 @@ func TestAddRuntimeAnnotations(t *testing.T) {
ocispec.Annotations[vcAnnotations.DisableNewNetNs] = "true" ocispec.Annotations[vcAnnotations.DisableNewNetNs] = "true"
ocispec.Annotations[vcAnnotations.InterNetworkModel] = "macvtap" ocispec.Annotations[vcAnnotations.InterNetworkModel] = "macvtap"
ocispec.Annotations[vcAnnotations.CreateContainerTimeout] = "100" ocispec.Annotations[vcAnnotations.CreateContainerTimeout] = "100"
ocispec.Annotations[vcAnnotations.Initdata] = "initdata"
addAnnotations(ocispec, &config, runtimeConfig) addAnnotations(ocispec, &config, runtimeConfig)
assert.Equal(config.DisableGuestSeccomp, true) assert.Equal(config.DisableGuestSeccomp, true)
@ -867,6 +874,7 @@ func TestAddRuntimeAnnotations(t *testing.T) {
assert.Equal(config.NetworkConfig.DisableNewNetwork, true) assert.Equal(config.NetworkConfig.DisableNewNetwork, true)
assert.Equal(config.NetworkConfig.InterworkingModel, vc.NetXConnectMacVtapModel) assert.Equal(config.NetworkConfig.InterworkingModel, vc.NetXConnectMacVtapModel)
assert.Equal(config.CreateContainerTimeout, uint64(100)) assert.Equal(config.CreateContainerTimeout, uint64(100))
assert.Equal(config.HypervisorConfig.Initdata, "initdata")
} }
func TestRegexpContains(t *testing.T) { func TestRegexpContains(t *testing.T) {

View File

@ -684,6 +684,9 @@ type HypervisorConfig struct {
// QgsPort defines Intel Quote Generation Service port exposed from the host // QgsPort defines Intel Quote Generation Service port exposed from the host
QgsPort uint32 QgsPort uint32
// Initdata defines the initdata passed into guest when CreateVM
Initdata string
} }
// vcpu mapping from vcpu number to thread number // vcpu mapping from vcpu number to thread number

View File

@ -243,6 +243,9 @@ const (
// EnableRootlessHypervisor is a sandbox annotation to enable rootless hypervisor (only supported in QEMU currently). // EnableRootlessHypervisor is a sandbox annotation to enable rootless hypervisor (only supported in QEMU currently).
EnableRootlessHypervisor = kataAnnotHypervisorPrefix + "rootless" EnableRootlessHypervisor = kataAnnotHypervisorPrefix + "rootless"
// Initdata is the initdata passed in when CreateVM
Initdata = kataConfAnnotationsPrefix + "runtime.cc_init_data"
) )
// Runtime related annotations // Runtime related annotations

View File

@ -79,6 +79,7 @@ func (rh *remoteHypervisor) CreateVM(ctx context.Context, id string, network Net
annotations[hypannotations.MachineType] = hypervisorConfig.HypervisorMachineType annotations[hypannotations.MachineType] = hypervisorConfig.HypervisorMachineType
annotations[hypannotations.DefaultVCPUs] = strconv.FormatUint(uint64(hypervisorConfig.NumVCPUs()), 10) annotations[hypannotations.DefaultVCPUs] = strconv.FormatUint(uint64(hypervisorConfig.NumVCPUs()), 10)
annotations[hypannotations.DefaultMemory] = strconv.FormatUint(uint64(hypervisorConfig.MemorySize), 10) annotations[hypannotations.DefaultMemory] = strconv.FormatUint(uint64(hypervisorConfig.MemorySize), 10)
annotations[hypannotations.Initdata] = hypervisorConfig.Initdata
req := &pb.CreateVMRequest{ req := &pb.CreateVMRequest{
Id: id, Id: id,