Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPPool controller added #160

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ resources:
kind: NSXServiceAccount
path: github.com/vmware-tanzu/nsx-operator/pkg/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: nsx.vmware.com
kind: IPPool
path: github.com/vmware-tanzu/nsx-operator/pkg/api/v1alpha2
version: v1alpha2
version: "3"
34 changes: 2 additions & 32 deletions build/yaml/crd/nsx.vmware.com_ippools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.11.0
creationTimestamp: null
name: ippools.nsx.vmware.com
spec:
Expand All @@ -15,34 +15,10 @@ spec:
singular: ippool
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
properties:
spec:
properties:
subnets:
items:
properties:
ipFamily:
pattern: ^ipv(4|6)$
type: string
name:
type: string
prefixLength:
minimum: 1
type: integer
type: object
type: array
type: object
type: object
x-kubernetes-preserve-unknown-fields: true
served: true
storage: false
- name: v1alpha2
schema:
openAPIV3Schema:
description: IPPool is the Schema for the ippools API
description: IPPool is the Schema for the ippools API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down Expand Up @@ -152,9 +128,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: ["v1alpha2"]
3 changes: 1 addition & 2 deletions build/yaml/crd/nsx.vmware.com_subnets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ spec:
metadata:
type: object
spec:
description: SubnetSpec defines the desired state of Subnet. TODO Add
validate webhook or CEL(k8s 1.25+) for immutable fields(IPv4SubnetSize/AccessMode/IPAddresses/DHCPConfig).
description: SubnetSpec defines the desired state of Subnet.
properties:
DHCPConfig:
description: DHCPConfig DHCP configuration.
Expand Down
3 changes: 1 addition & 2 deletions build/yaml/crd/nsx.vmware.com_subnetsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ spec:
metadata:
type: object
spec:
description: SubnetSetSpec defines the desired state of SubnetSet. TODO
Add validate webhook or CEL(k8s 1.25+) for immutable fields(IPv4SubnetSize/AccessMode/DHCPConfig).
description: SubnetSetSpec defines the desired state of SubnetSet.
properties:
DHCPConfig:
description: DHCPConfig DHCP configuration.
Expand Down
33 changes: 32 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"

"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/config"
commonctl "github.com/vmware-tanzu/nsx-operator/pkg/controllers/common"
ippool2 "github.com/vmware-tanzu/nsx-operator/pkg/controllers/ippool"
namespacecontroller "github.com/vmware-tanzu/nsx-operator/pkg/controllers/namespace"
nsxserviceaccountcontroller "github.com/vmware-tanzu/nsx-operator/pkg/controllers/nsxserviceaccount"
securitypolicycontroller "github.com/vmware-tanzu/nsx-operator/pkg/controllers/securitypolicy"
Expand All @@ -29,6 +31,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"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/ippool"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/nsxserviceaccount"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/securitypolicy"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/vpc"
Expand All @@ -45,6 +48,7 @@ func init() {
var err error
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
config.AddFlags()

logf.SetLogger(logger.ZapLogger())
Expand Down Expand Up @@ -105,6 +109,31 @@ func StartNSXServiceAccountController(mgr ctrl.Manager, commonService common.Ser
}
}

func StartIPPoolController(mgr ctrl.Manager, commonService common.Service) {
ippoolReconcile := &ippool2.IPPoolReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}
if ipPoolService, err := ippool.InitializeIPPool(commonService); err != nil {
log.Error(err, "failed to initialize ippool commonService", "controller", "IPPool")
os.Exit(1)
} else {
ippoolReconcile.Service = ipPoolService
}

// TODO: remove this after vpc is ready
if vpcService, err := vpc.InitializeVPC(commonService); err != nil {
log.Error(err, "failed to initialize vpc commonService", "controller", "vpc")
os.Exit(1)
} else {
commonctl.ServiceMediator.VPCService = vpcService
}
if err := ippoolReconcile.Start(mgr); err != nil {
dantingl marked this conversation as resolved.
Show resolved Hide resolved
log.Error(err, "failed to create controller", "controller", "IPPool")
os.Exit(1)
}
}

func StartVPCController(mgr ctrl.Manager, commonService common.Service) {
vpcReconciler := &vpccontroller.VPCReconciler{
Client: mgr.GetClient(),
Expand Down Expand Up @@ -182,8 +211,10 @@ func main() {

StartNamespaceController(mgr, commonService)
StartVPCController(mgr, commonService)
StartIPPoolController(mgr, commonService)
}
// Start the security policy controller, it supports VPC and non VPC mode

// Start the security policy controller.
StartSecurityPolicyController(mgr, commonService)

// Start the NSXServiceAccount controller.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ require (
github.com/stretchr/objx v0.4.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.4.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/v1alpha2/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/controllers/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const (
MetricResTypeSecurityPolicy = "securitypolicy"
MetricResTypeIPPool = "ippool"
MetricResTypeNSXServiceAccount = "nsxserviceaccount"
MetricResTypeSubnetPort = "subnetport"
MetricResTypeStaticRoute = "staticroute"
Expand Down
Loading
Loading