Skip to content

Commit

Permalink
Libvirt: Change the libvirt Volumename for s390x architecture
Browse files Browse the repository at this point in the history
For s390x Architecture, it requires the different volume name.  Changed the volumename in createCloudInit function based on the architecture
Signed-off-by : savitrilh <[email protected]>
  • Loading branch information
savitrilh committed Dec 11, 2024
1 parent e181107 commit 9ae2103
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/cloud-providers/libvirt/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
)

const (
userDataFilename = "user-data"
metaDataFilename = "meta-data"
vendorDataFilename = "vendor-data"
ciDataVolumeName = "cidata"
userDataFilename = "user-data"
metaDataFilename = "meta-data"
vendorDataFilename = "vendor-data"
ciDataVolumeName = "cidata"
ciDatas390xVolumeName = "cc_cidata"
ARCHS390x = "s390x"
)

// createCloudInit produces a cloud init ISO file as a data blob with a userdata and a metadata section
func createCloudInit(userData, metaData []byte) ([]byte, error) {
func createCloudInit(userData, metaData []byte, arch string) ([]byte, error) {
writer, err := iso9660.NewWriter()
if err != nil {
return nil, err
Expand All @@ -40,8 +42,12 @@ func createCloudInit(userData, metaData []byte) ([]byte, error) {
}

var buf bytes.Buffer

err = writer.WriteTo(&buf, ciDataVolumeName)
// Assign different volumeName for s390x architecture
if arch == ARCHS390x {
err = writer.WriteTo(&buf, ciDatas390xVolumeName)
} else {
err = writer.WriteTo(&buf, ciDataVolumeName)
}
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion src/cloud-providers/libvirt/cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func TestCloudInit(t *testing.T) {

userDataContent := []byte("userdata")
metaDataContent := []byte("metadata")
arch := "s390x"

isoData, err := createCloudInit(userDataContent, metaDataContent)
isoData, err := createCloudInit(userDataContent, metaDataContent, arch)
require.NoError(t, err)

err = os.WriteFile(file.Name(), isoData, os.ModePerm)
Expand Down
8 changes: 4 additions & 4 deletions src/cloud-providers/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func (s *sevGuestPolicy) getGuestPolicy() uint {
}

// createCloudInitISO creates an ISO file with a userdata and a metadata file. The ISO image will be created in-memory since it is small
func createCloudInitISO(v *vmConfig) ([]byte, error) {
func createCloudInitISO(v *vmConfig, arch string) ([]byte, error) {
logger.Println("Create cloudInit iso")

userData := v.userData
metaData := fmt.Sprintf("local-hostname: %s", v.name)

return createCloudInit([]byte(userData), []byte(metaData))
return createCloudInit([]byte(userData), []byte(metaData), arch)
}

func checkDomainExistsByName(name string, libvirtClient *libvirtClient) (exist bool, err error) {
Expand Down Expand Up @@ -680,8 +680,8 @@ func CreateDomain(ctx context.Context, libvirtClient *libvirtClient, v *vmConfig
if err != nil {
return nil, fmt.Errorf("Error in creating volume: %s", err)
}

cloudInitIso, err := createCloudInitISO(v)
// Pass the architecture to createCloudInitISO(), Use this value to take action for specific architecture.
cloudInitIso, err := createCloudInitISO(v, libvirtClient.nodeInfo.Model)
if err != nil {
return nil, fmt.Errorf("error in creating cloud init ISO file, cause: %w", err)
}
Expand Down

0 comments on commit 9ae2103

Please sign in to comment.