Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor subnet subnetset CRD status #604

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions build/yaml/crd/nsx.vmware.com_subnets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,6 @@ spec:
DHCPConfig:
description: DHCPConfig DHCP configuration.
properties:
dhcpRelayConfigPath:
description: DHCPRelayConfigPath is policy path of DHCP-relay-config.
type: string
dhcpV4PoolSize:
default: 80
description: DHCPV4PoolSize IPs in % to be reserved for DHCP ranges.
By default, 80% of IPv4 IPs will be reserved for DHCP. Configure
0 if no pool is required.
maximum: 100
minimum: 0
type: integer
dhcpV6PoolSize:
default: 2000
description: DHCPV6PoolSize number of IPs to be reserved for DHCP
ranges. By default, 2000 IPv6 IPs will be reserved for DHCP.
type: integer
dnsClientConfig:
description: DNSClientConfig holds DNS configurations.
properties:
dnsServersIPs:
items:
type: string
type: array
type: object
enableDHCP:
default: false
type: boolean
Expand Down Expand Up @@ -116,6 +92,10 @@ spec:
status:
description: SubnetStatus defines the observed state of Subnet.
properties:
DHCPServerAddresses:
items:
type: string
type: array
conditions:
items:
description: Condition defines condition of custom resource.
Expand Down Expand Up @@ -144,7 +124,11 @@ spec:
- type
type: object
type: array
ipAddresses:
gatewayAddresses:
items:
type: string
type: array
networkAddreses:
items:
type: string
type: array
Expand Down
37 changes: 9 additions & 28 deletions build/yaml/crd/nsx.vmware.com_subnetsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,6 @@ spec:
DHCPConfig:
description: DHCPConfig DHCP configuration.
properties:
dhcpRelayConfigPath:
description: DHCPRelayConfigPath is policy path of DHCP-relay-config.
type: string
dhcpV4PoolSize:
default: 80
description: DHCPV4PoolSize IPs in % to be reserved for DHCP ranges.
By default, 80% of IPv4 IPs will be reserved for DHCP. Configure
0 if no pool is required.
maximum: 100
minimum: 0
type: integer
dhcpV6PoolSize:
default: 2000
description: DHCPV6PoolSize number of IPs to be reserved for DHCP
ranges. By default, 2000 IPv6 IPs will be reserved for DHCP.
type: integer
dnsClientConfig:
description: DNSClientConfig holds DNS configurations.
properties:
dnsServersIPs:
items:
type: string
type: array
type: object
enableDHCP:
default: false
type: boolean
Expand Down Expand Up @@ -142,15 +118,20 @@ spec:
description: SubnetInfo defines the observed state of a single Subnet
of a SubnetSet.
properties:
ipAddresses:
DHCPServerAddresses:
items:
type: string
type: array
gatewayAddresses:
items:
type: string
type: array
networkAddresses:
items:
type: string
type: array
nsxResourcePath:
type: string
required:
- ipAddresses
- nsxResourcePath
type: object
type: array
type: object
Expand Down
22 changes: 5 additions & 17 deletions pkg/apis/nsx.vmware.com/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ type SubnetSpec struct {

// SubnetStatus defines the observed state of Subnet.
type SubnetStatus struct {
NSXResourcePath string `json:"nsxResourcePath,omitempty"`
IPAddresses []string `json:"ipAddresses,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
NSXResourcePath string `json:"nsxResourcePath,omitempty"`
NetworkAddresses []string `json:"networkAddreses,omitempty"`
GatewayAddresses []string `json:"gatewayAddresses,omitempty"`
DHCPServerAddresses []string `json:"DHCPServerAddresses,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}

// +genclient
Expand Down Expand Up @@ -78,20 +80,6 @@ type StaticIPAllocation struct {
type DHCPConfig struct {
// +kubebuilder:default:=false
EnableDHCP bool `json:"enableDHCP,omitempty"`
timdengyun marked this conversation as resolved.
Show resolved Hide resolved
// DHCPRelayConfigPath is policy path of DHCP-relay-config.
DHCPRelayConfigPath string `json:"dhcpRelayConfigPath,omitempty"`
// DHCPV4PoolSize IPs in % to be reserved for DHCP ranges.
// By default, 80% of IPv4 IPs will be reserved for DHCP.
// Configure 0 if no pool is required.
// +kubebuilder:default:=80
// +kubebuilder:validation:Maximum:=100
// +kubebuilder:validation:Minimum:=0
DHCPV4PoolSize int `json:"dhcpV4PoolSize,omitempty"`
// DHCPV6PoolSize number of IPs to be reserved for DHCP ranges.
// By default, 2000 IPv6 IPs will be reserved for DHCP.
// +kubebuilder:default:=2000
DHCPV6PoolSize int `json:"dhcpV6PoolSize,omitempty"`
DNSClientConfig DNSClientConfig `json:"dnsClientConfig,omitempty"`
}

// DNSClientConfig holds DNS configurations.
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/nsx.vmware.com/v1alpha1/subnetset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type SubnetSetSpec struct {

// SubnetInfo defines the observed state of a single Subnet of a SubnetSet.
type SubnetInfo struct {
NSXResourcePath string `json:"nsxResourcePath"`
IPAddresses []string `json:"ipAddresses"`
NSXResourcePath string `json:"nsxResourcePath,omitempty"`
NetworkAddresses []string `json:"networkAddresses,omitempty"`
GatewayAddresses []string `json:"gatewayAddresses,omitempty"`
DHCPServerAddresses []string `json:"DHCPServerAddresses,omitempty"`
}

// SubnetSetStatus defines the observed state of SubnetSet.
Expand Down
35 changes: 27 additions & 8 deletions pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 5 additions & 17 deletions pkg/apis/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ type SubnetSpec struct {

// SubnetStatus defines the observed state of Subnet.
type SubnetStatus struct {
NSXResourcePath string `json:"nsxResourcePath,omitempty"`
IPAddresses []string `json:"ipAddresses,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
NSXResourcePath string `json:"nsxResourcePath,omitempty"`
NetworkAddresses []string `json:"networkAddreses,omitempty"`
GatewayAddresses []string `json:"gatewayAddresses,omitempty"`
DHCPServerAddresses []string `json:"DHCPServerAddresses,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}

// +genclient
Expand Down Expand Up @@ -78,20 +80,6 @@ type StaticIPAllocation struct {
type DHCPConfig struct {
// +kubebuilder:default:=false
EnableDHCP bool `json:"enableDHCP,omitempty"`
// DHCPRelayConfigPath is policy path of DHCP-relay-config.
DHCPRelayConfigPath string `json:"dhcpRelayConfigPath,omitempty"`
// DHCPV4PoolSize IPs in % to be reserved for DHCP ranges.
// By default, 80% of IPv4 IPs will be reserved for DHCP.
// Configure 0 if no pool is required.
// +kubebuilder:default:=80
// +kubebuilder:validation:Maximum:=100
// +kubebuilder:validation:Minimum:=0
DHCPV4PoolSize int `json:"dhcpV4PoolSize,omitempty"`
// DHCPV6PoolSize number of IPs to be reserved for DHCP ranges.
// By default, 2000 IPv6 IPs will be reserved for DHCP.
// +kubebuilder:default:=2000
DHCPV6PoolSize int `json:"dhcpV6PoolSize,omitempty"`
DNSClientConfig DNSClientConfig `json:"dnsClientConfig,omitempty"`
}

// DNSClientConfig holds DNS configurations.
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/v1alpha1/subnetset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type SubnetSetSpec struct {

// SubnetInfo defines the observed state of a single Subnet of a SubnetSet.
type SubnetInfo struct {
NSXResourcePath string `json:"nsxResourcePath"`
IPAddresses []string `json:"ipAddresses"`
NSXResourcePath string `json:"nsxResourcePath,omitempty"`
NetworkAddresses []string `json:"networkAddresses,omitempty"`
GatewayAddresses []string `json:"gatewayAddresses,omitempty"`
DHCPServerAddresses []string `json:"DHCPServerAddresses,omitempty"`
}

// SubnetSetStatus defines the observed state of SubnetSet.
Expand Down
35 changes: 27 additions & 8 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions pkg/controllers/subnet/subnet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ func (r *SubnetReconciler) updateSubnetStatus(obj *v1alpha1.Subnet) error {
if nsxSubnet == nil {
return errors.New("failed to get NSX Subnet from store")
}
obj.Status.IPAddresses = obj.Status.IPAddresses[:0]
obj.Status.NetworkAddresses = obj.Status.NetworkAddresses[:0]
obj.Status.GatewayAddresses = obj.Status.GatewayAddresses[:0]
obj.Status.DHCPServerAddresses = obj.Status.DHCPServerAddresses[:0]
statusList, err := r.SubnetService.GetSubnetStatus(nsxSubnet)
if err != nil {
return err
}
for _, status := range statusList {
obj.Status.IPAddresses = append(obj.Status.IPAddresses, *status.NetworkAddress)
obj.Status.NetworkAddresses = append(obj.Status.NetworkAddresses, *status.NetworkAddress)
obj.Status.GatewayAddresses = append(obj.Status.GatewayAddresses, *status.GatewayAddress)
// DHCPServerAddress is only for the subnet with DHCP enabled
if status.DhcpServerAddress != nil {
obj.Status.DHCPServerAddresses = append(obj.Status.DHCPServerAddresses, *status.DhcpServerAddress)
}
}
obj.Status.NSXResourcePath = *nsxSubnet.Path
return nil
Expand Down
7 changes: 6 additions & 1 deletion pkg/nsx/services/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ func (service *SubnetService) UpdateSubnetSetStatus(obj *v1alpha1.SubnetSet) err
NSXResourcePath: *subnet.Path,
}
for _, status := range statusList {
subnetInfo.IPAddresses = append(subnetInfo.IPAddresses, *status.NetworkAddress)
subnetInfo.NetworkAddresses = append(subnetInfo.NetworkAddresses, *status.NetworkAddress)
subnetInfo.GatewayAddresses = append(subnetInfo.GatewayAddresses, *status.GatewayAddress)
// DHCPServerAddress is only for the subnet with DHCP enabled
if status.DhcpServerAddress != nil {
subnetInfo.DHCPServerAddresses = append(subnetInfo.DHCPServerAddresses, *status.DhcpServerAddress)
}
}
subnetInfoList = append(subnetInfoList, subnetInfo)
}
Expand Down
Loading
Loading