Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigDrive support + fix on dns search #553

Merged
merged 5 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions docs/cloud-init-data-generation.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Cloud-init data generation

The [cloud-init](http://cloudinit.readthedocs.io/en/latest/index.html)
data generated by Virtlet consists of `meta-data` and `user-data`
data generated by Virtlet consists of `meta-data`, `user-data` and `network-config`
parts. It's currently provided by means of
[no-cloud](http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html)
[NoCloud](http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html)
and [Config Drive](http://cloudinit.readthedocs.io/en/latest/topics/datasources/configdrive.html)
datasource, which in this case involves making an iso9660 image to be
mounted by the VM. An implementation of either
[Amazon EC2](http://cloudinit.readthedocs.io/en/latest/topics/datasources/ec2.html)
or
[OpenStack](http://cloudinit.readthedocs.io/en/latest/topics/datasources/openstack.html)
datasource can be added later.

## Output ISO image format

Virtlet supports two types of Cloud-init ISO9660-based datasources, NoCloud and
ConfigDrive. The user may choose an appropriate one using
`VirtletCloudInitImageType` annotation, which can have either `nocloud` or
`configdrive` as its value. When there's no `VirtletCloudInitImageType`
annotation, Virtlet defaults to `nocloud`.

## Basic idea with an example

Expand Down Expand Up @@ -149,6 +157,9 @@ The `meta-data` part is a piece of JSON that looks like this:
}
```

In case of ConfigDrive, this JSON has `instance-id` repeated as `uuid` and
`local-hostname` repeated as `hostname`.

We're using JSON format here so as to be compatible with older
cloud-init implementations such as one used in
[CirrOS](https://launchpad.net/cirros) images which are used to test
Expand Down Expand Up @@ -194,10 +205,8 @@ users:
```

[Network configuration](http://cloudinit.readthedocs.io/en/latest/topics/network-config.html)
options may be added here later, too. There's an idea to circumvent
the limitations of DHCP server that make it hard to use more complex
CNI implementations like Calico with the VMs by applying the network
configuration via the cloud-init mechanism.
uses YAML to provide data in
[Network Config Version 1](http://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v1.html).

The `user-data` content is generated as follows:
* `mounts` are generated based on `volumeMount` options of the
Expand Down
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