-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Add test/typecheck, a fast typecheck for all build platforms. #59289
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e04b91f
Remove unused variables (only assigned to) from test code.
0067002
Make a few code paths compile cleanly with 32-bit Go.
8aa3ca3
Add a few "+build linux" tags where appropriate.
01a9f83
Move linux-only getProxyMode tests to a linux-only file.
c3acf07
Vendor golang's go/types to include a fix for CGo typechecking.
4d2e43f
Fix build tag for grpc_service_unix_test.go.
dd40e61
Add test/typecheck, a fast typecheck for all build platforms.
800c2f8
Ensure generated files are present before typechecking.
1b37113
Ensure status bar displays full progress.
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
// +build !windows | ||
|
||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
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 app | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
"k8s.io/kubernetes/pkg/proxy/ipvs" | ||
"k8s.io/kubernetes/pkg/util/iptables" | ||
) | ||
|
||
func Test_getProxyMode(t *testing.T) { | ||
var cases = []struct { | ||
flag string | ||
annotationKey string | ||
annotationVal string | ||
iptablesVersion string | ||
ipsetVersion string | ||
kmods []string | ||
kernelCompat bool | ||
iptablesError error | ||
ipsetError error | ||
expected string | ||
}{ | ||
{ // flag says userspace | ||
flag: "userspace", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, error detecting version | ||
flag: "iptables", | ||
iptablesError: fmt.Errorf("oops!"), | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, version too low | ||
flag: "iptables", | ||
iptablesVersion: "0.0.0", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, version ok, kernel not compatible | ||
flag: "iptables", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: false, | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, version ok, kernel is compatible | ||
flag: "iptables", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // detect, error | ||
flag: "", | ||
iptablesError: fmt.Errorf("oops!"), | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // detect, version too low | ||
flag: "", | ||
iptablesVersion: "0.0.0", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // detect, version ok, kernel not compatible | ||
flag: "", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: false, | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // detect, version ok, kernel is compatible | ||
flag: "", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // specify ipvs, feature gateway disabled, iptables version ok, kernel is compatible | ||
flag: "ipvs", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // specify ipvs, feature gateway disabled, iptables version too low | ||
flag: "ipvs", | ||
iptablesVersion: "0.0.0", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // specify ipvs, feature gateway disabled, iptables version ok, kernel is not compatible | ||
flag: "ipvs", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: false, | ||
expected: proxyModeUserspace, | ||
}, | ||
} | ||
for i, c := range cases { | ||
versioner := &fakeIPTablesVersioner{c.iptablesVersion, c.iptablesError} | ||
kcompater := &fakeKernelCompatTester{c.kernelCompat} | ||
ipsetver := &fakeIPSetVersioner{c.ipsetVersion, c.ipsetError} | ||
khandler := &fakeKernelHandler{c.kmods} | ||
r := getProxyMode(c.flag, versioner, khandler, ipsetver, kcompater) | ||
if r != c.expected { | ||
t.Errorf("Case[%d] Expected %q, got %q", i, c.expected, r) | ||
} | ||
} | ||
} | ||
|
||
// This is a coarse test, but it offers some modicum of confidence as the code is evolved. | ||
func Test_getProxyModeEnableFeatureGateway(t *testing.T) { | ||
// enable IPVS feature gateway | ||
utilfeature.DefaultFeatureGate.Set("SupportIPVSProxyMode=true") | ||
|
||
var cases = []struct { | ||
flag string | ||
iptablesVersion string | ||
ipsetVersion string | ||
kernelCompat bool | ||
iptablesError error | ||
ipsetError error | ||
mods []string | ||
expected string | ||
}{ | ||
{ // flag says userspace | ||
flag: "userspace", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, error detecting version | ||
flag: "iptables", | ||
iptablesError: fmt.Errorf("oops!"), | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, version too low | ||
flag: "iptables", | ||
iptablesVersion: "0.0.0", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, version ok, kernel not compatible | ||
flag: "iptables", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: false, | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says iptables, version ok, kernel is compatible | ||
flag: "iptables", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // detect, error | ||
flag: "", | ||
iptablesError: fmt.Errorf("oops!"), | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // detect, version too low | ||
flag: "", | ||
iptablesVersion: "0.0.0", | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // detect, version ok, kernel not compatible | ||
flag: "", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: false, | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // detect, version ok, kernel is compatible | ||
flag: "", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // detect, version ok, kernel is compatible | ||
flag: "", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // flag says ipvs, ipset version ok, kernel modules installed | ||
flag: "ipvs", | ||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack_ipv4"}, | ||
ipsetVersion: ipvs.MinIPSetCheckVersion, | ||
expected: proxyModeIPVS, | ||
}, | ||
{ // flag says ipvs, ipset version too low, fallback on iptables mode | ||
flag: "ipvs", | ||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack_ipv4"}, | ||
ipsetVersion: "0.0", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // flag says ipvs, bad ipset version, fallback on iptables mode | ||
flag: "ipvs", | ||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack_ipv4"}, | ||
ipsetVersion: "a.b.c", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // flag says ipvs, required kernel modules are not installed, fallback on iptables mode | ||
flag: "ipvs", | ||
mods: []string{"foo", "bar", "baz"}, | ||
ipsetVersion: ipvs.MinIPSetCheckVersion, | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: true, | ||
expected: proxyModeIPTables, | ||
}, | ||
{ // flag says ipvs, required kernel modules are not installed, iptables version too old, fallback on userspace mode | ||
flag: "ipvs", | ||
mods: []string{"foo", "bar", "baz"}, | ||
ipsetVersion: ipvs.MinIPSetCheckVersion, | ||
iptablesVersion: "0.0.0", | ||
kernelCompat: true, | ||
expected: proxyModeUserspace, | ||
}, | ||
{ // flag says ipvs, ipset version too low, iptables version too old, kernel not compatible, fallback on userspace mode | ||
flag: "ipvs", | ||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack_ipv4"}, | ||
ipsetVersion: "0.0", | ||
iptablesVersion: iptables.MinCheckVersion, | ||
kernelCompat: false, | ||
expected: proxyModeUserspace, | ||
}, | ||
} | ||
for i, c := range cases { | ||
versioner := &fakeIPTablesVersioner{c.iptablesVersion, c.iptablesError} | ||
kcompater := &fakeKernelCompatTester{c.kernelCompat} | ||
ipsetver := &fakeIPSetVersioner{c.ipsetVersion, c.ipsetError} | ||
khandle := &fakeKernelHandler{c.mods} | ||
r := getProxyMode(c.flag, versioner, khandle, ipsetver, kcompater) | ||
if r != c.expected { | ||
t.Errorf("Case[%d] Expected %q, got %q", i, c.expected, r) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did gazelle generate this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is what happens when you have build tags and use hack/update-bazel.sh.