-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from chrisliu1995/feat/network_params
add params for network plugins
- Loading branch information
Showing
5 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package util | ||
|
||
import ( | ||
"k8s.io/klog/v2" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func GetNetworkTotalWaitTime() time.Duration { | ||
networkTotalWaitTime := 60 * time.Second | ||
if num := os.Getenv("NETWORK_TOTAL_WAIT_TIME"); len(num) > 0 { | ||
if p, err := strconv.ParseInt(num, 10, 32); err == nil { | ||
networkTotalWaitTime = time.Duration(p) * time.Second | ||
} else { | ||
klog.Fatalf("failed to convert NETWORK_TOTAL_WAIT_TIME=%v in env: %v", p, err) | ||
} | ||
} | ||
return networkTotalWaitTime | ||
} | ||
|
||
func GetNetworkIntervalTime() time.Duration { | ||
networkIntervalTime := 5 * time.Second | ||
if num := os.Getenv("NETWORK_PROBE_INTERVAL_TIME"); len(num) > 0 { | ||
if p, err := strconv.ParseInt(num, 10, 32); err == nil { | ||
networkIntervalTime = time.Duration(p) * time.Second | ||
} else { | ||
klog.Fatalf("failed to convert NETWORK_PROBE_INTERVAL_TIME=%v in env: %v", p, err) | ||
} | ||
} | ||
return networkIntervalTime | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestGetNetworkTotalWaitTime(t *testing.T) { | ||
tests := []struct { | ||
networkTotalWaitTime string | ||
result time.Duration | ||
}{ | ||
{ | ||
networkTotalWaitTime: "60", | ||
result: 60 * time.Second, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
os.Setenv("NETWORK_TOTAL_WAIT_TIME", test.networkTotalWaitTime) | ||
if GetNetworkTotalWaitTime() != test.result { | ||
t.Errorf("expect %v but got %v", test.result, GetNetworkTotalWaitTime()) | ||
} | ||
} | ||
} | ||
|
||
func TestGetNetworkIntervalTime(t *testing.T) { | ||
tests := []struct { | ||
networkIntervalTime string | ||
result time.Duration | ||
}{ | ||
{ | ||
networkIntervalTime: "5", | ||
result: 5 * time.Second, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
os.Setenv("NETWORK_PROBE_INTERVAL_TIME", test.networkIntervalTime) | ||
if GetNetworkIntervalTime() != test.result { | ||
t.Errorf("expect %v but got %v", test.result, GetNetworkIntervalTime()) | ||
} | ||
} | ||
} |