Bug 2213449

Summary: cloud-init fails when configuring both network and SSH key from the OpenShift console
Product: Container Native Virtualization (CNV) Reporter: Dieter <ddemoiti>
Component: User ExperienceAssignee: Tal Nisan <tnisan>
Status: NEW --- QA Contact: Guohua Ouyang <gouyang>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 4.12.3CC: dholler, fdeutsch, nashok
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Dieter 2023-06-08 07:55:27 UTC
# Description of problem:
When creating a virtual machine from the console, adding both network information and an SSH key via cloud-init does not work.

# How reproducible:
100%

# Steps to Reproduce:
1: From the console, create a RHEL9 VM using the template, customize virtual machine 
2: Add a secondary Network interface
3: Go to scripts => Edit cloudinit => "Add network data" => use
Ethernet name: eth1
IP addresses: 10.10.21.32/24
4: Authorized SSH Key => Edit and add a public key
5: Go to yaml and make changes to work around https://bugzilla.redhat.com/show_bug.cgi?id=2213073
6: Create virtual machine

A code snippet of the VirtualMachine I created: 
```
    spec:
      accessCredentials:
        - sshPublicKey:
            propagationMethod:
              configDrive: {}
            source:
              secret:
                secretName: rhel9-6hwr6fv1xm7axnm6-ssh-key-hsby3p
....
        - cloudInitConfigDrive:
            networkData: |
              network:
                version: 1
                config:
                  - type: physical
                    name: eth1
                    subnets:
                      - type: static
                        address: 10.10.21.32.24
            userData: |
              #cloud-config
              user: cloud-user
              password: cloud-user
              chpasswd:
                expire: false
```                
                

# Actual results:
Neither the cloud-user password, the SSH key or the networking was configured on the VM. (login does not work, and ping does not work)

# Expected results:
The static IP to be configured, and the password and SSH key for the cloud user to be set.
Note that when leaving out the network configuration, the SSH key and cloud user password is set correctly.

# Additional info:
OpenShift virt by default uses cloudInitNoCloud, but this get's changed to cloudInitConfigDrive when configuring the SSH keys. When looking at the documentation of using Config drive, I could not find any information related to network configuration (https://cloudinit.readthedocs.io/en/latest/reference/datasources/configdrive.html ). Maybe the issue is related to that.

Using cloudInitNoCloud rather than cloudInitConfigDrive and pasting the SSH key directly in the userData works for me. However, in this case the (public) SSH key is stored as clear text in the custom resource, rather than stored in a Kubernetes secret .

```                
        - cloudInitNoCloud:
            networkData: |
              network:
                version: 1
                config:
                  - type: physical
                    name: eth0
                    subnets:
                      - type: static
                        address: {{ host'] }}/24
                        gateway: {{ gateway }}
                        dns_nameservers: {{ dns }}
            userData: |
              #cloud-config
              user: cloud-user
              password: cloud-user
              chpasswd:
                expire: false
              hostname: {{ hostname }}
              ssh_authorized_keys:
                - {{ ssh_key }}
```