Skip to content

Commit b926998

Browse files
committed
use network instead of ipconfig
1 parent febf64b commit b926998

File tree

12 files changed

+69
-165
lines changed

12 files changed

+69
-165
lines changed

api/v1beta1/cloudinit_types.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package v1beta1
22

3-
// CloudInit defines options related to the bootstrapping systems where
4-
// CloudInit is used.
3+
// CloudInit is passed through raw yaml file not Proxmox API
4+
// so you can configure more detailed configs
55
type CloudInit struct {
66
User *User `json:"user,omitempty"`
7-
8-
// Meta *Meta `json:"-"`
9-
10-
// DEPRECATED : use IPConfig instead
11-
Network *Network `json:"-"`
127
}
138

149
type User struct {
@@ -25,30 +20,6 @@ type User struct {
2520
RunCmd []string `yaml:"runcmd,omitempty" json:"-"`
2621
}
2722

28-
type Network struct {
29-
Version int `yaml:"version,omitempty" json:"version,omitempty"`
30-
Config []NetworkConfig `yaml:"config,omitempty" json:"config,omitempty"`
31-
}
32-
33-
type NetworkConfig struct {
34-
Type string `yaml:"type,omitempty" json:"type,omitempty"`
35-
Name string `yaml:"name,omitempty" json:"name,omitempty"`
36-
MacAddress string `yaml:"mac_address,omitempty" json:"mac_address,omitempty"`
37-
Subnets []Subnet `yaml:"subnets,omitempty" json:"subnets,omitempty"`
38-
Destination string `yaml:"destination,omitempty" json:"destination,omitempty"`
39-
Gateway string `yaml:"gateway,omitempty" json:"gateway,omitempty"`
40-
}
41-
42-
type Subnet struct {
43-
Type string `yaml:"type,omitempty" json:"type,omitempty"`
44-
Address string `yaml:"address,omitempty" json:"address,omitempty"`
45-
NetMask string `yaml:"netmask,omitempty" json:"netmask,omitempty"`
46-
Gateway string `yaml:"gateway,omitempty" json:"gateway,omitempty"`
47-
}
48-
49-
type Meta struct {
50-
}
51-
5223
type GrowPart struct {
5324
Mode string `yaml:"mode,omitempty" json:"-"`
5425
Devices []string `yaml:"devices,omitempty" json:"-"`

api/v1beta1/proxmoxmachine_types.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ type ProxmoxMachineSpec struct {
4646
// +optional
4747
CloudInit CloudInit `json:"cloudInit,omitempty"`
4848

49-
// IPConfig
50-
// to do : should accept multiple IPConfig
51-
IPConfig IPConfig `json:"ipConfig,omitempty"`
49+
// Network
50+
Network Network `json:"network,omitempty"`
5251

5352
// FailureDomain is the failure domain unique identifier this Machine should be attached to, as defined in Cluster API.
5453
// For this infrastructure provider, the ID is equivalent to an AWS Availability Zone.

api/v1beta1/type.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,28 @@ type ObjectReference struct {
3030
// ChecksumType *string `json:"checksumType,omitempty"`
3131
// }
3232

33+
// Network
34+
// cloud-init network configuration is configured through Proxmox API
35+
// it may be migrated to raw yaml way from Proxmox API way in the future
36+
type Network struct {
37+
// to do : should accept multiple IPConfig
38+
IPConfig IPConfig `json:"ipConfig,omitempty"`
39+
40+
// DNS server
41+
NameServer string `json:"nameServer,omitempty"`
42+
43+
// search domain
44+
SearchDomain string `json:"searchDomain,omitempty"`
45+
}
46+
3347
// IPConfig
3448
type IPConfig struct {
3549
IP string `json:"ip,omitempty"`
3650
Gateway4 string `json:"gateway,omitempty"`
51+
DHCP bool `json:"dhcp,omitempty"`
3752
}
3853

54+
// to do : user better logic
3955
func (i *IPConfig) String() string {
4056
config := ""
4157
if i.IP != "" {
@@ -47,6 +63,9 @@ func (i *IPConfig) String() string {
4763
if i.Gateway4 != "" {
4864
config += fmt.Sprintf("gw=%s", i.Gateway4)
4965
}
66+
if config == "" {
67+
config = "ip=dhcp"
68+
}
5069
return config
5170
}
5271

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 2 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/cloudinit/network.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

cloud/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type MachineGetter interface {
6060
GetInstanceStatus() *infrav1.InstanceStatus
6161
GetStorage() infrav1.Storage
6262
GetCloudInit() infrav1.CloudInit
63-
GetIPConfig() infrav1.IPConfig
63+
GetNetwork() infrav1.Network
6464
}
6565

6666
// MachineSetter is an interface which can set machine information.

cloud/scope/machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ func (m *MachineScope) GetCloudInit() infrav1.CloudInit {
155155
return m.ProxmoxMachine.Spec.CloudInit
156156
}
157157

158-
func (m *MachineScope) GetIPConfig() infrav1.IPConfig {
159-
return m.ProxmoxMachine.Spec.IPConfig
158+
func (m *MachineScope) GetNetwork() infrav1.Network {
159+
return m.ProxmoxMachine.Spec.Network
160160
}
161161

162162
// SetProviderID sets the ProxmoxMachine providerID in spec.

cloud/services/compute/instance/cloudinit.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,6 @@ func reconcileCloudInitUser(vmid int, vmName, storageName, bootstrap string, con
5252
return nil
5353
}
5454

55-
// DEPRECATED : network can be configured via API with ipconfig params
56-
func reconcileCloudInitConfig(vmid int, vmName, storageName string, cloudInit infrav1.CloudInit, ssh scope.SSHClient) error {
57-
58-
if cloudInit.Network != nil {
59-
networkYaml, err := cloudinit.GenerateNetworkYaml(*cloudInit.Network)
60-
if err != nil {
61-
return err
62-
}
63-
out, err := ssh.RunWithStdin(fmt.Sprintf("tee /var/lib/vz/%s/snippets/%s-network.yml", storageName, vmName), networkYaml)
64-
if err != nil {
65-
return errors.Errorf("ssh command error : %s : %v", out, err)
66-
}
67-
}
68-
69-
// if meta != nil {
70-
// metaYaml, err := cloudinit.GenerateMetaYaml(*meta)
71-
// if err != nil {
72-
// return err
73-
// }
74-
// out, err := ssh.RunWithStdin(fmt.Sprintf("tee /var/lib/vz/%s/snippets/%s-meta.yml", storageName, vmName), metaYaml)
75-
// if err != nil {
76-
// return errors.Errorf("ssh command error : %s : %v", out, err)
77-
// }
78-
// }
79-
80-
return nil
81-
}
82-
8355
// DEPRECATED : cicustom should be set via API
8456
func ApplyCICustom(vmid int, vmName, storageName, ciType string, ssh scope.SSHClient) error {
8557
if !cloudinit.IsValidType(ciType) {

cloud/services/compute/instance/reconcile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (s *Service) CreateInstance(ctx context.Context, bootstrap string) (*vm.Vir
114114
}
115115

116116
// create vm
117-
vmoption := generateVMOptions(s.scope.Name(), s.scope.GetStorage().Name, s.scope.GetIPConfig())
117+
vmoption := generateVMOptions(s.scope.Name(), s.scope.GetStorage().Name, s.scope.GetNetwork())
118118
vm, err := node.CreateVirtualMachine(vmid, vmoption)
119119
if err != nil {
120120
log.Error(err, "failed to create virtual machine")
@@ -203,7 +203,7 @@ func SetCloudImage(ctx context.Context, vmid int, storageName string, ssh scope.
203203
return nil
204204
}
205205

206-
func generateVMOptions(vmName, storageName string, ipconfig infrav1.IPConfig) vm.VirtualMachineCreateOptions {
206+
func generateVMOptions(vmName, storageName string, network infrav1.Network) vm.VirtualMachineCreateOptions {
207207

208208
vmoptions := vm.VirtualMachineCreateOptions{
209209
Agent: "enabled=1",
@@ -213,7 +213,7 @@ func generateVMOptions(vmName, storageName string, ipconfig infrav1.IPConfig) vm
213213
Boot: "order=scsi0",
214214
Ide: vm.Ide{Ide2: fmt.Sprintf("file=%s:cloudinit,media=cdrom", storageName)},
215215
CiCustom: fmt.Sprintf("user=%s:snippets/%s-user.yml", storageName, vmName),
216-
IPConfig: vm.IPConfig{IPConfig0: ipconfig.String()},
216+
IPConfig: vm.IPConfig{IPConfig0: network.IPConfig.String()},
217217
OSType: vm.L26,
218218
Net: vm.Net{Net0: "model=virtio,bridge=vmbr0,firewall=1"},
219219
Scsi: vm.Scsi{Scsi0: fmt.Sprintf("file=%s:8", storageName)},

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,24 @@ spec:
6464
Zone. If multiple subnets are matched for the availability zone,
6565
the first one returned is picked.
6666
type: string
67-
ipConfig:
68-
description: 'IPConfig to do : should accept multiple IPConfig'
67+
network:
68+
description: Network
6969
properties:
70-
gateway:
70+
ipConfig:
71+
description: 'to do : should accept multiple IPConfig'
72+
properties:
73+
dhcp:
74+
type: boolean
75+
gateway:
76+
type: string
77+
ip:
78+
type: string
79+
type: object
80+
nameServer:
81+
description: DNS server
7182
type: string
72-
ip:
83+
searchDomain:
84+
description: search domain
7385
type: string
7486
type: object
7587
providerID:

0 commit comments

Comments
 (0)