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

merge upstream 0.0.34 #12

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5c4cf8a
Adding tests for Agent options and validation.
cheftako Sep 20, 2022
e8966b0
Merge pull request #408 from cheftako/test
k8s-ci-robot Oct 25, 2022
c11c5bd
update owners
andrewsykim Nov 14, 2022
7766058
Merge pull request #416 from andrewsykim/owners
k8s-ci-robot Nov 16, 2022
a2dc6cf
go mod tidy
tallclair Nov 17, 2022
456c714
Run konnectivity-client tests in the client module
tallclair Nov 17, 2022
6faac34
Merge pull request #418 from tallclair/client-mod
k8s-ci-robot Nov 18, 2022
73e89b0
Log the agent username on successful authentication
tallclair Nov 19, 2022
c3e6ddc
Adjust server log verbosity
tallclair Nov 19, 2022
0de2942
Improve dial response logging
tallclair Nov 17, 2022
e928a49
Merge pull request #419 from tallclair/dial-rsp-log
k8s-ci-robot Nov 23, 2022
e6cff9f
Agent: log dialID in DIAL_REQ handling.
jkh52 Nov 23, 2022
c7da662
Merge pull request #420 from tallclair/log-spam
k8s-ci-robot Dec 2, 2022
1d2756f
Add rudimentary data transfer benchmark tests
tallclair Nov 30, 2022
11be5f6
Merge pull request #421 from jkh52/agent-log-dial-id
k8s-ci-robot Dec 2, 2022
02f689c
Merge pull request #425 from tallclair/benchmarks
k8s-ci-robot Dec 2, 2022
47b3dd4
Update go.mod to be more conservative.
jkh52 Dec 7, 2022
4a8d316
Fixed admin port listen code.
cheftako Dec 7, 2022
ae77bef
Merge pull request #433 from cheftako/AdminBindAddress
k8s-ci-robot Dec 7, 2022
7ccbedc
Merge pull request #432 from jkh52/go-mod-1.24
k8s-ci-robot Dec 8, 2022
869e056
Add several new metrics, including new KAS client package.
jkh52 Nov 14, 2022
8bf47d8
Merge pull request #423 from jkh52/more-metrics
k8s-ci-robot Dec 8, 2022
f3708b7
Fix segfault on empty packet
ncopa Nov 24, 2022
8f7006c
Merge pull request #422 from ncopa/fix-segfault
k8s-ci-robot Dec 12, 2022
bfa285e
konnectivity-client: make release-0.0 branch compatible with older k/…
jkh52 Dec 13, 2022
00e91fa
Merge pull request #437 from jkh52/release-0.0-goleak
k8s-ci-robot Dec 14, 2022
2b43421
update .gitignore
zqzten Dec 9, 2022
6e6b620
add more pprof functions to server and agent’s admin server
zqzten Dec 9, 2022
005c781
konnectivity-client: add dial failures metric by reason.
jkh52 Dec 13, 2022
4784bce
Fix broken `make lint`.
jkh52 Dec 20, 2022
cce2a51
konnectivity-client: add a tunnels gauge metric.
jkh52 Dec 20, 2022
7a9e3e5
Merge pull request #444 from jkh52/prepare-0.0.34
k8s-ci-robot Dec 22, 2022
62164fa
Merge tag 'v0.0.34' into upstream-0.0.34
ncopa Dec 27, 2022
eecd9a1
Rename ApiServerMapping to APIServerMapping
ncopa Dec 27, 2022
d4eb3e0
Fix linter warning: G102: Binds to all network interfaces (gosec)
ncopa Dec 27, 2022
b49f476
Fix linter warnings in server test
ncopa Dec 27, 2022
11ce63c
Fix linter warning about needless "= nil" assignment
ncopa Dec 27, 2022
64fd9e2
Fix potential context leak and linter warning
ncopa Dec 27, 2022
bed5b95
Merge branch 'master' into upstream-0.0.34
ncopa Apr 4, 2023
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
/easy-rsa-master/
/easy-rsa.tar.gz
/easy-rsa

# editor and IDE paraphernalia
.idea
.vscode

# macOS paraphernalia
.DS_Store
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ endif
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
INSTALL_LOCATION:=$(shell go env GOPATH)/bin
GOLANGCI_LINT_VERSION ?= 1.45.2
GOLANGCI_LINT_VERSION ?= 1.50.1
GOSEC_VERSION ?= 2.13.1

REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
Expand Down Expand Up @@ -56,7 +56,8 @@ mock_gen:

.PHONY: test
test:
GO111MODULE=on go test -race sigs.k8s.io/apiserver-network-proxy/...
go test -race ./...
cd konnectivity-client && go test -race ./...

## --------------------------------------
## Binaries
Expand Down Expand Up @@ -90,7 +91,7 @@ bin/proxy-server-static: proto/agent/agent.pb.go konnectivity-client/proto/clien
.PHONY: lint
lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(INSTALL_LOCATION) v$(GOLANGCI_LINT_VERSION)
$(INSTALL_LOCATION)/golangci-lint run --no-config --disable-all --enable=gofmt,golint,gosec,govet,unused --fix --verbose --timeout 3m
$(INSTALL_LOCATION)/golangci-lint run --no-config --disable-all --enable=gofmt,revive,gosec,govet,unused --fix --verbose --timeout 3m

## --------------------------------------
## Go
Expand Down
10 changes: 5 additions & 5 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# See the OWNERS docs at https://go.k8s.io/owners

reviewers:
- caesarxuchao
- dberkov
- jefftree
- jkh52
- tallclair
approvers:
- cheftako
- mcrute
- anfernee
- cheftako
- jkh52
emeritus_approvers:
- andrewsykim
- caesarxuchao
emeritus_approvers:
- mcrute
- Sh4d1
57 changes: 40 additions & 17 deletions cmd/agent/app/options/options.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2022 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 options

