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] Support NSXLB for VPC #618

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

gran-vmv
Copy link
Contributor

@gran-vmv gran-vmv commented Jun 27, 2024

When NSXLB is enabled, create NSX LBS with VPC and skip AviLB code, and store NSX LBS path to VPCNetworkConfuguration status.

@@ -139,7 +139,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request)
LoadBalancerIPAddresses: cidr,
PrivateIPv4CIDRs: nc.PrivateIPv4CIDRs,
}
updateSuccess(r, &ctx, obj, r.Client, state, nc.Name, path)
updateSuccess(r, &ctx, obj, r.Client, state, nc.Name, path, r.Service.GetNSXLBSPath(nc.Org, nc.NsxtProject, *createdVpc.Id, obj.Namespace))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible GetNSXLBSPath() return error, or notFound?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible but I think no need to do this, since LBS and VPC is created in a batch request.
GetNSXLBSPath returns empty string means no LBS created for this VPC.

return &infraObj, nil
}

func (service *Service) WrapVPC(vpc *model.Vpc) ([]*data.StructValue, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put WrapVPC and WrapLBS in pkg/nsx/services/vpc/wrap.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although these 2 functions are used by VPC only, they can be used by other packages in future.
In future, I think we might refactor these functions to one function which can wrap multiple types to Children resource.

@gran-vmv gran-vmv force-pushed the lbvpc-1 branch 3 times, most recently from 5040cc2 to 4c564f5 Compare July 3, 2024 05:59
@gran-vmv gran-vmv requested review from heypnus and TaoZou1 July 4, 2024 03:00
@gran-vmv gran-vmv force-pushed the lbvpc-1 branch 8 times, most recently from 660f1a2 to 9d8f41b Compare July 8, 2024 03:55
@@ -602,6 +640,7 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, *
if realizestate.IsRealizeStateError(err) {
log.Error(err, "the created VPC is in error realization state, cleaning the resource", "VPC", *createdVpc.Id)
// delete the nsx vpc object and re-created in next loop
// TODO(gran) DeleteVPC will check VpcStore but new Vpc is not in store at this moment. Is it correct?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantingl @lxiaopei @seanpang-vmware Could you check if we have bug here?

@gran-vmv
Copy link
Contributor Author

gran-vmv commented Jul 8, 2024

Verified with latest NSXT. However, the realization time is too long to DefaultRetry.

status:
{
    "consolidated_status": {
        "consolidated_status": "SUCCESS"
    },
    "consolidated_status_per_enforcement_point": [
        {
            "resource_type": "ConsolidatedStatusPerEnforcementPoint",
            "enforcement_point_id": "default",
            "consolidated_status": {
                "consolidated_status": "SUCCESS"
            }
        }
    ],
    "publish_status": "REALIZED",
    "intent_version": "0",
    "intent_path": "/orgs/default/projects/project-quality/vpcs/418f860d-a2fc-4dcb-bc77-c59eedf045b4/vpc-lbs/418f860d-a2fc-4dcb-bc77-c59eedf045b4"
}

realized-entities:
{
    "results": [
        {
            "extended_attributes": [
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "key": "service_error_message"
                },
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "values": [
                        "42eb6532-3a87-11ef-9f38-000c29c18e29"
                    ],
                    "key": "standby_transport_nodes"
                },
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "values": [
                        "1720421390701"
                    ],
                    "key": "last_update_timestamp"
                },
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "values": [
                        "UP"
                    ],
                    "key": "service_status"
                },
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "key": "memory_usage"
                },
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "values": [
                        "94c2a942-3a87-11ef-9343-000c29b21f97"
                    ],
                    "key": "active_transport_nodes"
                },
                {
                    "data_type": "STRING",
                    "multivalue": false,
                    "key": "cpu_usage"
                }
            ],
            "entity_type": "LbServiceDto",
            "intent_paths": [
                "/orgs/default/projects/project-quality/vpcs/418f860d-a2fc-4dcb-bc77-c59eedf045b4/vpc-lbs/418f860d-a2fc-4dcb-bc77-c59eedf045b4"
            ],
            "resource_type": "GenericPolicyRealizedResource",
            "id": "418f860d-a2fc-4dcb-bc77-c59eedf045b4",
            "display_name": "418f860d-a2fc-4dcb-bc77-c59eedf045b4",
            "path": "/orgs/default/projects/project-quality/vpcs/418f860d-a2fc-4dcb-bc77-c59eedf045b4/realized-state/enforcement-points/default/lb-services/418f860d-a2fc-4dcb-bc77-c59eedf045b4",
            "relative_path": "418f860d-a2fc-4dcb-bc77-c59eedf045b4",
            "parent_path": "/orgs/default/projects/project-quality/vpcs/418f860d-a2fc-4dcb-bc77-c59eedf045b4/realized-state/enforcement-points/default",
            "unique_id": "bf04c0b7-3837-4c86-8ccb-98e5a69dd3cd",
            "realization_id": "bf04c0b7-3837-4c86-8ccb-98e5a69dd3cd",
            "owner_id": "204df74a-5006-462b-8f34-7ee58a4eeb22",
            "intent_reference": [
                "/orgs/default/projects/project-quality/vpcs/418f860d-a2fc-4dcb-bc77-c59eedf045b4/vpc-lbs/418f860d-a2fc-4dcb-bc77-c59eedf045b4"
            ],
            "realization_specific_identifier": "ee84d8d3-ecab-44c3-9dac-6db636de465c",
            "realization_api": "/api/v1/loadbalancer/services/ee84d8d3-ecab-44c3-9dac-6db636de465c",
            "state": "REALIZED",
            "alarms": [
            ],
            "runtime_status": "UP",
            "publish_status": "UNINITIALIZED",
            "_system_owned": false,
            "_protection": "NOT_PROTECTED",
            "_create_time": 1720421181082,
            "_create_user": "system",
            "_last_modified_time": 1720421400132,
            "_last_modified_user": "system",
            "_revision": 2
        }
    ],
    "result_count": 1
}

