Skip to content

Commit

Permalink
Implement ipaddressallocation controller
Browse files Browse the repository at this point in the history
Signed-off-by: Xie Zheng <xizheng@vmware.com>
  • Loading branch information
zhengxiexie committed Jul 4, 2024
1 parent 4bc8285 commit d37e336
Show file tree
Hide file tree
Showing 21 changed files with 1,581 additions and 238 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ jobs:
- name: Run build
run: make build

- name: Run ipaddressallocation test
run: KUBEBUILDER_ASSETS="" go test -gcflags=all=-l -v github.com/vmware-tanzu/nsx-operator/pkg/controllers/ipaddressallocation


- name: Run test
run: make test

32 changes: 13 additions & 19 deletions build/yaml/crd/nsx.vmware.com_ipaddressallocations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
controller-gen.kubebuilder.io/version: v0.11.0
creationTimestamp: null
name: ipaddressallocations.nsx.vmware.com
spec:
group: nsx.vmware.com
Expand All @@ -29,19 +30,14 @@ spec:
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
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
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
Expand All @@ -54,12 +50,10 @@ spec:
ip_address_block_visibility:
default: Private
description: IPAddressBlockVisibility specifies the visibility of
the IPBlocks to allocate IP addresses. Can be External, Private
or Project.
the IPBlocks to allocate IP addresses. Can be External or Private.
enum:
- External
- Private
- Project
type: string
type: object
status:
Expand All @@ -73,10 +67,10 @@ spec:
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.
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:
Expand Down
22 changes: 22 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha1"
"github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha2"
"github.com/vmware-tanzu/nsx-operator/pkg/controllers/ipaddressallocation"

"github.com/vmware-tanzu/nsx-operator/pkg/config"
ippool2 "github.com/vmware-tanzu/nsx-operator/pkg/controllers/ippool"
Expand All @@ -39,6 +40,7 @@ import (
"github.com/vmware-tanzu/nsx-operator/pkg/metrics"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"
ipaddressallocationservice "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/ipaddressallocation"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/ippool"
nodeservice "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/node"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/nsxserviceaccount"
Expand Down Expand Up @@ -147,6 +149,21 @@ func StartNamespaceController(mgr ctrl.Manager, cf *config.NSXOperatorConfig, vp
}
}

func StartIPAddressAllocationController(mgr ctrl.Manager, ipAddressAllocationService *ipaddressallocationservice.IPAddressAllocationService, vpcService common.VPCServiceProvider) {
ipAddressAllocationReconciler := &ipaddressallocation.IPAddressAllocationReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Service: ipAddressAllocationService,
VPCService: vpcService,
Recorder: mgr.GetEventRecorderFor("ipaddressallocation-controller"),
}

if err := ipAddressAllocationReconciler.SetupWithManager(mgr); err != nil {
log.Error(err, "failed to create namespace controller", "controller", "Namespace")
os.Exit(1)
}
}

func main() {
log.Info("starting NSX Operator")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -202,6 +219,10 @@ func main() {
if err != nil {
log.Error(err, "failed to initialize ippool commonService", "controller", "IPPool")
}
ipAddressAllocationService, err := ipaddressallocationservice.InitializeIPAddressAllocation(commonService, vpcService)
if err != nil {
log.Error(err, "failed to initialize ipaddressallocation commonService", "controller", "IPAddressAllocation")
}
subnetPortService, err := subnetportservice.InitializeSubnetPort(commonService)
if err != nil {
log.Error(err, "failed to initialize subnetport commonService", "controller", "SubnetPort")
Expand Down Expand Up @@ -238,6 +259,7 @@ func main() {
subnetport.StartSubnetPortController(mgr, subnetPortService, subnetService, vpcService)
pod.StartPodController(mgr, subnetPortService, subnetService, vpcService, nodeService)
StartIPPoolController(mgr, ipPoolService, vpcService)
StartIPAddressAllocationController(mgr, ipAddressAllocationService, vpcService)
networkpolicycontroller.StartNetworkPolicyController(mgr, commonService, vpcService)
service.StartServiceLbController(mgr, commonService)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/nsx.vmware.com/v1alpha1/ipaddressallocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type IPAddressAllocationList struct {

// 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
// IPAddressBlockVisibility specifies the visibility of the IPBlocks to allocate IP addresses. Can be External or Private.
// +kubebuilder:validation:Enum=External;Private
// +kubebuilder:default=Private
// +optional
IPAddressBlockVisibility IPAddressVisibility `json:"ip_address_block_visibility,omitempty"`
Expand Down
185 changes: 96 additions & 89 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.

9 changes: 4 additions & 5 deletions pkg/apis/v1alpha1/ipaddressallocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
type IPAddressVisibility string

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

// +genclient
Expand Down Expand Up @@ -42,8 +41,8 @@ type IPAddressAllocationList struct {

// 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
// IPAddressBlockVisibility specifies the visibility of the IPBlocks to allocate IP addresses. Can be External or Private.
// +kubebuilder:validation:Enum=External;Private
// +kubebuilder:default=Private
// +optional
IPAddressBlockVisibility IPAddressVisibility `json:"ip_address_block_visibility,omitempty"`
Expand Down
Loading

0 comments on commit d37e336

Please sign in to comment.