Skip to content

Commit 2213a7b

Browse files
committed
update proxmoxmachine network
1 parent 3349ab8 commit 2213a7b

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

api/v1beta1/type.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1beta1
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/sp-yduck/proxmox/pkg/service/node/vm"
78
)
@@ -57,29 +58,40 @@ type Network struct {
5758
SearchDomain string `json:"searchDomain,omitempty"`
5859
}
5960

60-
// IPConfig
61+
// IPConfig defines IP addresses and gateways for corresponding interface
6162
type IPConfig struct {
62-
IP string `json:"ip,omitempty"`
63-
Gateway4 string `json:"gateway,omitempty"`
64-
DHCP bool `json:"dhcp,omitempty"`
63+
// IPv4 with CIDR
64+
IP string `json:"ip,omitempty"`
65+
// gateway IPv4
66+
Gateway string `json:"gateway,omitempty"`
67+
// IPv6 with CIDR
68+
IP6 string `json:"ip6,omitempty"`
69+
// gateway IPv6
70+
Gateway6 string `json:"gateway6,omitempty"`
6571
}
6672

67-
// to do : user better logic
68-
func (i *IPConfig) String() string {
69-
config := ""
70-
if i.IP != "" {
71-
config += fmt.Sprintf("ip=%s", i.IP)
73+
func (c *IPConfig) String() string {
74+
configs := []string{}
75+
if c.IP != "" {
76+
configs = append(configs, fmt.Sprintf("ip=%s", c.IP))
7277
}
73-
if i.IP != "" && i.Gateway4 != "" {
74-
config += ","
78+
if c.Gateway != "" {
79+
configs = append(configs, fmt.Sprintf("gw=%s", c.Gateway))
7580
}
76-
if i.Gateway4 != "" {
77-
config += fmt.Sprintf("gw=%s", i.Gateway4)
81+
if c.IP6 != "" {
82+
configs = append(configs, fmt.Sprintf("ip6=%s", c.IP6))
7883
}
79-
if config == "" {
80-
config = "ip=dhcp"
84+
if c.Gateway6 != "" {
85+
configs = append(configs, fmt.Sprintf("gw6=%s", c.Gateway6))
8186
}
82-
return config
87+
ipconfig := strings.Join(configs, ",")
88+
89+
// it defaults to using dhcp on IPv4 if neither IP nor IP6 is specified
90+
if !strings.Contains(ipconfig, "ip") {
91+
ipconfig = "ip=dhcp"
92+
}
93+
94+
return ipconfig
8395
}
8496

8597
// Storage for image and snippets

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ spec:
9898
ipConfig:
9999
description: 'to do : should accept multiple IPConfig'
100100
properties:
101-
dhcp:
102-
type: boolean
103101
gateway:
102+
description: gateway IPv4
103+
type: string
104+
gateway6:
105+
description: gateway IPv6
104106
type: string
105107
ip:
108+
description: IPv4 with CIDR
109+
type: string
110+
ip6:
111+
description: IPv6 with CIDR
106112
type: string
107113
type: object
108114
nameServer:

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,17 @@ spec:
136136
ipConfig:
137137
description: 'to do : should accept multiple IPConfig'
138138
properties:
139-
dhcp:
140-
type: boolean
141139
gateway:
140+
description: gateway IPv4
141+
type: string
142+
gateway6:
143+
description: gateway IPv6
142144
type: string
143145
ip:
146+
description: IPv4 with CIDR
147+
type: string
148+
ip6:
149+
description: IPv6 with CIDR
144150
type: string
145151
type: object
146152
nameServer:

0 commit comments

Comments
 (0)