@gran-vmv gran-vmv force-pushed the lbvpc-1 branch 2 times, most recently from 4712571 to 59bcda2 Compare July 8, 2024 07:39
@@ -561,6 +561,8 @@ func CasttoPointer(obj interface{}) interface{} {
return &v
case model.Vpc:
return &v
case model.LBService:
return &v
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any comment to inform developers to change here for each new resource type? @dantingl @lxiaopei

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If type is missing, operator will crash when populate non-empty cache.

@gran-vmv gran-vmv force-pushed the lbvpc-1 branch 5 times, most recently from 1f37f48 to 4a1d178 Compare July 9, 2024 08:15
@gran-vmv gran-vmv force-pushed the lbvpc-1 branch 2 times, most recently from b878b9d to 104a4e8 Compare July 10, 2024 03:15
// LBS id should equal VPC id
lbs.Id = common.String(string(nsObj.GetUID()))
lbs.DisplayName = &lbsName
// TODO(gran) do we need "created_for" and "lb_t1_link_ip" tag?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantingl Here is the missing tags. I think lb_t1_link_ip is not available for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lb_t1_link_ip is not needed. created_for should be added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to expose lb_t1_link_ip for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this part.

@zhengxiexie
Copy link
Contributor

/e2e

// if lb vpc enabled, read avi subnet path and cidr
// nsx bug, if set LoadBalancerVpcEndpoint.Enabled to false, when read this vpc back,
// LoadBalancerVpcEndpoint.Enabled will become a nil pointer.
if createdVpc.LoadBalancerVpcEndpoint.Enabled != nil && *createdVpc.LoadBalancerVpcEndpoint.Enabled {
if r.Service.NSXConfig.NsxConfig.UseAVILB && createdVpc.LoadBalancerVpcEndpoint.Enabled != nil && *createdVpc.LoadBalancerVpcEndpoint.Enabled {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for AviLB, and L587 is for NSXLB. Although we support only 2 LB types currently, this is different.

However, createdVpc.LoadBalancerVpcEndpoint.Enabled is only for AviLB, thus we do not need to check UseAVILB in this line. Is it correct?

if realizestate.IsRealizeStateError(err) {
log.Error(err, "the created LBS is in error realization state, cleaning the resource", "LBS", *createdLBS.Id)
// delete the nsx vpc object and re-created in next loop
if err := s.DeleteVPC(*newVpc.Path); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if only lb not realized, must delete the whole vpc, it a must? Can we optimize it by not deleting it, rather only try lbs realization again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lbs realization timeout is longer than vpc, thus it is enough.
lbs is always created with vpc, thus we should use deleteVPC to remove them.

go VPCService.InitializeResourceStore(&wg, fatalErrors, common.ResourceTypeVpc, nil, VPCService.VpcStore)
wg.Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you update line 158 and 161, not here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We might need to add a switch here, thus I use a separate wg.Add(1)

@zhengxiexie
Copy link
Contributor

BTW, could you check why e2e test not pass?

@zhengxiexie
Copy link
Contributor

Pls also attach what tests you have done in comment. Refer #626

@gran-vmv
Copy link
Contributor Author

Result:

apiVersion: nsx.vmware.com/v1alpha1
kind: VPCNetworkConfiguration
metadata:
  creationTimestamp: "2024-07-09T06:55:58Z"
  generation: 1
  name: gran-ns1-vpc
  resourceVersion: "3738252"
  uid: a7cb1fea-1a8a-402e-bb76-edaee29f0173
spec:
  defaultGatewayPath: /infra/tier-0s/ContainerT0
  defaultIPv4SubnetSize: 64
  defaultSubnetAccessMode: Public
  edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/21cdfe18-3136-4027-94d4-f66bb975a50e
  externalIPv4Blocks:
  - /infra/ip-blocks/ipblock-192.168.0.0-netmask-16
  nsxtProject: /orgs/default/projects/project-quality
  privateIPv4CIDRs:
  - 172.26.0.0/16
status:
  vpcs:
  - name: vpc-c3a65fe0-42ce-4b8c-ac1a-191efaf44793--gran-ns1
    nsxlbspath: /orgs/default/projects/project-quality/vpcs/41b4e3cd-cd1f-423d-83b9-c8385c150d39/vpc-lbs/41b4e3cd-cd1f-423d-83b9-c8385c150d39

Signed-off-by: gran <gran@vmware.com>
@gran-vmv
Copy link
Contributor Author

/e2e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants