Skip to content

Commit

Permalink
Support codegen for v1alpha2
Browse files Browse the repository at this point in the history
The repo misses the v1alpha2 for codegen.
  • Loading branch information
zhengxiexie committed Aug 17, 2023
1 parent 597057f commit f2a0d0c
Show file tree
Hide file tree
Showing 76 changed files with 754 additions and 140 deletions.
1 change: 0 additions & 1 deletion build/yaml/crd/nsx.vmware.com_staticroutes.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
2 changes: 1 addition & 1 deletion build/yaml/crd/nsx.vmware.com_subnetports.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -86,6 +85,7 @@ spec:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
subnet:
description: Subnet defines the parent Subnet name of the SubnetPort.
type: string
Expand Down
1 change: 0 additions & 1 deletion build/yaml/crd/nsx.vmware.com_subnets.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
1 change: 0 additions & 1 deletion build/yaml/crd/nsx.vmware.com_subnetsets.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
1 change: 0 additions & 1 deletion build/yaml/crd/nsx.vmware.com_vpcs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
18 changes: 9 additions & 9 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ APIS=./pkg/apis
APIS_PKG=github.com/vmware-tanzu/nsx-operator/pkg/apis
OUTPUT_PKG=github.com/vmware-tanzu/nsx-operator/pkg/client
GROUP=nsx.vmware.com
VERSION=v1alpha1
GROUP_VERSION=$GROUP:$VERSION

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=$(go env GOMODCACHE)/k8s.io/code-generator@v0.27.1

