File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import (
35
35
"github.com/containernetworking/cni/pkg/version"
36
36
"github.com/containernetworking/plugins/pkg/ip"
37
37
"github.com/containernetworking/plugins/pkg/ns"
38
+ "github.com/joho/godotenv"
38
39
"github.com/vishvananda/netlink"
39
40
)
40
41
@@ -313,6 +314,8 @@ func tickSuicide(done chan bool) {
313
314
}
314
315
}
315
316
317
+ const envFilePath = "/etc/kubernetes/ucloud"
318
+
316
319
func main () {
317
320
// Print version
318
321
if len (os .Args ) == 2 && os .Args [1 ] == "version" {
@@ -322,6 +325,20 @@ func main() {
322
325
323
326
ulog .BinaryMode ("/var/log/cnivpc.log" )
324
327
328
+ _ , err := os .Stat (envFilePath )
329
+ if err != nil {
330
+ if os .IsNotExist (err ) {
331
+ ulog .Warnf ("Env file %s not found" , envFilePath )
332
+ } else {
333
+ ulog .Errorf ("Check env file %s error: %v" , envFilePath , err )
334
+ }
335
+ } else {
336
+ err = godotenv .Load (envFilePath )
337
+ if err != nil {
338
+ ulog .Errorf ("Load env file %s error: %v" , envFilePath , err )
339
+ }
340
+ }
341
+
325
342
about := fmt .Sprintf ("ucloud-uk8s-cnivpc version %s" , vs .CNIVersion )
326
343
327
344
done := make (chan bool , 1 )
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ require (
8
8
github.com/containernetworking/plugins v0.9.1
9
9
github.com/coreos/go-iptables v0.6.0
10
10
github.com/j-keck/arping v1.0.2
11
+ github.com/joho/godotenv v1.5.1
11
12
github.com/mattn/go-shellwords v1.0.12
12
13
github.com/sirupsen/logrus v1.6.0
13
14
github.com/spf13/cobra v1.7.0
Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
88
88
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56 /go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA =
89
89
github.com/j-keck/arping v1.0.2 h1:hlLhuXgQkzIJTZuhMigvG/CuSkaspeaD9hRDk2zuiMI =
90
90
github.com/j-keck/arping v1.0.2 /go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw =
91
+ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0 =
92
+ github.com/joho/godotenv v1.5.1 /go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4 =
91
93
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY =
92
94
github.com/josharian/intern v1.0.0 /go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y =
93
95
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM =
You can’t perform that action at this time.
0 commit comments