From e82fb3595abf9628828c9159ca69f1f8b81646d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hor=C3=A1=C4=8Dek?= Date: Mon, 2 Jul 2018 20:53:06 +0200 Subject: [PATCH] hooks: rebase on latest master Most of the changes are VM -> VMI --- ...r-hook.yaml => vmi-with-sidecar-hook.yaml} | 8 +-- cmd/example-hook-sidecar/smbios.go | 10 ++-- pkg/hooks/manager.go | 8 +-- pkg/hooks/v1alpha1/api.pb.go | 22 ++++---- pkg/hooks/v1alpha1/api.proto | 4 +- pkg/virt-controller/services/template.go | 2 +- pkg/virt-launcher/virtwrap/manager.go | 2 +- ...decar_test.go => vmi_hook_sidecar_test.go} | 52 +++++++++---------- tools/vms-generator/vms-generator.go | 14 ++--- 9 files changed, 61 insertions(+), 61 deletions(-) rename cluster/examples/{vm-with-sidecar-hook.yaml => vmi-with-sidecar-hook.yaml} (87%) rename tests/{vm_hook_sidecar_test.go => vmi_hook_sidecar_test.go} (69%) diff --git a/cluster/examples/vm-with-sidecar-hook.yaml b/cluster/examples/vmi-with-sidecar-hook.yaml similarity index 87% rename from cluster/examples/vm-with-sidecar-hook.yaml rename to cluster/examples/vmi-with-sidecar-hook.yaml index 959466dffca5..290749f5f2e3 100644 --- a/cluster/examples/vm-with-sidecar-hook.yaml +++ b/cluster/examples/vmi-with-sidecar-hook.yaml @@ -1,13 +1,13 @@ -apiVersion: kubevirt.io/v1alpha1 -kind: VirtualMachine +apiVersion: kubevirt.io/v1alpha2 +kind: VirtualMachineInstance metadata: annotations: hooks.kubevirt.io/hookSidecars: '[{"image": "registry:5000/kubevirt/example-hook-sidecar:devel"}]' smbios.vm.kubevirt.io/baseBoardManufacturer: Radical Edward creationTimestamp: null labels: - special: vm-with-sidecar-hook - name: vm-with-sidecar-hook + special: vmi-with-sidecar-hook + name: vmi-with-sidecar-hook spec: domain: devices: diff --git a/cmd/example-hook-sidecar/smbios.go b/cmd/example-hook-sidecar/smbios.go index ec645ac3c02e..fdbab5b0f9f2 100644 --- a/cmd/example-hook-sidecar/smbios.go +++ b/cmd/example-hook-sidecar/smbios.go @@ -62,15 +62,15 @@ type v1alpha1Server struct{} func (s v1alpha1Server) OnDefineDomain(ctx context.Context, params *hooksV1alpha1.OnDefineDomainParams) (*hooksV1alpha1.OnDefineDomainResult, error) { log.Log.Info("Hook's OnDefineDomain callback method has been called") - vmJSON := params.GetVm() - vmSpec := vmSchema.VirtualMachine{} - err := json.Unmarshal(vmJSON, &vmSpec) + vmiJSON := params.GetVmi() + vmiSpec := vmSchema.VirtualMachineInstance{} + err := json.Unmarshal(vmiJSON, &vmiSpec) if err != nil { - log.Log.Reason(err).Errorf("Failed to unmarshal given VM spec: %s", vmJSON) + log.Log.Reason(err).Errorf("Failed to unmarshal given VMI spec: %s", vmiJSON) panic(err) } - annotations := vmSpec.GetAnnotations() + annotations := vmiSpec.GetAnnotations() if _, found := annotations[baseBoardManufacturerAnnotation]; !found { log.Log.Info("SM BIOS hook sidecar was requested, but no attributes provided. Returning original domain spec") diff --git a/pkg/hooks/manager.go b/pkg/hooks/manager.go index d1b799afdf68..d69e7b4d0a62 100644 --- a/pkg/hooks/manager.go +++ b/pkg/hooks/manager.go @@ -167,7 +167,7 @@ func sortCallbacksPerHookPoint(callbacksPerHookPoint map[string][]*callackClient } } -func (m *Manager) OnDefineDomain(domainSpec *virtwrapApi.DomainSpec, vm *v1.VirtualMachine) (*virtwrapApi.DomainSpec, error) { +func (m *Manager) OnDefineDomain(domainSpec *virtwrapApi.DomainSpec, vmi *v1.VirtualMachineInstance) (*virtwrapApi.DomainSpec, error) { if callbacks, found := m.callbacksPerHookPoint[hooksInfo.OnDefineDomainHookPointName]; found { for _, callback := range callbacks { if callback.Version == hooksV1alpha1.Version { @@ -175,9 +175,9 @@ func (m *Manager) OnDefineDomain(domainSpec *virtwrapApi.DomainSpec, vm *v1.Virt if err != nil { return nil, fmt.Errorf("Failed to marshal domain spec: %v", domainSpec) } - vmJSON, err := json.Marshal(vm) + vmiJSON, err := json.Marshal(vmi) if err != nil { - return nil, fmt.Errorf("Failed to marshal VM spec: %v", vm) + return nil, fmt.Errorf("Failed to marshal VMI spec: %v", vmi) } conn, err := dialSocket(callback.SocketPath) @@ -193,7 +193,7 @@ func (m *Manager) OnDefineDomain(domainSpec *virtwrapApi.DomainSpec, vm *v1.Virt defer cancel() result, err := client.OnDefineDomain(ctx, &hooksV1alpha1.OnDefineDomainParams{ DomainXML: domainSpecXML, - Vm: vmJSON, + Vmi: vmiJSON, }) if err != nil { return nil, err diff --git a/pkg/hooks/v1alpha1/api.pb.go b/pkg/hooks/v1alpha1/api.pb.go index 748e3ae4eb15..bc9e92edb0a2 100644 --- a/pkg/hooks/v1alpha1/api.pb.go +++ b/pkg/hooks/v1alpha1/api.pb.go @@ -36,8 +36,8 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type OnDefineDomainParams struct { // domainXML is original libvirt domain specification DomainXML []byte `protobuf:"bytes,1,opt,name=domainXML,proto3" json:"domainXML,omitempty"` - // vm is VirtualMachine is object of virtual machine currently processed by virt-launcher, it is encoded as JSON - Vm []byte `protobuf:"bytes,2,opt,name=vm,proto3" json:"vm,omitempty"` + // vmi is VirtualMachineInstance is object of virtual machine currently processed by virt-launcher, it is encoded as JSON + Vmi []byte `protobuf:"bytes,2,opt,name=vmi,proto3" json:"vmi,omitempty"` } func (m *OnDefineDomainParams) Reset() { *m = OnDefineDomainParams{} } @@ -52,9 +52,9 @@ func (m *OnDefineDomainParams) GetDomainXML() []byte { return nil } -func (m *OnDefineDomainParams) GetVm() []byte { +func (m *OnDefineDomainParams) GetVmi() []byte { if m != nil { - return m.Vm + return m.Vmi } return nil } @@ -160,12 +160,12 @@ var fileDescriptor0 = []byte{ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xc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, 0x9c, 0xa0, 0xd4, 0xe2, 0xd2, 0x9c, 0x12, + 0xfc, 0xe6, 0x18, 0x55, 0x73, 0x71, 0x3a, 0x27, 0xe6, 0xe4, 0x24, 0x25, 0x26, 0x67, 0x17, 0x0b, + 0xe5, 0x71, 0xf1, 0xa1, 0x1a, 0x21, 0xa4, 0xab, 0x87, 0xc3, 0xd9, 0x7a, 0xd8, 0xdc, 0x2c, 0x45, + 0xac, 0x72, 0x88, 0xd3, 0x92, 0xd8, 0xc0, 0x41, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x7d, + 0x13, 0xe2, 0x3a, 0x27, 0x01, 0x00, 0x00, } diff --git a/pkg/hooks/v1alpha1/api.proto b/pkg/hooks/v1alpha1/api.proto index 7f784a26d60a..736b456a03dd 100644 --- a/pkg/hooks/v1alpha1/api.proto +++ b/pkg/hooks/v1alpha1/api.proto @@ -9,8 +9,8 @@ service Callbacks { message OnDefineDomainParams { // domainXML is original libvirt domain specification bytes domainXML = 1; - // vm is VirtualMachine is object of virtual machine currently processed by virt-launcher, it is encoded as JSON - bytes vm = 2; + // vmi is VirtualMachineInstance is object of virtual machine currently processed by virt-launcher, it is encoded as JSON + bytes vmi = 2; } message OnDefineDomainResult { diff --git a/pkg/virt-controller/services/template.go b/pkg/virt-controller/services/template.go index 0652e424dc25..d3dbaa025802 100644 --- a/pkg/virt-controller/services/template.go +++ b/pkg/virt-controller/services/template.go @@ -210,7 +210,7 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) ( // Read requested hookSidecars from VM annotation var err error requestedHookSidecarList := make(hooks.HookSidecarList, 0) - if rawRequestedHookSidecarList, requestedHookSidecarListDefined := vm.GetObjectMeta().GetAnnotations()[hooks.HookSidecarListAnnotationName]; requestedHookSidecarListDefined { + if rawRequestedHookSidecarList, requestedHookSidecarListDefined := vmi.GetObjectMeta().GetAnnotations()[hooks.HookSidecarListAnnotationName]; requestedHookSidecarListDefined { requestedHookSidecarList, err = hooks.UnmarshalHookSidecarList(rawRequestedHookSidecarList) if err != nil { return nil, err diff --git a/pkg/virt-launcher/virtwrap/manager.go b/pkg/virt-launcher/virtwrap/manager.go index effe1b52f261..279677e57392 100644 --- a/pkg/virt-launcher/virtwrap/manager.go +++ b/pkg/virt-launcher/virtwrap/manager.go @@ -112,7 +112,7 @@ func (l *LibvirtDomainManager) preStartHook(vmi *v1.VirtualMachineInstance, doma } hooksManager := hooks.GetManager() - domainSpec, err := hooksManager.OnDefineDomain(&domain.Spec, vm) + domainSpec, err := hooksManager.OnDefineDomain(&domain.Spec, vmi) if err != nil { return domain, err } diff --git a/tests/vm_hook_sidecar_test.go b/tests/vmi_hook_sidecar_test.go similarity index 69% rename from tests/vm_hook_sidecar_test.go rename to tests/vmi_hook_sidecar_test.go index 539bfa9d0309..04067a6f89ce 100644 --- a/tests/vm_hook_sidecar_test.go +++ b/tests/vmi_hook_sidecar_test.go @@ -42,32 +42,32 @@ var _ = Describe("HookSidecars", func() { virtClient, err := kubecli.GetKubevirtClient() tests.PanicOnError(err) - var vm *v1.VirtualMachine + var vmi *v1.VirtualMachineInstance BeforeEach(func() { tests.BeforeTestCleanup() - vm = tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskAlpine)) - vm.ObjectMeta.Annotations = map[string]string{ + vmi = tests.NewRandomVMIWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskAlpine)) + vmi.ObjectMeta.Annotations = map[string]string{ "hooks.kubevirt.io/hookSidecars": `[{"image": "registry:5000/kubevirt/example-hook-sidecar:devel"}]`, "smbios.vm.kubevirt.io/baseBoardManufacturer": "Radical Edward", } }) - Describe("VM definition", func() { + Describe("VMI definition", func() { Context("with SM BIOS hook sidecar", func() { It("should successfully start with hook sidecar annotation", func() { - By("Starting a VM") - vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm) + By("Starting a VMI") + vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi) Expect(err).ToNot(HaveOccurred()) - tests.WaitForSuccessfulVMStart(vm) + tests.WaitForSuccessfulVMIStart(vmi) }, 300) It("should call Collect on the hook sidecar", func() { By("Getting hook-sidecar logs") - vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm) + vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi) Expect(err).ToNot(HaveOccurred()) - logs := func() string { return getHookSidecarLogs(virtClient, vm) } - tests.WaitForSuccessfulVMStart(vm) + logs := func() string { return getHookSidecarLogs(virtClient, vmi) } + tests.WaitForSuccessfulVMIStart(vmi) Eventually(logs, 11*time.Second, 500*time.Millisecond). @@ -76,10 +76,10 @@ var _ = Describe("HookSidecars", func() { It("should call OnDefineDomain on the hook sidecar", func() { By("Getting hook-sidecar logs") - vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm) + vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi) Expect(err).ToNot(HaveOccurred()) - logs := func() string { return getHookSidecarLogs(virtClient, vm) } - tests.WaitForSuccessfulVMStart(vm) + logs := func() string { return getHookSidecarLogs(virtClient, vmi) } + tests.WaitForSuccessfulVMIStart(vmi) Eventually(logs, 11*time.Second, 500*time.Millisecond). @@ -89,9 +89,9 @@ var _ = Describe("HookSidecars", func() { It("should update domain XML with SM BIOS properties", func() { By("Reading domain XML using virsh") tests.SkipIfNoKubectl() - vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm) - tests.WaitForSuccessfulVMStart(vm) - domainXml := getVmDomainXml(virtClient, vm) + vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi) + tests.WaitForSuccessfulVMIStart(vmi) + domainXml := getVmDomainXml(virtClient, vmi) Expect(domainXml).Should(ContainSubstring("")) Expect(domainXml).Should(ContainSubstring("")) Expect(domainXml).Should(ContainSubstring("Radical Edward")) @@ -101,9 +101,9 @@ var _ = Describe("HookSidecars", func() { }) -func getHookSidecarLogs(virtCli kubecli.KubevirtClient, vm *v1.VirtualMachine) string { - namespace := vm.GetObjectMeta().GetNamespace() - podName := getVmPodName(virtCli, vm) +func getHookSidecarLogs(virtCli kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance) string { + namespace := vmi.GetObjectMeta().GetNamespace() + podName := getVmPodName(virtCli, vmi) var tailLines int64 = 100 logsRaw, err := virtCli.CoreV1(). @@ -118,22 +118,22 @@ func getHookSidecarLogs(virtCli kubecli.KubevirtClient, vm *v1.VirtualMachine) s return string(logsRaw) } -func getVmDomainXml(virtCli kubecli.KubevirtClient, vm *v1.VirtualMachine) string { - podName := getVmPodName(virtCli, vm) +func getVmDomainXml(virtCli kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance) string { + podName := getVmPodName(virtCli, vmi) - vmNameListRaw, err := tests.RunKubectlCommand("exec", "-ti", "--namespace", vm.GetObjectMeta().GetNamespace(), podName, "--container", "compute", "--", "virsh", "list", "--name") + vmNameListRaw, err := tests.RunKubectlCommand("exec", "-ti", "--namespace", vmi.GetObjectMeta().GetNamespace(), podName, "--container", "compute", "--", "virsh", "list", "--name") Expect(err).ToNot(HaveOccurred()) vmName := strings.Split(vmNameListRaw, "\n")[0] - vmDomainXML, err := tests.RunKubectlCommand("exec", "-ti", "--namespace", vm.GetObjectMeta().GetNamespace(), podName, "--container", "compute", "--", "virsh", "dumpxml", vmName) + vmDomainXML, err := tests.RunKubectlCommand("exec", "-ti", "--namespace", vmi.GetObjectMeta().GetNamespace(), podName, "--container", "compute", "--", "virsh", "dumpxml", vmName) Expect(err).ToNot(HaveOccurred()) return vmDomainXML } -func getVmPodName(virtCli kubecli.KubevirtClient, vm *v1.VirtualMachine) string { - namespace := vm.GetObjectMeta().GetNamespace() - domain := vm.GetObjectMeta().GetName() +func getVmPodName(virtCli kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance) string { + namespace := vmi.GetObjectMeta().GetNamespace() + domain := vmi.GetObjectMeta().GetName() labelSelector := fmt.Sprintf("kubevirt.io/domain in (%s)", domain) pods, err := virtCli.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: labelSelector}) diff --git a/tools/vms-generator/vms-generator.go b/tools/vms-generator/vms-generator.go index fe8d06440acc..f051bf942588 100644 --- a/tools/vms-generator/vms-generator.go +++ b/tools/vms-generator/vms-generator.go @@ -578,18 +578,18 @@ func getVMIPresetSmall() *v1.VirtualMachineInstancePreset { return vmPreset } -func getVmWithHookSidecar() *v1.VirtualMachine { - vm := getBaseVMI(vmiWithHookSidecar) - vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1024M") +func getVMIWithHookSidecar() *v1.VirtualMachineInstance { + vmi := getBaseVMI(vmiWithHookSidecar) + vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1024M") - addRegistryDisk(&vm.Spec, fmt.Sprintf("%s/%s:%s", dockerPrefix, imageFedora, dockerTag), busVirtio) - addNoCloudDiskWitUserData(&vm.Spec, "#cloud-config\npassword: fedora\nchpasswd: { expire: False }") + addRegistryDisk(&vmi.Spec, fmt.Sprintf("%s/%s:%s", dockerPrefix, imageFedora, dockerTag), busVirtio) + addNoCloudDiskWitUserData(&vmi.Spec, "#cloud-config\npassword: fedora\nchpasswd: { expire: False }") - vm.ObjectMeta.Annotations = map[string]string{ + vmi.ObjectMeta.Annotations = map[string]string{ "hooks.kubevirt.io/hookSidecars": `[{"image": "registry:5000/kubevirt/example-hook-sidecar:devel"}]`, "smbios.vm.kubevirt.io/baseBoardManufacturer": "Radical Edward", } - return vm + return vmi } func main() {