Skip to content

Commit 2c46396

Browse files
authored
[VPC] Add NSX LBS path to VPCInfo and use LB options in NsxConfig (vmware-tanzu#606)
Signed-off-by: gran <gran@vmware.com>
1 parent 6b05d60 commit 2c46396

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ spec:
103103
maxLength: 8
104104
type: string
105105
vpc:
106-
description: NSX path of the VPC the Namespace associated with. If
107-
vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode
106+
description: |-
107+
NSX path of the VPC the Namespace associated with.
108+
If vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode
108109
take effect, other fields are ignored.
109110
type: string
110111
type: object
@@ -125,6 +126,10 @@ spec:
125126
name:
126127
description: VPC name.
127128
type: string
129+
nsxLoadBalancerPath:
130+
description: NSXLoadBalancerPath is the NSX Policy path for
131+
the NSX Load Balancer.
132+
type: string
128133
required:
129134
- name
130135
type: object

pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type VPCInfo struct {
6565
Name string `json:"name"`
6666
// AVISESubnetPath is the NSX Policy Path for the AVI SE Subnet.
6767
AVISESubnetPath string `json:"lbSubnetPath,omitempty"`
68+
// NSXLoadBalancerPath is the NSX Policy path for the NSX Load Balancer.
69+
NSXLoadBalancerPath string `json:"nsxLoadBalancerPath,omitempty"`
6870
}
6971

7072
// +genclient

pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type VPCInfo struct {
6565
Name string `json:"name"`
6666
// AVISESubnetPath is the NSX Policy Path for the AVI SE Subnet.
6767
AVISESubnetPath string `json:"lbSubnetPath,omitempty"`
68+
// NSXLoadBalancerPath is the NSX Policy path for the NSX Load Balancer.
69+
NSXLoadBalancerPath string `json:"nsxLoadBalancerPath,omitempty"`
6870
}
6971

7072
// +genclient

pkg/config/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"os"
1313

14+
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
1415
"go.uber.org/zap"
1516
ini "gopkg.in/ini.v1"
1617

@@ -117,6 +118,10 @@ type NsxConfig struct {
117118
EnvoyHost string `ini:"envoy_host"`
118119
EnvoyPort int `ini:"envoy_port"`
119120
LicenseValidationInterval int `ini:"license_validation_interval"`
121+
UseAVILoadBalancer bool `ini:"use_avi_lb"`
122+
UseNSXLoadBalancer *bool `ini:"use_native_loadbalancer"`
123+
RelaxNSXLBScaleValication bool `ini:"relax_scale_validation"`
124+
NSXLBSize string `ini:"service_size"`
120125
}
121126

122127
type K8sConfig struct {
@@ -406,3 +411,18 @@ func (coeConfig *CoeConfig) validate() error {
406411
func (nsxConfig *NsxConfig) ValidateConfigFromCmd() error {
407412
return nsxConfig.validate(true)
408413
}
414+
415+
func (nsxConfig *NsxConfig) NSXLBEnabled() bool {
416+
if nsxConfig.UseAVILoadBalancer == false && (nsxConfig.UseNSXLoadBalancer == nil || *nsxConfig.UseNSXLoadBalancer == true) {
417+
return true
418+
}
419+
return false
420+
}
421+
422+
func (nsxConfig *NsxConfig) GetNSXLBSize() string {
423+
lbsSize := nsxConfig.NSXLBSize
424+
if lbsSize == "" {
425+
lbsSize = model.LBService_SIZE_SMALL
426+
}
427+
return lbsSize
428+
}

pkg/config/config_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"os"
1010
"testing"
1111

12+
"github.com/openlyinc/pointy"
1213
"github.com/stretchr/testify/assert"
14+
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
1315
)
1416

1517
func TestConfig_VCConfig(t *testing.T) {
@@ -176,3 +178,85 @@ func TestNSXOperatorConfig_GetCACert(t *testing.T) {
176178
})
177179
}
178180
}
181+
182+
func TestNsxConfig_NSXLBEnabled(t *testing.T) {
183+
type fields struct {
184+
UseAVILB bool
185+
UseNativeLoadBalancer *bool
186+
}
187+
tests := []struct {
188+
name string
189+
fields fields
190+
want bool
191+
}{{
192+
name: "avilb",
193+
fields: fields{
194+
UseAVILB: true,
195+
UseNativeLoadBalancer: nil,
196+
},
197+
want: false,
198+
}, {
199+
name: "nsxlbnil",
200+
fields: fields{
201+
UseAVILB: false,
202+
UseNativeLoadBalancer: nil,
203+
},
204+
want: true,
205+
}, {
206+
name: "nsxlbtrue",
207+
fields: fields{
208+
UseAVILB: false,
209+
UseNativeLoadBalancer: pointy.Bool(true),
210+
},
211+
want: true,
212+
}, {
213+
name: "nsxlbfalse",
214+
fields: fields{
215+
UseAVILB: false,
216+
UseNativeLoadBalancer: pointy.Bool(false),
217+
},
218+
want: false,
219+
},
220+
}
221+
for _, tt := range tests {
222+
t.Run(tt.name, func(t *testing.T) {
223+
nsxConfig := &NsxConfig{
224+
UseAVILoadBalancer: tt.fields.UseAVILB,
225+
UseNSXLoadBalancer: tt.fields.UseNativeLoadBalancer,
226+
}
227+
assert.Equalf(t, tt.want, nsxConfig.NSXLBEnabled(), "NSXLBEnabled()")
228+
})
229+
}
230+
}
231+
232+
func TestNsxConfig_GetServiceSize(t *testing.T) {
233+
type fields struct {
234+
ServiceSize string
235+
}
236+
tests := []struct {
237+
name string
238+
fields fields
239+
want string
240+
}{{
241+
name: "default",
242+
fields: fields{
243+
ServiceSize: "",
244+
},
245+
want: model.LBService_SIZE_SMALL,
246+
}, {
247+
name: "large",
248+
fields: fields{
249+
ServiceSize: model.LBService_SIZE_LARGE,
250+
},
251+
want: model.LBService_SIZE_LARGE,
252+
},
253+
}
254+
for _, tt := range tests {
255+
t.Run(tt.name, func(t *testing.T) {
256+
nsxConfig := &NsxConfig{
257+
NSXLBSize: tt.fields.ServiceSize,
258+
}
259+
assert.Equalf(t, tt.want, nsxConfig.GetNSXLBSize(), "GetNSXLBSize()")
260+
})
261+
}
262+
}

0 commit comments

Comments
 (0)