Skip to content

Commit

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

Fix ippool crd for v1alpha1 and v1alpha2
  • Loading branch information
zhengxiexie authored Aug 17, 2023
2 parents 53d287d + 56491e8 commit 597057f
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ help: ## Display this help.

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/apis/v1alpha1/" output:crd:artifacts:config=build/yaml/crd/
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/apis/v1alpha2/" output:crd:artifacts:config=build/yaml/crd/
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/apis/v1alpha1/;./pkg/apis/v1alpha2/" output:crd:artifacts:config=build/yaml/crd/

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
105 changes: 104 additions & 1 deletion build/yaml/crd/nsx.vmware.com_ippools.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand All @@ -16,6 +15,110 @@ spec:
singular: ippool
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: IPPool is the Schema for the ippools API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: IPPoolSpec defines the desired state of IPPool.
properties:
subnets:
description: Subnets defines set of subnets need to be allocated.
items:
description: SubnetRequest defines the subnet allocation request.
properties:
ipFamily:
default: IPv4
description: IPFamily defines the IP family type for this subnet,
could be IPv4 or IPv6. This is optional, the default is IPv4.
enum:
- IPv4
- IPv6
type: string
name:
description: Name defines the name of this subnet.
type: string
prefixLength:
description: PrefixLength defines prefix length for this subnet.
type: integer
required:
- name
type: object
type: array
type: object
status:
description: IPPoolStatus defines the observed state of IPPool.
properties:
conditions:
description: Conditions defines current state of the IPPool.
items:
description: Condition defines condition of custom resource.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: Message shows a human-readable message about condition.
type: string
reason:
description: Reason shows a brief reason of condition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type defines condition type.
type: string
required:
- status
- type
type: object
type: array
subnets:
description: Subnets defines subnets allocation result.
items:
description: SubnetResult defines the subnet allocation result.
properties:
cidr:
description: CIDR defines the allocated CIDR.
type: string
name:
description: Name defines the name of this subnet.
type: string
required:
- cidr
- name
type: object
type: array
required:
- conditions
- subnets
type: object
required:
- metadata
- spec
type: object
served: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
- description: Type of IPPool
jsonPath: .spec.type
Expand Down
72 changes: 72 additions & 0 deletions pkg/apis/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{})
}
136 changes: 136 additions & 0 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.

1 change: 1 addition & 0 deletions pkg/apis/v1alpha2/ippool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

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

// IPPool is the Schema for the ippools API.
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`,description="Type of IPPool"
Expand Down

0 comments on commit 597057f

Please sign in to comment.