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

[VPC] Add NSX LBS path to VPCInfo and use LB options in NsxConfig #606

Merged
merged 1 commit into from
Jul 25, 2024
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
9 changes: 7 additions & 2 deletions build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ spec:
maxLength: 8
type: string
vpc:
description: NSX path of the VPC the Namespace associated with. If
vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode
description: |-
NSX path of the VPC the Namespace associated with.
If vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode
take effect, other fields are ignored.
type: string
type: object
Expand All @@ -125,6 +126,10 @@ spec:
name:
description: VPC name.
type: string
nsxLoadBalancerPath:
description: NSXLoadBalancerPath is the NSX Policy path for
the NSX Load Balancer.
type: string
required:
- name
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type VPCInfo struct {
Name string `json:"name"`
// AVISESubnetPath is the NSX Policy Path for the AVI SE Subnet.
AVISESubnetPath string `json:"lbSubnetPath,omitempty"`
// NSXLoadBalancerPath is the NSX Policy path for the NSX Load Balancer.
NSXLoadBalancerPath string `json:"nsxLoadBalancerPath,omitempty"`
}

// +genclient
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type VPCInfo struct {
Name string `json:"name"`
// AVISESubnetPath is the NSX Policy Path for the AVI SE Subnet.
AVISESubnetPath string `json:"lbSubnetPath,omitempty"`
gran-vmv marked this conversation as resolved.
Show resolved Hide resolved
// NSXLoadBalancerPath is the NSX Policy path for the NSX Load Balancer.
NSXLoadBalancerPath string `json:"nsxLoadBalancerPath,omitempty"`
}

// +genclient
Expand Down
20 changes: 20 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"

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

Expand Down Expand Up @@ -117,6 +118,10 @@ type NsxConfig struct {
EnvoyHost string `ini:"envoy_host"`
EnvoyPort int `ini:"envoy_port"`
LicenseValidationInterval int `ini:"license_validation_interval"`
UseAVILoadBalancer bool `ini:"use_avi_lb"`
UseNSXLoadBalancer *bool `ini:"use_native_loadbalancer"`
RelaxNSXLBScaleValication bool `ini:"relax_scale_validation"`
NSXLBSize string `ini:"service_size"`
}

type K8sConfig struct {
Expand Down Expand Up @@ -406,3 +411,18 @@ func (coeConfig *CoeConfig) validate() error {
func (nsxConfig *NsxConfig) ValidateConfigFromCmd() error {
return nsxConfig.validate(true)
}

func (nsxConfig *NsxConfig) NSXLBEnabled() bool {
if nsxConfig.UseAVILoadBalancer == false && (nsxConfig.UseNSXLoadBalancer == nil || *nsxConfig.UseNSXLoadBalancer == true) {
return true
}
return false
}

func (nsxConfig *NsxConfig) GetNSXLBSize() string {
lbsSize := nsxConfig.NSXLBSize
if lbsSize == "" {
lbsSize = model.LBService_SIZE_SMALL
}
return lbsSize
}
84 changes: 84 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"os"
"testing"

"github.com/openlyinc/pointy"
"github.com/stretchr/testify/assert"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
)

func TestConfig_VCConfig(t *testing.T) {
Expand Down Expand Up @@ -176,3 +178,85 @@ func TestNSXOperatorConfig_GetCACert(t *testing.T) {
})
}
}

func TestNsxConfig_NSXLBEnabled(t *testing.T) {
type fields struct {
UseAVILB bool
UseNativeLoadBalancer *bool
}
tests := []struct {
name string
fields fields
want bool
}{{
name: "avilb",
fields: fields{
UseAVILB: true,
UseNativeLoadBalancer: nil,
},
want: false,
}, {
name: "nsxlbnil",
fields: fields{
UseAVILB: false,
UseNativeLoadBalancer: nil,
},
want: true,
}, {
name: "nsxlbtrue",
fields: fields{
UseAVILB: false,
UseNativeLoadBalancer: pointy.Bool(true),
},
want: true,
}, {
name: "nsxlbfalse",
fields: fields{
UseAVILB: false,
UseNativeLoadBalancer: pointy.Bool(false),
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nsxConfig := &NsxConfig{
UseAVILoadBalancer: tt.fields.UseAVILB,
UseNSXLoadBalancer: tt.fields.UseNativeLoadBalancer,
}
assert.Equalf(t, tt.want, nsxConfig.NSXLBEnabled(), "NSXLBEnabled()")
})
}
}

func TestNsxConfig_GetServiceSize(t *testing.T) {
type fields struct {
ServiceSize string
}
tests := []struct {
name string
fields fields
want string
}{{
name: "default",
fields: fields{
ServiceSize: "",
},
want: model.LBService_SIZE_SMALL,
}, {
name: "large",
fields: fields{
ServiceSize: model.LBService_SIZE_LARGE,
},
want: model.LBService_SIZE_LARGE,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nsxConfig := &NsxConfig{
NSXLBSize: tt.fields.ServiceSize,
}
assert.Equalf(t, tt.want, nsxConfig.GetNSXLBSize(), "GetNSXLBSize()")
})
}
}
Loading