add flag 'logging-format' to kube-proxy
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
logsapi "k8s.io/component-base/logs/api/v1"
|
||||
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
|
||||
|
||||
"k8s.io/utils/pointer"
|
||||
@@ -58,6 +59,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "192.168.59.103",
|
||||
HealthzBindAddress: "0.0.0.0:10256",
|
||||
@@ -75,6 +79,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "192.168.59.103",
|
||||
HealthzBindAddress: "",
|
||||
@@ -92,6 +99,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "fd00:192:168:59::103",
|
||||
HealthzBindAddress: "",
|
||||
@@ -109,6 +119,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "10.10.12.11",
|
||||
HealthzBindAddress: "0.0.0.0:12345",
|
||||
@@ -126,6 +139,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "10.10.12.11",
|
||||
HealthzBindAddress: "0.0.0.0:12345",
|
||||
@@ -143,6 +159,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "10.10.12.11",
|
||||
HealthzBindAddress: "0.0.0.0:12345",
|
||||
@@ -160,6 +179,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "10.10.12.11",
|
||||
HealthzBindAddress: "0.0.0.0:12345",
|
||||
@@ -181,6 +203,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
DetectLocal: kubeproxyconfig.DetectLocalConfiguration{
|
||||
InterfaceNamePrefix: "vethabcde",
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}, {
|
||||
BindAddress: "10.10.12.11",
|
||||
HealthzBindAddress: "0.0.0.0:12345",
|
||||
@@ -202,6 +227,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
DetectLocal: kubeproxyconfig.DetectLocalConfiguration{
|
||||
BridgeInterface: "avz",
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}}
|
||||
|
||||
for _, successCase := range successCases {
|
||||
@@ -233,6 +261,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("BindAddress"), "10.10.12.11:2000", "not a valid textual representation of an IP address")},
|
||||
},
|
||||
@@ -254,6 +285,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("HealthzBindAddress"), "0.0.0.0", "must be IP:port")},
|
||||
},
|
||||
@@ -275,6 +309,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("MetricsBindAddress"), "127.0.0.1", "must be IP:port")},
|
||||
},
|
||||
@@ -296,6 +333,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("ClusterCIDR"), "192.168.59.0", "must be a valid CIDR block (e.g. 10.100.0.0/16 or fde4:8dba:82e1::/48)")},
|
||||
},
|
||||
@@ -317,6 +357,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("ClusterCIDR"), "192.168.59.0/24,fd00:192:168::/64,10.0.0.0/16", "only one CIDR allowed or a valid DualStack CIDR (e.g. 10.100.0.0/16,fde4:8dba:82e1::/48)")},
|
||||
},
|
||||
@@ -338,6 +381,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("ConfigSyncPeriod"), metav1.Duration{Duration: -1 * time.Second}, "must be greater than 0")},
|
||||
},
|
||||
@@ -361,6 +407,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("KubeProxyIPVSConfiguration.SyncPeriod"), metav1.Duration{Duration: 0}, "must be greater than 0")},
|
||||
},
|
||||
@@ -386,6 +435,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
DetectLocal: kubeproxyconfig.DetectLocalConfiguration{
|
||||
InterfaceNamePrefix: "",
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("InterfacePrefix"), "", "must not be empty")},
|
||||
},
|
||||
@@ -411,6 +463,9 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
DetectLocal: kubeproxyconfig.DetectLocalConfiguration{
|
||||
InterfaceNamePrefix: "eth0", // we won't care about prefix since mode is not prefix
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("InterfaceName"), "", "must not be empty")},
|
||||
},
|
||||
@@ -433,9 +488,36 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
DetectLocalMode: "Guess",
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.NotSupported(newPath.Child("DetectLocalMode"), "Guess", []string{"ClusterCIDR", "NodeCIDR", "BridgeInterface", "InterfaceNamePrefix", ""})},
|
||||
},
|
||||
"invalid logging format": {
|
||||
config: kubeproxyconfig.KubeProxyConfiguration{
|
||||
BindAddress: "10.10.12.11",
|
||||
HealthzBindAddress: "0.0.0.0:12345",
|
||||
MetricsBindAddress: "127.0.0.1:10249",
|
||||
ClusterCIDR: "192.168.59.0/24",
|
||||
ConfigSyncPeriod: metav1.Duration{Duration: 1 * time.Second},
|
||||
IPTables: kubeproxyconfig.KubeProxyIPTablesConfiguration{
|
||||
MasqueradeAll: true,
|
||||
SyncPeriod: metav1.Duration{Duration: 5 * time.Second},
|
||||
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||
},
|
||||
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
|
||||
MaxPerCore: pointer.Int32(1),
|
||||
Min: pointer.Int32(1),
|
||||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
|
||||
},
|
||||
Logging: logsapi.LoggingConfiguration{
|
||||
Format: "unsupported format",
|
||||
},
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("logging.format"), "unsupported format", "Unsupported log format")},
|
||||
},
|
||||
}
|
||||
|
||||
for name, testCase := range testCases {
|
||||
|
Reference in New Issue
Block a user