mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
kube-proxy: add --write-config flag
Add --write-config flag to kube-proxy to write the default configuration values to the specified file location.
This commit is contained in:
@@ -18,15 +18,19 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/iptables"
|
||||
)
|
||||
|
||||
@@ -132,14 +136,17 @@ func Test_getProxyMode(t *testing.T) {
|
||||
|
||||
// This test verifies that Proxy Server does not crash when CleanupAndExit is true.
|
||||
func TestProxyServerWithCleanupAndExit(t *testing.T) {
|
||||
options := Options{
|
||||
config: &componentconfig.KubeProxyConfiguration{
|
||||
BindAddress: "0.0.0.0",
|
||||
},
|
||||
CleanupAndExit: true,
|
||||
options, err := NewOptions()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
proxyserver, err := NewProxyServer(options.config, options.CleanupAndExit, options.master)
|
||||
options.config = &componentconfig.KubeProxyConfiguration{
|
||||
BindAddress: "0.0.0.0",
|
||||
}
|
||||
options.CleanupAndExit = true
|
||||
|
||||
proxyserver, err := NewProxyServer(options.config, options.CleanupAndExit, options.scheme, options.master)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, proxyserver)
|
||||
@@ -203,3 +210,82 @@ func TestGetConntrackMax(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
yaml := `apiVersion: componentconfig/v1alpha1
|
||||
bindAddress: 9.8.7.6
|
||||
clientConnection:
|
||||
acceptContentTypes: "abc"
|
||||
burst: 100
|
||||
contentType: content-type
|
||||
kubeconfig: "/path/to/kubeconfig"
|
||||
qps: 7
|
||||
clusterCIDR: "1.2.3.0/24"
|
||||
configSyncPeriod: 15s
|
||||
conntrack:
|
||||
max: 4
|
||||
maxPerCore: 2
|
||||
min: 1
|
||||
tcpCloseWaitTimeout: 10s
|
||||
tcpEstablishedTimeout: 20s
|
||||
featureGates: "all"
|
||||
healthzBindAddress: 1.2.3.4:12345
|
||||
hostnameOverride: "foo"
|
||||
iptables:
|
||||
masqueradeAll: true
|
||||
masqueradeBit: 17
|
||||
minSyncPeriod: 10s
|
||||
syncPeriod: 60s
|
||||
kind: KubeProxyConfiguration
|
||||
metricsBindAddress: 2.3.4.5:23456
|
||||
mode: "iptables"
|
||||
oomScoreAdj: 17
|
||||
portRange: "2-7"
|
||||
resourceContainer: /foo
|
||||
udpTimeoutMilliseconds: 123ms
|
||||
`
|
||||
|
||||
expected := &componentconfig.KubeProxyConfiguration{
|
||||
BindAddress: "9.8.7.6",
|
||||
ClientConnection: componentconfig.ClientConnectionConfiguration{
|
||||
AcceptContentTypes: "abc",
|
||||
Burst: 100,
|
||||
ContentType: "content-type",
|
||||
KubeConfigFile: "/path/to/kubeconfig",
|
||||
QPS: 7,
|
||||
},
|
||||
ClusterCIDR: "1.2.3.0/24",
|
||||
ConfigSyncPeriod: metav1.Duration{Duration: 15 * time.Second},
|
||||
Conntrack: componentconfig.KubeProxyConntrackConfiguration{
|
||||
Max: 4,
|
||||
MaxPerCore: 2,
|
||||
Min: 1,
|
||||
TCPCloseWaitTimeout: metav1.Duration{Duration: 10 * time.Second},
|
||||
TCPEstablishedTimeout: metav1.Duration{Duration: 20 * time.Second},
|
||||
},
|
||||
FeatureGates: "all",
|
||||
HealthzBindAddress: "1.2.3.4:12345",
|
||||
HostnameOverride: "foo",
|
||||
IPTables: componentconfig.KubeProxyIPTablesConfiguration{
|
||||
MasqueradeAll: true,
|
||||
MasqueradeBit: util.Int32Ptr(17),
|
||||
MinSyncPeriod: metav1.Duration{Duration: 10 * time.Second},
|
||||
SyncPeriod: metav1.Duration{Duration: 60 * time.Second},
|
||||
},
|
||||
MetricsBindAddress: "2.3.4.5:23456",
|
||||
Mode: "iptables",
|
||||
OOMScoreAdj: util.Int32Ptr(17),
|
||||
PortRange: "2-7",
|
||||
ResourceContainer: "/foo",
|
||||
UDPIdleTimeout: metav1.Duration{Duration: 123 * time.Millisecond},
|
||||
}
|
||||
|
||||
options, err := NewOptions()
|
||||
assert.NoError(t, err)
|
||||
|
||||
config, err := options.loadConfig([]byte(yaml))
|
||||
assert.NoError(t, err)
|
||||
if !reflect.DeepEqual(expected, config) {
|
||||
t.Fatalf("unexpected config, diff = %s", diff.ObjectDiff(config, expected))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user