import (
Expand Down Expand Up @@ -30,10 +46,14 @@ type GrpcProxyAgentOptions struct {
ProxyServerPort int
AlpnProtos []string

// Ports for the health and admin server
// Bind address for the health connections.
HealthServerHost string
// Port we listen for health connections on.
HealthServerPort int
AdminServerPort int
// Bind address for the admin connections.
AdminBindAddress string
// Port we listen for admin connections on.
AdminServerPort int
// Enables pprof at host:adminPort/debug/pprof.
EnableProfiling bool
// If EnableProfiling is true, this enables the lock contention
Expand All @@ -59,9 +79,9 @@ type GrpcProxyAgentOptions struct {
// The check is an "unlocked" read but is still use at your own peril.
WarnOnChannelLimit bool

SyncForever bool
BindAddress string
ApiServerMapping portMapping
SyncForever bool
BindAddress string
APIServerMapping portMapping
}

var _ pflag.Value = &portMapping{}
Expand Down Expand Up @@ -108,6 +128,7 @@ func (o *GrpcProxyAgentOptions) Flags() *pflag.FlagSet {
flags.StringVar(&o.HealthServerHost, "health-server-host", o.HealthServerHost, "The host address to listen on, without port.")
flags.IntVar(&o.HealthServerPort, "health-server-port", o.HealthServerPort, "The port the health server is listening on.")
flags.IntVar(&o.AdminServerPort, "admin-server-port", o.AdminServerPort, "The port the admin server is listening on.")
flags.StringVar(&o.AdminBindAddress, "admin-bind-address", o.AdminBindAddress, "Bind address for admin connections. If empty, we will bind to all interfaces.")
flags.BoolVar(&o.EnableProfiling, "enable-profiling", o.EnableProfiling, "enable pprof at host:admin-port/debug/pprof")
flags.BoolVar(&o.EnableContentionProfiling, "enable-contention-profiling", o.EnableContentionProfiling, "enable contention profiling at host:admin-port/debug/pprof/block. \"--enable-profiling\" must also be set.")
flags.StringVar(&o.AgentID, "agent-id", o.AgentID, "The unique ID of this agent. Can also be set by the 'PROXY_AGENT_ID' environment variable. Default to a generated uuid if not set.")
Expand All @@ -118,7 +139,7 @@ func (o *GrpcProxyAgentOptions) Flags() *pflag.FlagSet {
flags.StringVar(&o.ServiceAccountTokenPath, "service-account-token-path", o.ServiceAccountTokenPath, "If non-empty proxy agent uses this token to prove its identity to the proxy server.")
flags.StringVar(&o.AgentIdentifiers, "agent-identifiers", o.AgentIdentifiers, "Identifiers of the agent that will be used by the server when choosing agent. N.B. the list of identifiers must be in URL encoded format. e.g.,host=localhost&host=node1.mydomain.com&cidr=127.0.0.1/16&ipv4=1.2.3.4&ipv4=5.6.7.8&ipv6=:::::&default-route=true")
flags.BoolVar(&o.WarnOnChannelLimit, "warn-on-channel-limit", o.WarnOnChannelLimit, "Turns on a warning if the system is going to push to a full channel. The check involves an unsafe read.")
flags.Var(&o.ApiServerMapping, "apiserver-port-mapping", "Mapping between a local port and the host:port used to reach the Kubernetes API Server")
flags.Var(&o.APIServerMapping, "apiserver-port-mapping", "Mapping between a local port and the host:port used to reach the Kubernetes API Server")
flags.StringVar(&o.BindAddress, "bind-address", o.BindAddress, "Address used to listen for traffic generated on cluster network")
// add feature gates flag
features.DefaultMutableFeatureGate.AddFlag(flags)
Expand All @@ -135,6 +156,7 @@ func (o *GrpcProxyAgentOptions) Print() {
klog.V(1).Infof("ALPNProtos set to %+s.\n", o.AlpnProtos)
klog.V(1).Infof("HealthServerHost set to %s\n", o.HealthServerHost)
klog.V(1).Infof("HealthServerPort set to %d.\n", o.HealthServerPort)
klog.V(1).Infof("Admin bind address set to %q.\n", o.AdminBindAddress)
klog.V(1).Infof("AdminServerPort set to %d.\n", o.AdminServerPort)
klog.V(1).Infof("EnableProfiling set to %v.\n", o.EnableProfiling)
klog.V(1).Infof("EnableContentionProfiling set to %v.\n", o.EnableContentionProfiling)
Expand All @@ -148,7 +170,7 @@ func (o *GrpcProxyAgentOptions) Print() {
klog.V(1).Infof("WarnOnChannelLimit set to %t.\n", o.WarnOnChannelLimit)
if features.DefaultMutableFeatureGate.Enabled(features.NodeToMasterTraffic) {
klog.V(1).Infof("AgentBindAddress set to %s.\n", o.BindAddress)
klog.V(1).Infof("Apiserver port mapping set to %s.\n", o.ApiServerMapping.String())
klog.V(1).Infof("Apiserver port mapping set to %s.\n", o.APIServerMapping.String())
}
klog.V(1).Infof("SyncForever set to %v.\n", o.SyncForever)
}
Expand Down Expand Up @@ -201,20 +223,20 @@ func (o *GrpcProxyAgentOptions) Validate() error {
if err := validateHostnameOrIP(o.BindAddress); err != nil {
return fmt.Errorf("agent bind address is invalid: %v", err)
}
if err := validateHostnameOrIP(o.ApiServerMapping.RemoteHost); err != nil {
if err := validateHostnameOrIP(o.APIServerMapping.RemoteHost); err != nil {
return fmt.Errorf("apiserver address is invalid: %v", err)
}
if o.ApiServerMapping.LocalPort > 49151 {
return fmt.Errorf("please do not try to use ephemeral port %d for the apiserver local port", o.ApiServerMapping.LocalPort)
if o.APIServerMapping.LocalPort > 49151 {
return fmt.Errorf("please do not try to use ephemeral port %d for the apiserver local port", o.APIServerMapping.LocalPort)
}
if o.ApiServerMapping.LocalPort < 1024 {
return fmt.Errorf("please do not try to use reserved port %d for the apiserver local port", o.ApiServerMapping.LocalPort)
if o.APIServerMapping.LocalPort < 1024 {
return fmt.Errorf("please do not try to use reserved port %d for the apiserver local port", o.APIServerMapping.LocalPort)
}
if o.ApiServerMapping.RemotePort > 49151 {
return fmt.Errorf("please do not try to use ephemeral port %d for the apiserver remote port", o.ApiServerMapping.LocalPort)
if o.APIServerMapping.RemotePort > 49151 {
return fmt.Errorf("please do not try to use ephemeral port %d for the apiserver remote port", o.APIServerMapping.LocalPort)
}
if o.ApiServerMapping.RemotePort < 1 {
return fmt.Errorf("invalid port %d for the apiserver remote port", o.ApiServerMapping.RemotePort)
if o.APIServerMapping.RemotePort < 1 {
return fmt.Errorf("invalid port %d for the apiserver remote port", o.APIServerMapping.RemotePort)
}
return nil
}
Expand Down Expand Up @@ -259,6 +281,7 @@ func NewGrpcProxyAgentOptions() *GrpcProxyAgentOptions {
ProxyServerPort: 8091,
HealthServerHost: "",
HealthServerPort: 8093,
AdminBindAddress: "127.0.0.1",
AdminServerPort: 8094,
EnableProfiling: false,
EnableContentionProfiling: false,
Expand All @@ -271,7 +294,7 @@ func NewGrpcProxyAgentOptions() *GrpcProxyAgentOptions {
ServiceAccountTokenPath: "",
WarnOnChannelLimit: false,
SyncForever: false,
ApiServerMapping: portMapping{LocalPort: 6443, RemoteHost: "localhost", RemotePort: 6443},
APIServerMapping: portMapping{LocalPort: 6443, RemoteHost: "localhost", RemotePort: 6443},
BindAddress: "127.0.0.1",
}
return &o
Expand Down
172 changes: 172 additions & 0 deletions cmd/agent/app/options/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
Copyright 2022 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 options

import (
"fmt"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
"time"
)

/*
* TestDefaultServerOptions is intended to ensure we do not make a backward incompatible
* change to the default flag values for the ANP agent.
*/
func TestDefaultServerOptions(t *testing.T) {
defaultAgentOptions := NewGrpcProxyAgentOptions()
assertDefaultValue(t, "AgentCert", defaultAgentOptions.AgentCert, "")
assertDefaultValue(t, "AgentKey", defaultAgentOptions.AgentKey, "")
assertDefaultValue(t, "CaCert", defaultAgentOptions.CaCert, "")
assertDefaultValue(t, "ProxyServerHost", defaultAgentOptions.ProxyServerHost, "127.0.0.1")
assertDefaultValue(t, "ProxyServerPort", defaultAgentOptions.ProxyServerPort, 8091)
assertDefaultValue(t, "HealthServerHost", defaultAgentOptions.HealthServerHost, "")
assertDefaultValue(t, "HealthServerPort", defaultAgentOptions.HealthServerPort, 8093)
assertDefaultValue(t, "AdminBindAddress", defaultAgentOptions.AdminBindAddress, "127.0.0.1")
assertDefaultValue(t, "AdminServerPort", defaultAgentOptions.AdminServerPort, 8094)
assertDefaultValue(t, "EnableProfiling", defaultAgentOptions.EnableProfiling, false)
assertDefaultValue(t, "EnableContentionProfiling", defaultAgentOptions.EnableContentionProfiling, false)
assertDefaultValue(t, "AgentIdentifiers", defaultAgentOptions.AgentIdentifiers, "")
assertDefaultValue(t, "SyncInterval", defaultAgentOptions.SyncInterval, 1*time.Second)
assertDefaultValue(t, "ProbeInterval", defaultAgentOptions.ProbeInterval, 1*time.Second)
assertDefaultValue(t, "SyncIntervalCap", defaultAgentOptions.SyncIntervalCap, 10*time.Second)
assertDefaultValue(t, "KeepaliveTime", defaultAgentOptions.KeepaliveTime, 1*time.Hour)
assertDefaultValue(t, "ServiceAccountTokenPath", defaultAgentOptions.ServiceAccountTokenPath, "")
assertDefaultValue(t, "WarnOnChannelLimit", defaultAgentOptions.WarnOnChannelLimit, false)
assertDefaultValue(t, "SyncForever", defaultAgentOptions.SyncForever, false)
}

func assertDefaultValue(t *testing.T, fieldName string, actual, expected interface{}) {
t.Helper()
assert.IsType(t, expected, actual, "For field %s, got the wrong type.", fieldName)
assert.Equal(t, expected, actual, "For field %s, got the wrong value.", fieldName)
}

func TestValidate(t *testing.T) {
for desc, tc := range map[string]struct {
fieldMap map[string]interface{}
expected error
}{
"default": {
fieldMap: map[string]interface{}{},
expected: nil,
},
"ZeroProxyServerPort": {
fieldMap: map[string]interface{}{"ProxyServerPort": 0},
expected: fmt.Errorf("proxy server port 0 must be greater than 0"),
},
"NegativeProxyServerPort": {
fieldMap: map[string]interface{}{"ProxyServerPort": -1},
expected: fmt.Errorf("proxy server port -1 must be greater than 0"),
},
"ReservedProxyServerPort": {
fieldMap: map[string]interface{}{"ProxyServerPort": 1023},
expected: nil, //TODO: fmt.Errorf("please do not try to use reserved port 1023 for the proxy server port"),
},
"StartValidProxyServerPort": {
fieldMap: map[string]interface{}{"ProxyServerPort": 1024},
expected: nil,
},
"EndValidProxyServerPort": {
fieldMap: map[string]interface{}{"ProxyServerPort": 49151},
expected: nil,
},
"StartEphemeralProxyServerPort": {
fieldMap: map[string]interface{}{"ProxyServerPort": 49152},
expected: nil, //TODO: fmt.Errorf("please do not try to use ephemeral port 49152 for the proxy server port"),
},
"ZeroHealthServerPort": {
fieldMap: map[string]interface{}{"HealthServerPort": 0},
expected: fmt.Errorf("health server port 0 must be greater than 0"),
},
"NegativeHealthServerPort": {
fieldMap: map[string]interface{}{"HealthServerPort": -1},
expected: fmt.Errorf("health server port -1 must be greater than 0"),
},
"ReservedHealthServerPort": {
fieldMap: map[string]interface{}{"HealthServerPort": 1023},
expected: nil, //TODO: fmt.Errorf("please do not try to use reserved port 1023 for the health server port"),
},
"StartValidHealthServerPort": {
fieldMap: map[string]interface{}{"HealthServerPort": 1024},
expected: nil,
},
"EndValidHealthServerPort": {
fieldMap: map[string]interface{}{"HealthServerPort": 49151},
expected: nil,
},
"StartEphemeralHealthServerPort": {
fieldMap: map[string]interface{}{"HealthServerPort": 49152},
expected: nil, //TODO: fmt.Errorf("please do not try to use ephemeral port 49152 for the health server port"),
},
"ZeroAdminServerPort": {
fieldMap: map[string]interface{}{"AdminServerPort": 0},
expected: fmt.Errorf("admin server port 0 must be greater than 0"),
},
"NegativeAdminServerPort": {
fieldMap: map[string]interface{}{"AdminServerPort": -1},
expected: fmt.Errorf("admin server port -1 must be greater than 0"),
},
"ReservedAdminServerPort": {
fieldMap: map[string]interface{}{"AdminServerPort": 1023},
expected: nil, //TODO: fmt.Errorf("please do not try to use reserved port 1023 for the health port"),
},
"StartValidAdminServerPort": {
fieldMap: map[string]interface{}{"AdminServerPort": 1024},
expected: nil,
},
"EndValidAdminServerPort": {
fieldMap: map[string]interface{}{"AdminServerPort": 49151},
expected: nil,
},
"StartEphemeralAdminServerPort": {
fieldMap: map[string]interface{}{"AdminServerPort": 49152},
expected: nil, //TODO: fmt.Errorf("please do not try to use ephemeral port 49152 for the health port"),
},
"ContentionProfilingRequiresProfiling": {
fieldMap: map[string]interface{}{
"EnableContentionProfiling": true,
"EnableProfiling": false,
},
expected: fmt.Errorf("if --enable-contention-profiling is set, --enable-profiling must also be set"),
},
} {
t.Run(desc, func(t *testing.T) {
testAgentOptions := NewGrpcProxyAgentOptions()
for field, value := range tc.fieldMap {
rv := reflect.ValueOf(testAgentOptions)
rv = rv.Elem()
fv := rv.FieldByName(field)
switch reflect.TypeOf(value).Kind() {
case reflect.String:
svalue := value.(string)
fv.SetString(svalue)
case reflect.Int:
ivalue := value.(int)
fv.SetInt(int64(ivalue))
case reflect.Bool:
bvalue := value.(bool)
fv.SetBool(bvalue)
}
}
actual := testAgentOptions.Validate()
assert.IsType(t, tc.expected, actual, "Validation for case %s, got the wrong type.", desc)
assert.Equal(t, tc.expected, actual, "Validation for case %s, got the wrong value.", desc)
})
}
}
Loading