Skip to content

Commit

Permalink
gh-681: unified cloud-api frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed May 28, 2024
1 parent aaf4b0d commit 883cea7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 23 deletions.
30 changes: 8 additions & 22 deletions pkg/loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1532,16 +1532,9 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) {
if R.vipMap[sNetAddr.IP.String()] == 0 {
if utils.IsIPHostAddr(sNetAddr.IP.String()) {
loxinlp.DelAddrNoHook(sNetAddr.IP.String()+"/32", "lo")
if mh.cloudLabel == "aws" {
err := AWSUpdatePrivateIP(sNetAddr.IP, false)
if err != nil {
tk.LogIt(tk.LogError, "aws lb-rule vip %s delete failed. err: %v\n", sNetAddr.IP.String(), err)
}
} else if mh.cloudLabel == "ncloud" {
err := nClient.NcloudUpdatePrivateIp(sNetAddr.IP, false)
if err != nil {
tk.LogIt(tk.LogError, "ncloud lb-rule vip %s delete failed. err: %v\n", sNetAddr.IP.String(), err)
}
err := CloudUpdatePrivateIP(sNetAddr.IP, false)
if err != nil {
tk.LogIt(tk.LogError, "%s: lb-rule vip %s delete failed. err: %v\n", mh.cloudLabel, sNetAddr.IP.String(), err)
}
}
dev := fmt.Sprintf("llb-rule-%s", sNetAddr.IP.String())
Expand Down Expand Up @@ -2642,19 +2635,12 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP) error {
ev, _, iface := R.zone.L3.IfaSelectAny(IP, false)
if ev == 0 {
if !utils.IsIPHostAddr(IP.String()) {
if mh.cloudLabel == "aws" {
err := AWSUpdatePrivateIP(IP, true)
if err != nil {
tk.LogIt(tk.LogError, "aws lb-rule vip %s add failed. err: %v\n", IP.String(), err)
return err
}
} else if mh.cloudLabel == "ncloud" {
err := nClient.NcloudUpdatePrivateIp(IP, true)
if err != nil {
tk.LogIt(tk.LogError, "ncloud lb-rule vip %s add failed. err: %v\n", IP.String(), err)
return err
}
err := CloudUpdatePrivateIP(IP, true)
if err != nil {
tk.LogIt(tk.LogError, "%s: lb-rule vip %s add failed. err: %v\n", mh.cloudLabel, IP.String(), err)
return err
}

if loxinlp.AddAddrNoHook(IP.String()+"/32", "lo") != 0 {
tk.LogIt(tk.LogError, "nat lb-rule vip %s:%s add failed\n", IP.String(), "lo")
} else {
Expand Down
13 changes: 12 additions & 1 deletion pkg/loxinet/utils_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ func AWSPrepVIPNetwork() error {
return nil
}

loxiEniPrivIP := *intfOutput.NetworkInterface.PrivateIpAddress
loxiEniID = *intfOutput.NetworkInterface.NetworkInterfaceId

tk.LogIt(tk.LogInfo, "Created interface (%s) for loxilb instance %v\n", *intfOutput.NetworkInterface.NetworkInterfaceId, vpcID)
tk.LogIt(tk.LogInfo, "Created interface (%s:%s) for loxilb instance %v\n", *intfOutput.NetworkInterface.NetworkInterfaceId, loxiEniPrivIP, vpcID)

devIdx := int32(1)
aniOut, err := ec2Client.AttachNetworkInterface(ctx3, &ec2.AttachNetworkInterfaceInput{DeviceIndex: &devIdx,
Expand Down Expand Up @@ -255,6 +256,16 @@ retry:
if err != nil {
tk.LogIt(tk.LogError, "failed to set link (%s) mtu:%s\n", nintf.Name, err)
}

Address, err := nl.ParseAddr(loxiEniPrivIP + "/32")
if err != nil {
tk.LogIt(tk.LogWarning, "privIP %s parse fail\n", loxiEniPrivIP)
return err
}
err = nl.AddrAdd(link, Address)
if err != nil {
tk.LogIt(tk.LogWarning, "privIP %s:%s add failed\n", loxiEniPrivIP, nintf.Name)
}
newIntfName = nintf.Name
}
}
Expand Down
37 changes: 37 additions & 0 deletions pkg/loxinet/utils_cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 NetLOX Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package loxinet

import (
tk "github.com/loxilb-io/loxilib"
"net"
)

func CloudUpdatePrivateIP(vIP net.IP, add bool) error {
if mh.cloudLabel == "aws" {
err := AWSUpdatePrivateIP(vIP, false)
if err != nil {
tk.LogIt(tk.LogError, "aws lb-rule vip %s delete failed. err: %v\n", vIP.String(), err)
}
} else if mh.cloudLabel == "ncloud" {
err := nClient.NcloudUpdatePrivateIp(vIP, false)
if err != nil {
tk.LogIt(tk.LogError, "ncloud lb-rule vip %s delete failed. err: %v\n", vIP.String(), err)
}
}
return nil
}

0 comments on commit 883cea7

Please sign in to comment.