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

fix: use default network interface #42

Merged
merged 2 commits into from
Nov 13, 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
33 changes: 0 additions & 33 deletions .github/workflows/check-go.yml

This file was deleted.

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
Loading