Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#288 from zhengxiexie/codegen_alpha2_v…
Browse files Browse the repository at this point in the history
…pc_dev

Support codegen for v1alpha2
  • Loading branch information
zhengxiexie authored Oct 30, 2023
2 parents 1ef2441 + 1d51c28 commit 553261d
Show file tree
Hide file tree
Showing 90 changed files with 1,820 additions and 168 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/[email protected]

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
73 changes: 73 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,73 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1

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

// +genclient
//+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{})
}
28 changes: 20 additions & 8 deletions pkg/apis/nsx.vmware.com/v1alpha1/nsxserviceaccount_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,35 @@ const (
NSXServiceAccountPhaseRealized NSXServiceAccountPhase = "realized"
NSXServiceAccountPhaseInProgress NSXServiceAccountPhase = "inProgress"
NSXServiceAccountPhaseFailed NSXServiceAccountPhase = "failed"

ConditionTypeRealized string = "Realized"
ConditionReasonRealizationSuccess string = "RealizationSuccess"
ConditionReasonRealizationError string = "RealizationError"
)

// NSXServiceAccountStatus defines the observed state of NSXServiceAccount
type NSXServiceAccountStatus struct {
Phase NSXServiceAccountPhase `json:"phase,omitempty"`
Reason string `json:"reason,omitempty"`
VPCPath string `json:"vpcPath,omitempty"`
NSXManagers []string `json:"nsxManagers,omitempty"`
ProxyEndpoints NSXProxyEndpoint `json:"proxyEndpoints,omitempty"`
ClusterID string `json:"clusterID,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
Secrets []NSXSecret `json:"secrets,omitempty"`
// Deprecated: Use Conditions instead.
// +kubebuilder:deprecatedversion:warning="nsx.vmware.com/v1alpha1 Phase is deprecated"
Phase NSXServiceAccountPhase `json:"phase,omitempty"`
// Deprecated: Use Conditions instead.
// +kubebuilder:deprecatedversion:warning="nsx.vmware.com/v1alpha1 Reason is deprecated"
Reason string `json:"reason,omitempty"`
// Represents the realization status of a NSXServiceAccount's current state.
// Known .status.conditions.type is: "Realized"
Conditions []metav1.Condition `json:"conditions,omitempty"`
VPCPath string `json:"vpcPath,omitempty"`
NSXManagers []string `json:"nsxManagers,omitempty"`
ProxyEndpoints NSXProxyEndpoint `json:"proxyEndpoints,omitempty"`
ClusterID string `json:"clusterID,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
Secrets []NSXSecret `json:"secrets,omitempty"`
}

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

// NSXServiceAccount is the Schema for the nsxserviceaccounts API
type NSXServiceAccount struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/nsx.vmware.com/v1alpha1/securitypolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type SecurityPolicyStatus struct {
// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion

// SecurityPolicy is the Schema for the securitypolicies API.
type SecurityPolicy struct {
Expand Down
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
18 changes: 9 additions & 9 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 @@ -12,15 +12,11 @@ type AccessMode string
// SubnetSpec defines the desired state of Subnet.
type SubnetSpec struct {
// Size of Subnet based upon estimated workload count.
// Defaults to 64.
// +kubebuilder:default:=64
// +kubebuilder:validation:Maximum:=65536
// +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
// +kubebuilder:validation:Enum=Private;Public
AccessMode AccessMode `json:"accessMode,omitempty"`
// Subnet CIDRS.
// +kubebuilder:validation:MinItems=0
Expand All @@ -34,16 +30,20 @@ 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
//+kubebuilder:storageversion

// 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
6 changes: 5 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 @@ -41,8 +41,12 @@ type SubnetPortIPAddress struct {
// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion

// 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
16 changes: 8 additions & 8 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 @@ -10,15 +10,11 @@ import (
// SubnetSetSpec defines the desired state of SubnetSet.
type SubnetSetSpec struct {
// Size of Subnet based upon estimated workload count.
// Defaults to 64.
// +kubebuilder:default:=64
// +kubebuilder:validation:Maximum:=65536
// +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
// +kubebuilder:validation:Enum=Private;Public
AccessMode AccessMode `json:"accessMode,omitempty"`
// Subnet advanced configuration.
AdvancedConfig AdvancedConfig `json:"advancedConfig,omitempty"`
Expand All @@ -34,15 +30,19 @@ 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
//+kubebuilder:storageversion

// 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
Loading

0 comments on commit 553261d

Please sign in to comment.