rm -fr "${APIS:?}/${GROUP:?}"
rm -fr ./pkg/client
mkdir -p "${APIS}/${GROUP}/${VERSION}"
cp -r "${APIS}/${VERSION}"/* "${APIS}/${GROUP}/${VERSION}/"

for VERSION in v1alpha1 v1alpha2; do
mkdir -p "${APIS}/${GROUP}/${VERSION}"
cp -r "${APIS}/${VERSION}"/* "${APIS}/${GROUP}/${VERSION}/"
done

bash "${CODEGEN_PKG}"/generate-groups.sh "client,lister,informer" \
${OUTPUT_PKG} ${APIS_PKG} \
${GROUP_VERSION} \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt \
--output-base "${SCRIPT_ROOT}" -v 10
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
${OUTPUT_PKG} ${APIS_PKG} \
${GROUP}:v1alpha1,v1alpha2 \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt \
--output-base "${SCRIPT_ROOT}" -v 10

mv ./${OUTPUT_PKG} ./pkg/
rm -rf ./github.com
72 changes: 72 additions & 0 deletions pkg/apis/nsx.vmware.com/v1alpha1/ippool_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// IPPool is the Schema for the ippools API.
type IPPool struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`

Spec IPPoolSpec `json:"spec"`
Status IPPoolStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// IPPoolList contains a list of IPPool.
type IPPoolList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []IPPool `json:"items"`
}

// IPPoolSpec defines the desired state of IPPool.
type IPPoolSpec struct {
// Subnets defines set of subnets need to be allocated.
// +optional
Subnets []SubnetRequest `json:"subnets"`
}

// IPPoolStatus defines the observed state of IPPool.
type IPPoolStatus struct {
// Subnets defines subnets allocation result.
Subnets []SubnetResult `json:"subnets"`
// Conditions defines current state of the IPPool.
Conditions []Condition `json:"conditions"`
}

// SubnetRequest defines the subnet allocation request.
type SubnetRequest struct {
// PrefixLength defines prefix length for this subnet.
PrefixLength int `json:"prefixLength,omitempty"`

// IPFamily defines the IP family type for this subnet, could be IPv4 or IPv6.
// This is optional, the default is IPv4.
// +kubebuilder:validation:Enum=IPv4;IPv6
// +kubebuilder:default=IPv4
IPFamily string `json:"ipFamily,omitempty"`

// Name defines the name of this subnet.
Name string `json:"name"`
}

// SubnetResult defines the subnet allocation result.
type SubnetResult struct {
// CIDR defines the allocated CIDR.
CIDR string `json:"cidr"`

// Name defines the name of this subnet.
Name string `json:"name"`
}

func init() {
SchemeBuilder.Register(&IPPool{}, &IPPoolList{})
}
7 changes: 5 additions & 2 deletions pkg/apis/nsx.vmware.com/v1alpha1/staticroute_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2022-2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1
Expand Down Expand Up @@ -31,7 +31,8 @@ type NextHop struct {

// StaticRouteStatus defines the observed state of StaticRoute.
type StaticRouteStatus struct {
Conditions []StaticRouteCondition `json:"conditions"`
Conditions []StaticRouteCondition `json:"conditions"`
NSXResourcePath string `json:"nsxResourcePath"`
}

// +genclient
Expand All @@ -40,6 +41,8 @@ type StaticRouteStatus struct {
//+kubebuilder:storageversion

// StaticRoute is the Schema for the staticroutes API.
// +kubebuilder:printcolumn:name="Network",type=string,JSONPath=`.spec.network`,description="Network in CIDR format"
// +kubebuilder:printcolumn:name="NextHops",type=string,JSONPath=`.spec.nextHops[*].ipAddress`,description="Next Hops"
type StaticRoute struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
17 changes: 10 additions & 7 deletions pkg/apis/nsx.vmware.com/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2022-2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1
Expand All @@ -18,9 +18,9 @@ type SubnetSpec struct {
// +kubebuilder:validation:Minimum:=16
IPv4SubnetSize int `json:"ipv4SubnetSize,omitempty"`
// Access mode of Subnet, accessible only from within VPC or from outside VPC.
// Defaults to private.
// +kubebuilder:default:=private
// +kubebuilder:validation:Enum=private;public
// Defaults to Private.
// +kubebuilder:default:=Private
// +kubebuilder:validation:Enum=Private;Public
AccessMode AccessMode `json:"accessMode,omitempty"`
// Subnet CIDRS.
// +kubebuilder:validation:MinItems=0
Expand All @@ -34,16 +34,19 @@ type SubnetSpec struct {

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

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Subnet is the Schema for the subnets API.
// +kubebuilder:printcolumn:name="AccessMode",type=string,JSONPath=`.spec.accessMode`,description="Access mode of Subnet"
// +kubebuilder:printcolumn:name="IPv4SubnetSize",type=string,JSONPath=`.spec.ipv4SubnetSize`,description="Size of Subnet"
// +kubebuilder:printcolumn:name="IPAddresses",type=string,JSONPath=`.status.ipAddresses[*]`,description="CIDRs for the Subnet"
type Subnet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/nsx.vmware.com/v1alpha1/subnetport_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2022-2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1
Expand Down Expand Up @@ -43,6 +43,9 @@ type SubnetPortIPAddress struct {
//+kubebuilder:subresource:status

// SubnetPort is the Schema for the subnetports API.
// +kubebuilder:printcolumn:name="VIFID",type=string,JSONPath=`.status.vifID`,description="Attachment VIF ID owned by the SubnetPort"
// +kubebuilder:printcolumn:name="IPAddress",type=string,JSONPath=`.status.ipAddresses[0].ip`,description="IP Address of the SubnetPort"
// +kubebuilder:printcolumn:name="MACAddress",type=string,JSONPath=`.status.macAddress`,description="MAC Address of the SubnetPort"
type SubnetPort struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
15 changes: 9 additions & 6 deletions pkg/apis/nsx.vmware.com/v1alpha1/subnetset_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2022-2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1
Expand All @@ -16,9 +16,9 @@ type SubnetSetSpec struct {
// +kubebuilder:validation:Minimum:=16
IPv4SubnetSize int `json:"ipv4SubnetSize,omitempty"`
// Access mode of Subnet, accessible only from within VPC or from outside VPC.
// Defaults to private.
// +kubebuilder:default:=private
// +kubebuilder:validation:Enum=private;public
// Defaults to Private.
// +kubebuilder:default:=Private
// +kubebuilder:validation:Enum=Private;Public
AccessMode AccessMode `json:"accessMode,omitempty"`
// Subnet advanced configuration.
AdvancedConfig AdvancedConfig `json:"advancedConfig,omitempty"`
Expand All @@ -34,15 +34,18 @@ type SubnetInfo struct {

// SubnetSetStatus defines the observed state of SubnetSet.
type SubnetSetStatus struct {
Conditions []Condition `json:"conditions"`
Subnets []SubnetInfo `json:"subnets"`
Conditions []Condition `json:"conditions,omitempty"`
Subnets []SubnetInfo `json:"subnets,omitempty"`
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// SubnetSet is the Schema for the subnetsets API.
// +kubebuilder:printcolumn:name="AccessMode",type=string,JSONPath=`.spec.accessMode`,description="Access mode of Subnet"
// +kubebuilder:printcolumn:name="IPv4SubnetSize",type=string,JSONPath=`.spec.ipv4SubnetSize`,description="Size of Subnet"
// +kubebuilder:printcolumn:name="IPAddresses",type=string,JSONPath=`.status.subnets[*].ipAddresses[*]`,description="CIDRs for the Subnet"
type SubnetSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
27 changes: 9 additions & 18 deletions pkg/apis/nsx.vmware.com/v1alpha1/vpc_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2022-2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1
Expand All @@ -13,6 +13,8 @@ import (
//+kubebuilder:storageversion

// VPC is the Schema for the VPC API
// +kubebuilder:printcolumn:name="SNATIP",type=string,JSONPath=`.status.defaultSNATIP`,description="Default SNAT IP for Private Subnets"
// +kubebuilder:printcolumn:name="LBSubnetCIDR",type=string,JSONPath=`.status.lbSubnetCIDR`,description="CIDR for the load balancer Subnet"
type VPC struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -39,23 +41,12 @@ type VPCStatus struct {
Conditions []Condition `json:"conditions"`
// NSX VPC Policy API resource path.
NSXResourcePath string `json:"nsxResourcePath"`
// Default SNAT IP for private Subnets
DefaultSNATIP string `json:"defaultSNATIP"`
CIDRsUsage VPCCIDRsUsageInfo `json:"cidrsUsage"`
}

type VPCCIDRsUsageInfo struct {
PublicCIDRsUsage CIDRsUsageInfo `json:"publicCIDRsUsage"`
PrivateCIDRsUsage CIDRsUsageInfo `json:"privateCIDRsUsage"`
}

type CIDRsUsageInfo struct {
// Allocated IPs in the IP Block (including IPs used by other VPCs).
Allocated int `json:"allocated"`
// Used IP for the VPC in the IP Block (IPs used only in current VPC).
Used int `json:"used"`
// Total IP number in the IP Block.
Total int `json:"total"`
// Default SNAT IP for Private Subnets.
DefaultSNATIP string `json:"defaultSNATIP"`
// NSX PolicyPath for the load balancer Subnet.
LBSubnetPath string `json:"lbSubnetPath"`
// CIDR for the load balancer Subnet.
LBSubnetCIDR string `json:"lbSubnetCIDR"`
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2022-2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

// +kubebuilder:object:generate=true
Expand All @@ -9,8 +9,8 @@ import (
)

const (
AccessModePublic string = "public"
AccessModePrivate string = "private"
AccessModePublic string = "Public"
AccessModePrivate string = "Private"
)

// Load balancer endpoint configuration.
Expand Down Expand Up @@ -38,7 +38,7 @@ type VPCNetworkConfigurationSpec struct {
// +kubebuilder:validation:MinItems=0
// +kubebuilder:validation:MaxItems=5
ExternalIPv4Blocks []string `json:"externalIPv4Blocks,omitempty"`
// Private IPv4 CIDRs used to allocate private Subnets.
// Private IPv4 CIDRs used to allocate Private Subnets.
// +kubebuilder:validation:MinItems=0
// +kubebuilder:validation:MaxItems=5
PrivateIPv4CIDRs []string `json:"privateIPv4CIDRs,omitempty"`
Expand All @@ -47,8 +47,8 @@ type VPCNetworkConfigurationSpec struct {
// +kubebuilder:default=26
DefaultIPv4SubnetSize int `json:"defaultIPv4SubnetSize,omitempty"`
// DefaultSubnetAccessMode defines the access mode of the default SubnetSet for PodVM and VM.
// Must be public or private.
// +kubebuilder:validation:Enum=public;private
// Must be Public or Private.
// +kubebuilder:validation:Enum=Public;Private
DefaultSubnetAccessMode string `json:"defaultSubnetAccessMode,omitempty"`
}

Expand All @@ -64,9 +64,9 @@ type VPCNetworkConfigurationStatus struct {

// VPCNetworkConfiguration is the Schema for the vpcnetworkconfigurations API.
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:printcolumn:name="NSXTProject",type=string,JSONPath=`.spec.NSXTProject`,description="NSXTProject the Namespace associated with"
// +kubebuilder:printcolumn:name="PublicIPv4Blocks",type=string,JSONPath=`.spec.ExternalIPv4Blocks`,description="ExternalIPv4Blocks assigned to the Namespace"
// +kubebuilder:printcolumn:name="PrivateIPv4CIDRs",type=string,JSONPath=`.spec.PrivateIPv4CIDRs`,description="PrivateIPv4CIDRs assigned to the Namespace"
// +kubebuilder:printcolumn:name="NSXTProject",type=string,JSONPath=`.spec.nsxtProject`,description="NSXTProject the Namespace associated with"
// +kubebuilder:printcolumn:name="ExternalIPv4Blocks",type=string,JSONPath=`.spec.externalIPv4Blocks`,description="ExternalIPv4Blocks assigned to the Namespace"
// +kubebuilder:printcolumn:name="PrivateIPv4CIDRs",type=string,JSONPath=`.spec.privateIPv4CIDRs`,description="PrivateIPv4CIDRs assigned to the Namespace"
type VPCNetworkConfiguration struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
Loading

0 comments on commit f2a0d0c

Please sign in to comment.