Skip to content

Commit

Permalink
Merge pull request #577 from zhengxiexie/zhengxie/ipallocation_crd
Browse files Browse the repository at this point in the history
Add IPAddressAllocation CRD
  • Loading branch information
zhengxiexie authored Jun 26, 2024
2 parents 14277d6 + 3a1fc16 commit 0fb7a85
Show file tree
Hide file tree
Showing 16 changed files with 924 additions and 0 deletions.
109 changes: 109 additions & 0 deletions build/yaml/crd/nsx.vmware.com_ipaddressallocations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: ipaddressallocations.nsx.vmware.com
spec:
group: nsx.vmware.com
names:
kind: IPAddressAllocation
listKind: IPAddressAllocationList
plural: ipaddressallocations
singular: ipaddressallocation
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: IPAddressBlockVisibility of IPAddressAllocation
jsonPath: .spec.ip_address_block_visibility
name: IPAddressBlockVisibility
type: string
- description: CIDRs for the IPAddressAllocation
jsonPath: .status.cidr
name: CIDR
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: IPAddressAllocation is the Schema for the IP allocation 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: IPAddressAllocationSpec defines the desired state of IPAddressAllocation.
properties:
allocation_size:
description: AllocationSize specifies the size of IP CIDR to be allocated.
type: integer
ip_address_block_visibility:
default: Private
description: IPAddressBlockVisibility specifies the visibility of
the IPBlocks to allocate IP addresses. Can be External, Private
or Project.
enum:
- External
- Private
- Project
type: string
type: object
status:
description: IPAddressAllocationStatus defines the observed state of IPAddressAllocation.
properties:
CIDR:
description: CIDR is the allocated CIDR
type: string
conditions:
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
required:
- CIDR
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
subresources:
status: {}
10 changes: 10 additions & 0 deletions build/yaml/samples/nsx_v1alpha1_ipaddressallocation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
name: guestcluster-workers-a
namespace: sc-a
spec:
ip_address_block_visibility: Private
allocation_size: 26
status:
CIDR: 172.26.1.0/28
63 changes: 63 additions & 0 deletions pkg/apis/nsx.vmware.com/v1alpha1/ipaddressallocation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright © 2024 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1

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

type IPAddressVisibility string

const (
IPAddressVisibilityExternal = "External"
IPAddressVisibilityPrivate = "Private"
IPAddressVisibilityProject = "Project"
)

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

// IPAddressAllocation is the Schema for the IP allocation API.
// +kubebuilder:printcolumn:name="IPAddressBlockVisibility",type=string,JSONPath=`.spec.ip_address_block_visibility`,description="IPAddressBlockVisibility of IPAddressAllocation"
// +kubebuilder:printcolumn:name="CIDR",type=string,JSONPath=`.status.cidr`,description="CIDRs for the IPAddressAllocation"
type IPAddressAllocation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`

Spec IPAddressAllocationSpec `json:"spec"`
Status IPAddressAllocationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

// IPAddressAllocationSpec defines the desired state of IPAddressAllocation.
type IPAddressAllocationSpec struct {
// IPAddressBlockVisibility specifies the visibility of the IPBlocks to allocate IP addresses. Can be External, Private or Project.
// +kubebuilder:validation:Enum=External;Private;Project
// +kubebuilder:default=Private
// +optional
IPAddressBlockVisibility IPAddressVisibility `json:"ip_address_block_visibility,omitempty"`
// AllocationSize specifies the size of IP CIDR to be allocated.
AllocationSize int `json:"allocation_size,omitempty"`
}

// IPAddressAllocationStatus defines the observed state of IPAddressAllocation.
type IPAddressAllocationStatus struct {
// CIDR is the allocated CIDR
CIDR string `json:"CIDR"`
Conditions []Condition `json:"conditions,omitempty"`
}

func init() {
SchemeBuilder.Register(&IPAddressAllocation{}, &IPAddressAllocationList{})
}
89 changes: 89 additions & 0 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.

63 changes: 63 additions & 0 deletions pkg/apis/v1alpha1/ipaddressallocation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright © 2024 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

package v1alpha1

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

type IPAddressVisibility string

const (
IPAddressVisibilityExternal = "External"
IPAddressVisibilityPrivate = "Private"
IPAddressVisibilityProject = "Project"
)

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

// IPAddressAllocation is the Schema for the IP allocation API.
// +kubebuilder:printcolumn:name="IPAddressBlockVisibility",type=string,JSONPath=`.spec.ip_address_block_visibility`,description="IPAddressBlockVisibility of IPAddressAllocation"
// +kubebuilder:printcolumn:name="CIDR",type=string,JSONPath=`.status.cidr`,description="CIDRs for the IPAddressAllocation"
type IPAddressAllocation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`

Spec IPAddressAllocationSpec `json:"spec"`
Status IPAddressAllocationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

// IPAddressAllocationSpec defines the desired state of IPAddressAllocation.
type IPAddressAllocationSpec struct {
// IPAddressBlockVisibility specifies the visibility of the IPBlocks to allocate IP addresses. Can be External, Private or Project.
// +kubebuilder:validation:Enum=External;Private;Project
// +kubebuilder:default=Private
// +optional
IPAddressBlockVisibility IPAddressVisibility `json:"ip_address_block_visibility,omitempty"`
// AllocationSize specifies the size of IP CIDR to be allocated.
AllocationSize int `json:"allocation_size,omitempty"`
}

// IPAddressAllocationStatus defines the observed state of IPAddressAllocation.
type IPAddressAllocationStatus struct {
// CIDR is the allocated CIDR
CIDR string `json:"CIDR"`
Conditions []Condition `json:"conditions,omitempty"`
}

func init() {
SchemeBuilder.Register(&IPAddressAllocation{}, &IPAddressAllocationList{})
}
Loading

0 comments on commit 0fb7a85

Please sign in to comment.