Skip to content

Commit

Permalink
fix: use default network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat committed Nov 8, 2024
1 parent 2f55a17 commit aaa62f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.7.0
github.com/ucloud/go-lockfile v0.1.0
github.com/ucloud/ucloud-sdk-go v0.21.46
github.com/ucloud/ucloud-sdk-go v0.22.30
github.com/vishvananda/netlink v1.2.1-beta.2
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f
google.golang.org/grpc v1.56.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ github.com/ucloud/go-lockfile v0.1.0 h1:Mzb1/OZc8Gween/p1cA4t6qBTiE9JnZntZpRTdII
github.com/ucloud/go-lockfile v0.1.0/go.mod h1:OCM7zfa82qicE2nW5pVtSDEMmPvjYvProNQ/f2YHEkw=
github.com/ucloud/ucloud-sdk-go v0.21.46 h1:LwrTxERZjQJPjVILoIfjy8PTgYkckah5ms2eq4ECgT0=
github.com/ucloud/ucloud-sdk-go v0.21.46/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw=
github.com/ucloud/ucloud-sdk-go v0.22.30 h1:CZQWo+LLLYMVgf/Mq9JoFVNyIM7jLFpwvnctsUwXV3k=
github.com/ucloud/ucloud-sdk-go v0.22.30/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw=
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs=
github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
Expand Down
15 changes: 10 additions & 5 deletions pkg/uapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ func NewClient() (*ApiClient, error) {
zoneId: meta.AvailabilityZone,
cfg: &cfg,
}
// Get vpcId and subnetId
if len(meta.UHost.NetworkInterfaces) > 0 {
uApi.vpcId = meta.UHost.NetworkInterfaces[0].VpcId
uApi.subnetId = meta.UHost.NetworkInterfaces[0].SubnetId
} else {

for _, iface := range meta.UHost.NetworkInterfaces {
if iface.Default {
uApi.vpcId = iface.VpcId
uApi.subnetId = iface.SubnetId
break
}
}

if uApi.vpcId == "" || uApi.subnetId == "" {
uApi.vpcId = os.Getenv("UCLOUD_VPC_ID")
uApi.subnetId = os.Getenv("UCLOUD_SUBNET_ID")
}
Expand Down

0 comments on commit aaa62f6

Please sign in to comment.