Skip to content

Commit cc16ece

Browse files
authored
Merge pull request #2134 from qinqon/kubevirt-nocloud
kubevirt: Support nocloud user-data
2 parents 55943e7 + 04aefad commit cc16ece

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)