Skip to content

Commit

Permalink
ConfiDrive support + fix on dns search
Browse files Browse the repository at this point in the history
  • Loading branch information
jellonek committed Jan 14, 2018
1 parent 421e727 commit 8787842
Show file tree
Hide file tree
Showing 22 changed files with 346 additions and 92 deletions.
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestContainerLifecycle.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestDomainDefinitions__cloud-init.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestDomainDefinitions__plain_domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestDomainDefinitions__raw_devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestDomainDefinitions__vcpu_count.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestDomainDefinitions__volumes.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/libvirttools/TestDomainForcedShutdown.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"Auth": null,
"Source": {
"File": "/var/lib/virtlet/nocloud/nocloud-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"File": "/var/lib/virtlet/config/config-231700d5-c9a6-5a49-738d-99a954c51550.iso",
"Device": "",
"Protocol": "",
"Name": "",
Expand Down
18 changes: 17 additions & 1 deletion pkg/libvirttools/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
)

type DiskDriver string
type ImageType string

const (
maxVCPUCount = 255
Expand All @@ -40,15 +41,19 @@ const (
CloudInitUserDataSourceKeyName = "VirtletCloudInitUserDataSource"
CloudInitUserDataOverwriteKeyName = "VirtletCloudInitUserDataOverwrite"
CloudInitUserDataScriptKeyName = "VirtletCloudInitUserDataScript"
CloudInitImageType = "VirtletCloudInitImageType"
SSHKeysKeyName = "VirtletSSHKeys"
SSHKeySourceKeyName = "VirtletSSHKeySource"
DiskDriverKeyName = "VirtletDiskDriver"
DiskDriverVirtio DiskDriver = "virtio"
DiskDriverScsi DiskDriver = "scsi"
ImageTypeNoCloud ImageType = "nocloud"
ImageTypeConfigDrive ImageType = "configdrive"
)

type VirtletAnnotations struct {
VCPUCount int
ImageType ImageType
MetaData map[string]interface{}
UserData map[string]interface{}
UserDataOverwrite bool
Expand Down Expand Up @@ -119,17 +124,24 @@ func (va *VirtletAnnotations) parsePodAnnotations(ns string, podAnnotations map[
}
}

va.ImageType = ImageType(strings.ToLower(podAnnotations[CloudInitImageType]))
va.DiskDriver = DiskDriver(podAnnotations[DiskDriverKeyName])

return nil
}

func (va *VirtletAnnotations) applyDefaults() {
if va.VCPUCount <= 0 {
va.VCPUCount = 1
}

if va.DiskDriver == "" {
va.DiskDriver = DiskDriverScsi
}

if va.ImageType == "" {
va.ImageType = ImageTypeNoCloud
}
}

func (va *VirtletAnnotations) validate() error {
Expand All @@ -139,7 +151,11 @@ func (va *VirtletAnnotations) validate() error {
}

if va.DiskDriver != DiskDriverVirtio && va.DiskDriver != DiskDriverScsi {
errs = append(errs, fmt.Sprintf("bad disk driver %q. Must be either %q or %q", DiskDriverVirtio, DiskDriverScsi))
errs = append(errs, fmt.Sprintf("bad disk driver %q. Must be either %q or %q", va.DiskDriver, DiskDriverVirtio, DiskDriverScsi))
}

if va.ImageType != ImageTypeNoCloud && va.ImageType != ImageTypeConfigDrive {
errs = append(errs, fmt.Sprintf("unknown config image type %q. Must be either %q or %q", va.ImageType, ImageTypeNoCloud, ImageTypeConfigDrive))
}

if errs != nil {
Expand Down
23 changes: 23 additions & 0 deletions pkg/libvirttools/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestVirtletAnnotations(t *testing.T) {
va: &VirtletAnnotations{
VCPUCount: 1,
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
Expand All @@ -42,6 +43,16 @@ func TestVirtletAnnotations(t *testing.T) {
va: &VirtletAnnotations{
VCPUCount: 1,
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
name: "non empty cloud init type annotation",
annotations: map[string]string{"VirtletCloudInitImageType": "configdrive"},
va: &VirtletAnnotations{
VCPUCount: 1,
DiskDriver: "scsi",
ImageType: "configdrive",
},
},
{
Expand All @@ -50,6 +61,7 @@ func TestVirtletAnnotations(t *testing.T) {
va: &VirtletAnnotations{
VCPUCount: 1,
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
Expand All @@ -58,6 +70,7 @@ func TestVirtletAnnotations(t *testing.T) {
va: &VirtletAnnotations{
VCPUCount: 1,
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
Expand All @@ -66,6 +79,7 @@ func TestVirtletAnnotations(t *testing.T) {
va: &VirtletAnnotations{
VCPUCount: 4,
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
Expand Down Expand Up @@ -93,6 +107,7 @@ func TestVirtletAnnotations(t *testing.T) {
},
SSHKeys: []string{"key1", "key2"},
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
Expand All @@ -104,6 +119,7 @@ func TestVirtletAnnotations(t *testing.T) {
VCPUCount: 1,
UserDataOverwrite: true,
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
{
Expand All @@ -115,6 +131,7 @@ func TestVirtletAnnotations(t *testing.T) {
VCPUCount: 1,
UserDataScript: "#!/bin/sh\necho hi\n",
DiskDriver: "scsi",
ImageType: "nocloud",
},
},
// bad metadata items follow
Expand All @@ -132,6 +149,12 @@ func TestVirtletAnnotations(t *testing.T) {
"VirtletCloudInitMetaData": "{",
},
},
{
name: "bad cloud-init image type",
annotations: map[string]string{
"VirtletCloudInitImageType": "ducttape",
},
},
{
name: "bad cloud-init user-data",
annotations: map[string]string{
Expand Down
Loading

0 comments on commit 8787842

Please sign in to comment.