forked from vmware-tanzu/nsx-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VPC] Support NSXLB for VPC (vmware-tanzu#618)
Signed-off-by: gran <[email protected]>
- Loading branch information
Showing
16 changed files
with
565 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/openlyinc/pointy" | ||
"github.com/vmware/vsphere-automation-sdk-go/runtime/data" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" | ||
) | ||
|
||
// WrapInfra TODO(gran) refactor existing code in other package | ||
func (service *Service) WrapInfra(children []*data.StructValue) (*model.Infra, error) { | ||
// This is the outermost layer of the hierarchy infra client. | ||
// It doesn't need ID field. | ||
resourceType := ResourceTypeInfra | ||
infraObj := model.Infra{ | ||
Children: children, | ||
ResourceType: &resourceType, | ||
} | ||
return &infraObj, nil | ||
} | ||
|
||
func (service *Service) WrapOrgRoot(children []*data.StructValue) (*model.OrgRoot, error) { | ||
resourceType := ResourceTypeOrgRoot | ||
orgRootObj := model.OrgRoot{ | ||
Children: children, | ||
ResourceType: &resourceType, | ||
} | ||
return &orgRootObj, nil | ||
} | ||
|
||
func (service *Service) WrapOrg(org string, children []*data.StructValue) ([]*data.StructValue, error) { | ||
targetType := ResourceTypeOrg | ||
return wrapChildResourceReference(targetType, org, children) | ||
} | ||
|
||
func (service *Service) WrapProject(nsxtProject string, children []*data.StructValue) ([]*data.StructValue, error) { | ||
targetType := ResourceTypeProject | ||
return wrapChildResourceReference(targetType, nsxtProject, children) | ||
} | ||
|
||
func wrapChildResourceReference(targetType, id string, children []*data.StructValue) ([]*data.StructValue, error) { | ||
resourceType := ResourceTypeChildResourceReference | ||
childProject := model.ChildResourceReference{ | ||
Id: &id, | ||
ResourceType: resourceType, | ||
TargetType: &targetType, | ||
Children: children, | ||
} | ||
dataValue, errors := NewConverter().ConvertToVapi(childProject, childProject.GetType__()) | ||
if len(errors) > 0 { | ||
return nil, errors[0] | ||
} | ||
return []*data.StructValue{dataValue.(*data.StructValue)}, nil | ||
|
||
} | ||
|
||
func (service *Service) WrapVPC(vpc *model.Vpc) ([]*data.StructValue, error) { | ||
vpc.ResourceType = pointy.String(ResourceTypeVpc) | ||
childVpc := model.ChildVpc{ | ||
Id: vpc.Id, | ||
MarkedForDelete: vpc.MarkedForDelete, | ||
ResourceType: "ChildVpc", | ||
Vpc: vpc, | ||
} | ||
dataValue, errs := NewConverter().ConvertToVapi(childVpc, childVpc.GetType__()) | ||
if len(errs) > 0 { | ||
return nil, errs[0] | ||
} | ||
return []*data.StructValue{dataValue.(*data.StructValue)}, nil | ||
} | ||
|
||
func (service *Service) WrapLBS(lbs *model.LBService) ([]*data.StructValue, error) { | ||
lbs.ResourceType = pointy.String(ResourceTypeLBService) | ||
childLBService := model.ChildLBService{ | ||
Id: lbs.Id, | ||
MarkedForDelete: lbs.MarkedForDelete, | ||
ResourceType: "ChildLBService", | ||
LbService: lbs, | ||
} | ||
dataValue, errs := NewConverter().ConvertToVapi(childLBService, childLBService.GetType__()) | ||
if len(errs) > 0 { | ||
return nil, errs[0] | ||
} | ||
return []*data.StructValue{dataValue.(*data.StructValue)}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package vpc | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha1" | ||
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common" | ||
) | ||
|
||
func Test_buildNSXLBS(t *testing.T) { | ||
type args struct { | ||
obj *v1alpha1.NetworkInfo | ||
nsObj *v1.Namespace | ||
cluster string | ||
lbsSize string | ||
vpcPath string | ||
relaxScaleValidation *bool | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *model.LBService | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "1", | ||
args: args{ | ||
obj: &v1alpha1.NetworkInfo{ | ||
ObjectMeta: metav1.ObjectMeta{Namespace: "ns1"}, | ||
VPCs: nil, | ||
}, | ||
nsObj: &v1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "ns1", UID: "nsuid1"}, | ||
}, | ||
cluster: "cluster1", | ||
lbsSize: model.LBService_SIZE_SMALL, | ||
vpcPath: "/vpc1", | ||
relaxScaleValidation: nil, | ||
}, | ||
want: &model.LBService{ | ||
Id: common.String("nsuid1"), | ||
DisplayName: common.String("vpc-cluster1--ns1"), | ||
Tags: []model.Tag{ | ||
{ | ||
Scope: common.String(common.TagScopeCluster), | ||
Tag: common.String("cluster1"), | ||
}, | ||
{ | ||
Scope: common.String(common.TagScopeVersion), | ||
Tag: common.String(strings.Join(common.TagValueVersion, ".")), | ||
}, | ||
{Scope: common.String(common.TagScopeNamespace), Tag: common.String("ns1")}, | ||
{Scope: common.String(common.TagScopeNamespaceUID), Tag: common.String("nsuid1")}, | ||
{Scope: common.String(common.TagScopeCreatedFor), Tag: common.String(common.TagValueSLB)}, | ||
}, | ||
Size: common.String(model.LBService_SIZE_SMALL), | ||
ConnectivityPath: common.String("/vpc1"), | ||
RelaxScaleValidation: nil, | ||
}, | ||
wantErr: assert.NoError, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := buildNSXLBS(tt.args.obj, tt.args.nsObj, tt.args.cluster, tt.args.lbsSize, tt.args.vpcPath, tt.args.relaxScaleValidation) | ||
if !tt.wantErr(t, err, fmt.Sprintf("buildNSXLBS(%v, %v, %v, %v, %v, %v)", tt.args.obj, tt.args.nsObj, tt.args.cluster, tt.args.lbsSize, tt.args.vpcPath, tt.args.relaxScaleValidation)) { | ||
return | ||
} | ||
assert.Equalf(t, tt.want, got, "buildNSXLBS(%v, %v, %v, %v, %v, %v)", tt.args.obj, tt.args.nsObj, tt.args.cluster, tt.args.lbsSize, tt.args.vpcPath, tt.args.relaxScaleValidation) | ||
}) | ||
} | ||
} |
Oops, something went wrong.