From 152e326722c95fd039d73d4736f6f8c5956a5460 Mon Sep 17 00:00:00 2001 From: liangwei Date: Sat, 25 Aug 2018 14:57:31 +0800 Subject: [PATCH] referencing ClientConnectionConfiguration from k8s.io/apimachinery/pkg/apis/config --- api/api-rules/violation_exceptions.list | 1 - cmd/kube-proxy/app/server.go | 9 +++++---- cmd/kube-proxy/app/server_test.go | 5 +++-- .../app/apis/kubeadm/v1alpha2/defaults.go | 4 ++-- .../app/apis/kubeadm/v1alpha3/conversion.go | 4 ++-- cmd/kubeadm/app/componentconfigs/defaults.go | 4 ++-- .../testdata/conversion/master/internal.yaml | 2 +- pkg/proxy/apis/config/types.go | 19 ++----------------- pkg/proxy/apis/config/v1alpha1/types.go | 19 ++----------------- .../apis/config/validation/validation.go | 3 ++- .../apis/config/validation/validation_test.go | 7 ++++--- 11 files changed, 25 insertions(+), 52 deletions(-) diff --git a/api/api-rules/violation_exceptions.list b/api/api-rules/violation_exceptions.list index c4326bfecd6..5e5a7b7aef1 100644 --- a/api/api-rules/violation_exceptions.list +++ b/api/api-rules/violation_exceptions.list @@ -170,7 +170,6 @@ API rule violation: names_match,k8s.io/kubernetes/pkg/apis/componentconfig/v1alp API rule violation: names_match,k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1,KubeletConfiguration,ResolverConfig API rule violation: names_match,k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1,KubeletConfiguration,IPTablesMasqueradeBit API rule violation: names_match,k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1,KubeletConfiguration,IPTablesDropBit -API rule violation: names_match,k8s.io/kubernetes/pkg/proxy/apis/config/v1alpha1,ClientConnectionConfiguration,KubeConfigFile API rule violation: names_match,k8s.io/kubernetes/pkg/proxy/apis/config/v1alpha1,KubeProxyConfiguration,IPTables API rule violation: names_match,k8s.io/metrics/pkg/apis/custom_metrics/v1beta1,MetricValue,WindowSeconds API rule violation: names_match,k8s.io/metrics/pkg/apis/external_metrics/v1beta1,ExternalMetricValue,WindowSeconds diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index e7a5919f16e..2cb56bf9b25 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -30,6 +30,7 @@ import ( "time" "k8s.io/api/core/v1" + apimachineryconfig "k8s.io/apimachinery/pkg/apis/config" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" @@ -138,7 +139,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.Int32Var(o.config.OOMScoreAdj, "oom-score-adj", utilpointer.Int32PtrDerefOr(o.config.OOMScoreAdj, int32(qos.KubeProxyOOMScoreAdj)), "The oom-score-adj value for kube-proxy process. Values must be within the range [-1000, 1000]") fs.StringVar(&o.config.ResourceContainer, "resource-container", o.config.ResourceContainer, "Absolute name of the resource-only container to create and run the Kube-proxy in (Default: /kube-proxy).") fs.MarkDeprecated("resource-container", "This feature will be removed in a later release.") - fs.StringVar(&o.config.ClientConnection.KubeConfigFile, "kubeconfig", o.config.ClientConnection.KubeConfigFile, "Path to kubeconfig file with authorization information (the master location is set by the master flag).") + fs.StringVar(&o.config.ClientConnection.Kubeconfig, "kubeconfig", o.config.ClientConnection.Kubeconfig, "Path to kubeconfig file with authorization information (the master location is set by the master flag).") fs.Var(componentconfig.PortRangeVar{Val: &o.config.PortRange}, "proxy-port-range", "Range of host ports (beginPort-endPort, single port or beginPort+offset, inclusive) that may be consumed in order to proxy service traffic. If (unspecified, 0, or 0-0) then ports will be randomly chosen.") fs.StringVar(&o.config.HostnameOverride, "hostname-override", o.config.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.") fs.Var(&o.config.Mode, "proxy-mode", "Which proxy mode to use: 'userspace' (older) or 'iptables' (faster) or 'ipvs' (experimental). If blank, use the best-available proxy (currently iptables). If the iptables proxy is selected, regardless of how, but the system's kernel or iptables versions are insufficient, this always falls back to the userspace proxy.") @@ -404,18 +405,18 @@ type ProxyServer struct { // createClients creates a kube client and an event client from the given config and masterOverride. // TODO remove masterOverride when CLI flags are removed. -func createClients(config kubeproxyconfig.ClientConnectionConfiguration, masterOverride string) (clientset.Interface, v1core.EventsGetter, error) { +func createClients(config apimachineryconfig.ClientConnectionConfiguration, masterOverride string) (clientset.Interface, v1core.EventsGetter, error) { var kubeConfig *rest.Config var err error - if len(config.KubeConfigFile) == 0 && len(masterOverride) == 0 { + if len(config.Kubeconfig) == 0 && len(masterOverride) == 0 { glog.Info("Neither kubeconfig file nor master URL was specified. Falling back to in-cluster config.") kubeConfig, err = rest.InClusterConfig() } else { // This creates a client, first loading any specified kubeconfig // file, and then overriding the Master flag, if non-empty. kubeConfig, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: config.KubeConfigFile}, + &clientcmd.ClientConfigLoadingRules{ExplicitPath: config.Kubeconfig}, &clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: masterOverride}}).ClientConfig() } if err != nil { diff --git a/cmd/kube-proxy/app/server_test.go b/cmd/kube-proxy/app/server_test.go index ed32520a587..be704cc4269 100644 --- a/cmd/kube-proxy/app/server_test.go +++ b/cmd/kube-proxy/app/server_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/assert" + apimachineryconfig "k8s.io/apimachinery/pkg/apis/config" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/diff" api "k8s.io/kubernetes/pkg/apis/core" @@ -288,11 +289,11 @@ nodePortAddresses: } expected := &kubeproxyconfig.KubeProxyConfiguration{ BindAddress: expBindAddr, - ClientConnection: kubeproxyconfig.ClientConnectionConfiguration{ + ClientConnection: apimachineryconfig.ClientConnectionConfiguration{ AcceptContentTypes: "abc", Burst: 100, ContentType: "content-type", - KubeConfigFile: "/path/to/kubeconfig", + Kubeconfig: "/path/to/kubeconfig", QPS: 7, }, ClusterCIDR: tc.clusterCIDR, diff --git a/cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go b/cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go index 26bc7d33fac..3e6451c1cf2 100644 --- a/cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go +++ b/cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go @@ -136,8 +136,8 @@ func SetDefaults_ProxyConfiguration(obj *InitConfiguration) { obj.KubeProxy.Config.ClusterCIDR = obj.Networking.PodSubnet } - if obj.KubeProxy.Config.ClientConnection.KubeConfigFile == "" { - obj.KubeProxy.Config.ClientConnection.KubeConfigFile = KubeproxyKubeConfigFileName + if obj.KubeProxy.Config.ClientConnection.Kubeconfig == "" { + obj.KubeProxy.Config.ClientConnection.Kubeconfig = KubeproxyKubeConfigFileName } kubeproxyscheme.Scheme.Default(obj.KubeProxy.Config) diff --git a/cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go b/cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go index fb3fd4d6581..6784dea4946 100644 --- a/cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go +++ b/cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go @@ -66,8 +66,8 @@ func defaultKubeProxyConfiguration(internalcfg *ClusterConfiguration, obj *kubep obj.ClusterCIDR = internalcfg.Networking.PodSubnet } - if obj.ClientConnection.KubeConfigFile == "" { - obj.ClientConnection.KubeConfigFile = "/var/lib/kube-proxy/kubeconfig.conf" + if obj.ClientConnection.Kubeconfig == "" { + obj.ClientConnection.Kubeconfig = "/var/lib/kube-proxy/kubeconfig.conf" } } diff --git a/cmd/kubeadm/app/componentconfigs/defaults.go b/cmd/kubeadm/app/componentconfigs/defaults.go index 97176f432b7..a14e44aacdb 100644 --- a/cmd/kubeadm/app/componentconfigs/defaults.go +++ b/cmd/kubeadm/app/componentconfigs/defaults.go @@ -45,8 +45,8 @@ func DefaultKubeProxyConfiguration(internalcfg *kubeadmapi.ClusterConfiguration) externalproxycfg.ClusterCIDR = internalcfg.Networking.PodSubnet } - if externalproxycfg.ClientConnection.KubeConfigFile == "" { - externalproxycfg.ClientConnection.KubeConfigFile = KubeproxyKubeConfigFileName + if externalproxycfg.ClientConnection.Kubeconfig == "" { + externalproxycfg.ClientConnection.Kubeconfig = KubeproxyKubeConfigFileName } // Run the rest of the kube-proxy defaulting code diff --git a/cmd/kubeadm/app/util/config/testdata/conversion/master/internal.yaml b/cmd/kubeadm/app/util/config/testdata/conversion/master/internal.yaml index 96988081553..3805072b984 100644 --- a/cmd/kubeadm/app/util/config/testdata/conversion/master/internal.yaml +++ b/cmd/kubeadm/app/util/config/testdata/conversion/master/internal.yaml @@ -29,7 +29,7 @@ ComponentConfigs: AcceptContentTypes: "" Burst: 10 ContentType: application/vnd.kubernetes.protobuf - KubeConfigFile: /var/lib/kube-proxy/kubeconfig.conf + Kubeconfig: /var/lib/kube-proxy/kubeconfig.conf QPS: 5 ClusterCIDR: "" ConfigSyncPeriod: 15m0s diff --git a/pkg/proxy/apis/config/types.go b/pkg/proxy/apis/config/types.go index b53ca0f7e01..7df427a7f80 100644 --- a/pkg/proxy/apis/config/types.go +++ b/pkg/proxy/apis/config/types.go @@ -21,25 +21,10 @@ import ( "sort" "strings" + apimachineryconfig "k8s.io/apimachinery/pkg/apis/config" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// ClientConnectionConfiguration contains details for constructing a client. -type ClientConnectionConfiguration struct { - // kubeconfig is the path to a kubeconfig file. - KubeConfigFile string - // acceptContentTypes defines the Accept header sent by clients when connecting to a server, overriding the - // default value of 'application/json'. This field will control all connections to the server used by a particular - // client. - AcceptContentTypes string - // contentType is the content type used when sending data to the server from this client. - ContentType string - // qps controls the number of queries per second allowed for this connection. - QPS float32 - // burst allows extra queries to accumulate when a client is exceeding its rate. - Burst int32 -} - // KubeProxyIPTablesConfiguration contains iptables-related configuration // details for the Kubernetes proxy server. type KubeProxyIPTablesConfiguration struct { @@ -123,7 +108,7 @@ type KubeProxyConfiguration struct { HostnameOverride string // clientConnection specifies the kubeconfig file and client connection settings for the proxy // server to use when communicating with the apiserver. - ClientConnection ClientConnectionConfiguration + ClientConnection apimachineryconfig.ClientConnectionConfiguration // iptables contains iptables-related configuration options. IPTables KubeProxyIPTablesConfiguration // ipvs contains ipvs-related configuration options. diff --git a/pkg/proxy/apis/config/v1alpha1/types.go b/pkg/proxy/apis/config/v1alpha1/types.go index beab095d605..b9c370b0d3c 100644 --- a/pkg/proxy/apis/config/v1alpha1/types.go +++ b/pkg/proxy/apis/config/v1alpha1/types.go @@ -17,25 +17,10 @@ limitations under the License. package v1alpha1 import ( + apimachineryconfigv1alpha1 "k8s.io/apimachinery/pkg/apis/config/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// ClientConnectionConfiguration contains details for constructing a client. -type ClientConnectionConfiguration struct { - // kubeconfig is the path to a kubeconfig file. - KubeConfigFile string `json:"kubeconfig"` - // acceptContentTypes defines the Accept header sent by clients when connecting to a server, overriding the - // default value of 'application/json'. This field will control all connections to the server used by a particular - // client. - AcceptContentTypes string `json:"acceptContentTypes"` - // contentType is the content type used when sending data to the server from this client. - ContentType string `json:"contentType"` - // qps controls the number of queries per second allowed for this connection. - QPS float32 `json:"qps"` - // burst allows extra queries to accumulate when a client is exceeding its rate. - Burst int `json:"burst"` -} - // KubeProxyIPTablesConfiguration contains iptables-related configuration // details for the Kubernetes proxy server. type KubeProxyIPTablesConfiguration struct { @@ -119,7 +104,7 @@ type KubeProxyConfiguration struct { HostnameOverride string `json:"hostnameOverride"` // clientConnection specifies the kubeconfig file and client connection settings for the proxy // server to use when communicating with the apiserver. - ClientConnection ClientConnectionConfiguration `json:"clientConnection"` + ClientConnection apimachineryconfigv1alpha1.ClientConnectionConfiguration `json:"clientConnection"` // iptables contains iptables-related configuration options. IPTables KubeProxyIPTablesConfiguration `json:"iptables"` // ipvs contains ipvs-related configuration options. diff --git a/pkg/proxy/apis/config/validation/validation.go b/pkg/proxy/apis/config/validation/validation.go index e1e527329d6..04d9e5ed9e6 100644 --- a/pkg/proxy/apis/config/validation/validation.go +++ b/pkg/proxy/apis/config/validation/validation.go @@ -23,6 +23,7 @@ import ( "strconv" "strings" + apimachineryconfig "k8s.io/apimachinery/pkg/apis/config" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation/field" @@ -186,7 +187,7 @@ func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Pat return field.ErrorList{field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg)} } -func validateClientConnectionConfiguration(config kubeproxyconfig.ClientConnectionConfiguration, fldPath *field.Path) field.ErrorList { +func validateClientConnectionConfiguration(config apimachineryconfig.ClientConnectionConfiguration, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(config.Burst), fldPath.Child("Burst"))...) return allErrs diff --git a/pkg/proxy/apis/config/validation/validation_test.go b/pkg/proxy/apis/config/validation/validation_test.go index 7117e1e3469..ca6d9a88136 100644 --- a/pkg/proxy/apis/config/validation/validation_test.go +++ b/pkg/proxy/apis/config/validation/validation_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + apimachineryconfig "k8s.io/apimachinery/pkg/apis/config" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation/field" kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" @@ -574,7 +575,7 @@ func TestValidateProxyMode(t *testing.T) { func TestValidateClientConnectionConfiguration(t *testing.T) { newPath := field.NewPath("KubeProxyConfiguration") - successCases := []kubeproxyconfig.ClientConnectionConfiguration{ + successCases := []apimachineryconfig.ClientConnectionConfiguration{ { Burst: 0, }, @@ -590,11 +591,11 @@ func TestValidateClientConnectionConfiguration(t *testing.T) { } errorCases := []struct { - ccc kubeproxyconfig.ClientConnectionConfiguration + ccc apimachineryconfig.ClientConnectionConfiguration msg string }{ { - ccc: kubeproxyconfig.ClientConnectionConfiguration{Burst: -5}, + ccc: apimachineryconfig.ClientConnectionConfiguration{Burst: -5}, msg: "must be greater than or equal to 0", }, }