Skip to content

Commit

Permalink
Merge pull request #189 from Prashanth684/multiarch-4.3
Browse files Browse the repository at this point in the history
Bug 1818149: Use virtio disk instead of config drive for injecting ignition for s390x/ppc64le
  • Loading branch information
openshift-merge-robot committed Apr 1, 2020
2 parents dd3fc51 + 0e27237 commit 58b3735
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 216 deletions.
49 changes: 20 additions & 29 deletions pkg/cloud/libvirt/client/client.go
Expand Up @@ -197,38 +197,29 @@ func (client *libvirtClient) CreateDomain(input CreateDomainInput) error {
if err != nil {
return fmt.Errorf("Error retrieving host architecture: %s", err)
}
// Both "s390" and "s390x" are linux kernel architectures for Linux on IBM z Systems, and they are for 31-bit and 64-bit respectively.
if arch == "s390x" || arch == "s390" {
if input.Ignition != nil {
if err := setIgnitionForS390X(&domainDef, client, input.Ignition, input.KubeClient, input.MachineNamespace, input.IgnitionVolumeName); err != nil {
return err
}
if input.Ignition != nil {
if err := setIgnition(&domainDef, client, input.Ignition, input.KubeClient, input.MachineNamespace, input.IgnitionVolumeName, arch); err != nil {
return err
}
} else if input.IgnKey != "" {
ignVolume, err := client.getVolume(input.IgnKey)
if err != nil {
return fmt.Errorf("error getting ignition volume: %v", err)
}
ignVolumePath, err := ignVolume.GetPath()
if err != nil {
return fmt.Errorf("error getting ignition volume path: %v", err)
}
} else {
if input.Ignition != nil {
if err := setIgnition(&domainDef, client, input.Ignition, input.KubeClient, input.MachineNamespace, input.IgnitionVolumeName); err != nil {
return err
}
} else if input.IgnKey != "" {
ignVolume, err := client.getVolume(input.IgnKey)
if err != nil {
return fmt.Errorf("error getting ignition volume: %v", err)
}
ignVolumePath, err := ignVolume.GetPath()
if err != nil {
return fmt.Errorf("error getting ignition volume path: %v", err)
}

if err := setCoreOSIgnition(&domainDef, ignVolumePath); err != nil {
return err
}
} else if input.CloudInit != nil {
if err := setCloudInit(&domainDef, client, input.CloudInit, input.KubeClient, input.MachineNamespace, input.CloudInitVolumeName, input.DomainName); err != nil {
return err
}
} else {
return fmt.Errorf("machine does not has a IgnKey nor CloudInit value")
if err := setCoreOSIgnition(&domainDef, ignVolumePath, arch); err != nil {
return err
}
} else if input.CloudInit != nil {
if err := setCloudInit(&domainDef, client, input.CloudInit, input.KubeClient, input.MachineNamespace, input.CloudInitVolumeName, input.DomainName); err != nil {
return err
}
} else {
return fmt.Errorf("machine does not has a IgnKey nor CloudInit value")
}

glog.Info("Set up network interface")
Expand Down
49 changes: 39 additions & 10 deletions pkg/cloud/libvirt/client/domain.go
Expand Up @@ -108,7 +108,8 @@ func newDevicesDef(virConn *libvirt.Connect) *libvirtxml.DomainDeviceList {
}
// Both "s390" and "s390x" are linux kernel architectures for Linux on IBM z Systems, and they are for 31-bit and 64-bit respectively.
// Graphics/Spice isn't supported on s390/s390x platform.
if arch != "s390x" && arch != "s390" {
// Same case for PowerPC systems as well
if !strings.HasPrefix(arch, "s390") && !strings.HasPrefix(arch, "ppc64") {
domainList.Graphics = []libvirtxml.DomainGraphic{
{
Spice: &libvirtxml.DomainGraphicSpice{
Expand Down Expand Up @@ -218,20 +219,48 @@ func newDomainDefForConnection(virConn *libvirt.Connect) (libvirtxml.Domain, err
return d, nil
}

func setCoreOSIgnition(domainDef *libvirtxml.Domain, ignKey string) error {
func setCoreOSIgnition(domainDef *libvirtxml.Domain, ignKey string, arch string) error {
if ignKey == "" {
return fmt.Errorf("error setting coreos ignition, ignKey is empty")
}
domainDef.QEMUCommandline = &libvirtxml.DomainQEMUCommandline{
Args: []libvirtxml.DomainQEMUCommandlineArg{
{
// https://github.com/qemu/qemu/blob/master/docs/specs/fw_cfg.txt
Value: "-fw_cfg",
if strings.HasPrefix(arch, "s390") || strings.HasPrefix(arch, "ppc64") {
// System Z and PowerPC do not support the Firmware Configuration
// device. After a discussion about the best way to support a similar
// method for qemu in https://github.com/coreos/ignition/issues/928,
// decided on creating a virtio-blk device with a serial of ignition
// which contains the ignition config and have ignition support for
// reading from the device which landed in https://github.com/coreos/ignition/pull/936
igndisk := libvirtxml.DomainDisk{
Device: "disk",
Source: &libvirtxml.DomainDiskSource{
File: &libvirtxml.DomainDiskSourceFile{
File: ignKey,
},
},
{
Value: fmt.Sprintf("name=opt/com.coreos/config,file=%s", ignKey),
Target: &libvirtxml.DomainDiskTarget{
Dev: "vdb",
Bus: "virtio",
},
},
Driver: &libvirtxml.DomainDiskDriver{
Name: "qemu",
Type: "raw",
},
ReadOnly: &libvirtxml.DomainDiskReadOnly{},
Serial: "ignition",
}
domainDef.Devices.Disks = append(domainDef.Devices.Disks, igndisk)
} else {
domainDef.QEMUCommandline = &libvirtxml.DomainQEMUCommandline{
Args: []libvirtxml.DomainQEMUCommandlineArg{
{
// https://github.com/qemu/qemu/blob/master/docs/specs/fw_cfg.txt
Value: "-fw_cfg",
},
{
Value: fmt.Sprintf("name=opt/com.coreos/config,file=%s", ignKey),
},
},
}
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/libvirt/client/domain_test.go
@@ -1,6 +1,7 @@
package client

import (
"runtime"
"testing"

libvirtxml "github.com/libvirt/libvirt-go-xml"
Expand Down Expand Up @@ -28,7 +29,7 @@ TestCases:
for i, tc := range testCases {
domainDef := libvirtxml.Domain{}

err := setCoreOSIgnition(&domainDef, tc.ignKey)
err := setCoreOSIgnition(&domainDef, tc.ignKey, runtime.GOARCH)
// if err, verify it returns expected error
if err != nil {
if err.Error() != tc.errorMessage {
Expand Down
47 changes: 38 additions & 9 deletions pkg/cloud/libvirt/client/ignition.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -15,7 +16,7 @@ import (
providerconfigv1 "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1"
)

func setIgnition(domainDef *libvirtxml.Domain, client *libvirtClient, ignition *providerconfigv1.Ignition, kubeClient kubernetes.Interface, machineNamespace, volumeName string) error {
func setIgnition(domainDef *libvirtxml.Domain, client *libvirtClient, ignition *providerconfigv1.Ignition, kubeClient kubernetes.Interface, machineNamespace, volumeName string, arch string) error {
glog.Info("Creating ignition file")
ignitionDef := newIgnitionDef()

Expand Down Expand Up @@ -43,16 +44,44 @@ func setIgnition(domainDef *libvirtxml.Domain, client *libvirtClient, ignition *
return err
}

domainDef.QEMUCommandline = &libvirtxml.DomainQEMUCommandline{
Args: []libvirtxml.DomainQEMUCommandlineArg{
{
// https://github.com/qemu/qemu/blob/master/docs/specs/fw_cfg.txt
Value: "-fw_cfg",
if strings.HasPrefix(arch, "s390") || strings.HasPrefix(arch, "ppc64") {
// System Z and PowerPC do not support the Firmware Configuration
// device. After a discussion about the best way to support a similar
// method for qemu in https://github.com/coreos/ignition/issues/928,
// decided on creating a virtio-blk device with a serial of ignition
// which contains the ignition config and have ignition support for
// reading from the device which landed in https://github.com/coreos/ignition/pull/936
igndisk := libvirtxml.DomainDisk{
Device: "disk",
Source: &libvirtxml.DomainDiskSource{
File: &libvirtxml.DomainDiskSourceFile{
File: ignitionVolumeName,
},
},
{
Value: fmt.Sprintf("name=opt/com.coreos/config,file=%s", ignitionVolumeName),
Target: &libvirtxml.DomainDiskTarget{
Dev: "vdb",
Bus: "virtio",
},
},
Driver: &libvirtxml.DomainDiskDriver{
Name: "qemu",
Type: "raw",
},
ReadOnly: &libvirtxml.DomainDiskReadOnly{},
Serial: "ignition",
}
domainDef.Devices.Disks = append(domainDef.Devices.Disks, igndisk)
} else {
domainDef.QEMUCommandline = &libvirtxml.DomainQEMUCommandline{
Args: []libvirtxml.DomainQEMUCommandlineArg{
{
// https://github.com/qemu/qemu/blob/master/docs/specs/fw_cfg.txt
Value: "-fw_cfg",
},
{
Value: fmt.Sprintf("name=opt/com.coreos/config,file=%s", ignitionVolumeName),
},
},
}
}
return nil
}
Expand Down
167 changes: 0 additions & 167 deletions pkg/cloud/libvirt/client/s390_ignition.go

This file was deleted.

0 comments on commit 58b3735

Please sign in to comment.