Skip to content

Commit 04aefad

Browse files
committed
kubevirt: Support nocloud user-data
At kubevirt one can configure the cloud init as config drive or nocloud, with config drive is the current approch, this change add the nocloud that spect a device mount with "cidata" label and tue user data file at /user-data there, also the main different if that on those cases the network data follows the netplan v1 or v2 that's is better format than the openstack meta data network service one. Signed-off-by: Enrique Llorente <ellorent@redhat.com>
1 parent 55943e7 commit 04aefad

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

docs/release-notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ nav_order: 9
1010

1111
### Features
1212

13+
- Add support for nocloud config fetching in kubevirt
14+
1315
### Changes
1416

1517
### Bug fixes

docs/supported-platforms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Ignition is currently supported for the following platforms:
2020
* [Hetzner Cloud] (`hetzner`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately.
2121
* [Microsoft Hyper-V] (`hyperv`) - Ignition will read its configuration from the `ignition.config` key in pool 0 of the Hyper-V Data Exchange Service (KVP). Values are limited to approximately 1 KiB of text, so Ignition can also read and concatenate multiple keys named `ignition.config.0`, `ignition.config.1`, and so on.
2222
* [IBM Cloud] (`ibmcloud`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately.
23-
* [KubeVirt] (`kubevirt`) - Ignition will read its configuration from the instance userdata via config drive. Cloud SSH keys are handled separately.
23+
* [KubeVirt] (`kubevirt`) - Ignition will read its configuration from the instance userdata via `cloudInitConfigDrive` or `cloudInitNoCloud`. Cloud SSH keys are handled separately.
2424
* Bare Metal (`metal`) - Use the `ignition.config.url` kernel parameter to provide a URL to the configuration. The URL can use the `http://`, `https://`, `tftp://`, `s3://`, `arn:`, or `gs://` schemes to specify a remote config.
2525
* [Nutanix] (`nutanix`) - Ignition will read its configuration from the instance userdata via config drive. Cloud SSH keys are handled separately.
2626
* [OpenStack] (`openstack`) - Ignition will read its configuration from the instance userdata via either metadata service or config drive. Cloud SSH keys are handled separately.

internal/providers/kubevirt/kubevirt.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
)
3838

3939
const (
40+
nocloudUserdataPath = "/user-data"
4041
configDriveUserdataPath = "/openstack/latest/user_data"
4142
)
4243

@@ -48,9 +49,15 @@ func init() {
4849
}
4950

5051
func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
51-
data, err := fetchConfigFromDevice(f.Logger, filepath.Join(distro.DiskByLabelDir(), "config-2"))
52+
// Try nocloud (cidata) first
53+
data, err := fetchConfigFromDevice(f.Logger, filepath.Join(distro.DiskByLabelDir(), "cidata"), nocloudUserdataPath)
5254
if err != nil {
53-
return types.Config{}, report.Report{}, err
55+
f.Logger.Debug("failed to fetch from nocloud cidata: %v, trying config-2 fallback", err)
56+
// Fall back to config-2 (OpenStack format)
57+
data, err = fetchConfigFromDevice(f.Logger, filepath.Join(distro.DiskByLabelDir(), "config-2"), configDriveUserdataPath)
58+
if err != nil {
59+
return types.Config{}, report.Report{}, err
60+
}
5461
}
5562

5663
return util.ParseConfig(f.Logger, data)
@@ -61,7 +68,7 @@ func fileExists(path string) bool {
6168
return (err == nil)
6269
}
6370

64-
func fetchConfigFromDevice(logger *log.Logger, path string) ([]byte, error) {
71+
func fetchConfigFromDevice(logger *log.Logger, path string, userdataPath string) ([]byte, error) {
6572
// There is not always a config drive in kubevirt, but we can limit ignition usage
6673
// to VMs with config drives. Block forever if there is none.
6774
for !fileExists(path) {
@@ -93,10 +100,10 @@ func fetchConfigFromDevice(logger *log.Logger, path string) ([]byte, error) {
93100
)
94101
}()
95102

96-
mntConfigDriveUserdataPath := filepath.Join(mnt, configDriveUserdataPath)
97-
if !fileExists(mntConfigDriveUserdataPath) {
103+
mntUserdataPath := filepath.Join(mnt, userdataPath)
104+
if !fileExists(mntUserdataPath) {
98105
return nil, nil
99106
}
100107

101-
return os.ReadFile(mntConfigDriveUserdataPath)
108+
return os.ReadFile(mntUserdataPath)
102109
}

0 commit comments

Comments
 (0)