mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #112580 from shyamjvs/disable-compression
Add --disable-compression flag to kubectl
This commit is contained in:
commit
b8e740f2e5
@ -37,24 +37,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagClusterName = "cluster"
|
flagClusterName = "cluster"
|
||||||
flagAuthInfoName = "user"
|
flagAuthInfoName = "user"
|
||||||
flagContext = "context"
|
flagContext = "context"
|
||||||
flagNamespace = "namespace"
|
flagNamespace = "namespace"
|
||||||
flagAPIServer = "server"
|
flagAPIServer = "server"
|
||||||
flagTLSServerName = "tls-server-name"
|
flagTLSServerName = "tls-server-name"
|
||||||
flagInsecure = "insecure-skip-tls-verify"
|
flagInsecure = "insecure-skip-tls-verify"
|
||||||
flagCertFile = "client-certificate"
|
flagCertFile = "client-certificate"
|
||||||
flagKeyFile = "client-key"
|
flagKeyFile = "client-key"
|
||||||
flagCAFile = "certificate-authority"
|
flagCAFile = "certificate-authority"
|
||||||
flagBearerToken = "token"
|
flagBearerToken = "token"
|
||||||
flagImpersonate = "as"
|
flagImpersonate = "as"
|
||||||
flagImpersonateUID = "as-uid"
|
flagImpersonateUID = "as-uid"
|
||||||
flagImpersonateGroup = "as-group"
|
flagImpersonateGroup = "as-group"
|
||||||
flagUsername = "username"
|
flagUsername = "username"
|
||||||
flagPassword = "password"
|
flagPassword = "password"
|
||||||
flagTimeout = "request-timeout"
|
flagTimeout = "request-timeout"
|
||||||
flagCacheDir = "cache-dir"
|
flagCacheDir = "cache-dir"
|
||||||
|
flagDisableCompression = "disable-compression"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
|
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
|
||||||
@ -80,23 +81,24 @@ type ConfigFlags struct {
|
|||||||
KubeConfig *string
|
KubeConfig *string
|
||||||
|
|
||||||
// config flags
|
// config flags
|
||||||
ClusterName *string
|
ClusterName *string
|
||||||
AuthInfoName *string
|
AuthInfoName *string
|
||||||
Context *string
|
Context *string
|
||||||
Namespace *string
|
Namespace *string
|
||||||
APIServer *string
|
APIServer *string
|
||||||
TLSServerName *string
|
TLSServerName *string
|
||||||
Insecure *bool
|
Insecure *bool
|
||||||
CertFile *string
|
CertFile *string
|
||||||
KeyFile *string
|
KeyFile *string
|
||||||
CAFile *string
|
CAFile *string
|
||||||
BearerToken *string
|
BearerToken *string
|
||||||
Impersonate *string
|
Impersonate *string
|
||||||
ImpersonateUID *string
|
ImpersonateUID *string
|
||||||
ImpersonateGroup *[]string
|
ImpersonateGroup *[]string
|
||||||
Username *string
|
Username *string
|
||||||
Password *string
|
Password *string
|
||||||
Timeout *string
|
Timeout *string
|
||||||
|
DisableCompression *bool
|
||||||
// If non-nil, wrap config function can transform the Config
|
// If non-nil, wrap config function can transform the Config
|
||||||
// before it is returned in ToRESTConfig function.
|
// before it is returned in ToRESTConfig function.
|
||||||
WrapConfigFn func(*rest.Config) *rest.Config
|
WrapConfigFn func(*rest.Config) *rest.Config
|
||||||
@ -199,6 +201,9 @@ func (f *ConfigFlags) toRawKubeConfigLoader() clientcmd.ClientConfig {
|
|||||||
if f.Insecure != nil {
|
if f.Insecure != nil {
|
||||||
overrides.ClusterInfo.InsecureSkipTLSVerify = *f.Insecure
|
overrides.ClusterInfo.InsecureSkipTLSVerify = *f.Insecure
|
||||||
}
|
}
|
||||||
|
if f.DisableCompression != nil {
|
||||||
|
overrides.ClusterInfo.DisableCompression = *f.DisableCompression
|
||||||
|
}
|
||||||
|
|
||||||
// bind context flags
|
// bind context flags
|
||||||
if f.Context != nil {
|
if f.Context != nil {
|
||||||
@ -393,6 +398,9 @@ func (f *ConfigFlags) AddFlags(flags *pflag.FlagSet) {
|
|||||||
if f.Timeout != nil {
|
if f.Timeout != nil {
|
||||||
flags.StringVar(f.Timeout, flagTimeout, *f.Timeout, "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.")
|
flags.StringVar(f.Timeout, flagTimeout, *f.Timeout, "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.")
|
||||||
}
|
}
|
||||||
|
if f.DisableCompression != nil {
|
||||||
|
flags.BoolVar(f.DisableCompression, flagDisableCompression, *f.DisableCompression, "If true, opt-out of response compression for all requests to the server")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDeprecatedPasswordFlag enables the username and password config flags
|
// WithDeprecatedPasswordFlag enables the username and password config flags
|
||||||
@ -424,26 +432,28 @@ func (f *ConfigFlags) WithWrapConfigFn(wrapConfigFn func(*rest.Config) *rest.Con
|
|||||||
func NewConfigFlags(usePersistentConfig bool) *ConfigFlags {
|
func NewConfigFlags(usePersistentConfig bool) *ConfigFlags {
|
||||||
impersonateGroup := []string{}
|
impersonateGroup := []string{}
|
||||||
insecure := false
|
insecure := false
|
||||||
|
disableCompression := false
|
||||||
|
|
||||||
return &ConfigFlags{
|
return &ConfigFlags{
|
||||||
Insecure: &insecure,
|
Insecure: &insecure,
|
||||||
Timeout: utilpointer.String("0"),
|
Timeout: utilpointer.String("0"),
|
||||||
KubeConfig: utilpointer.String(""),
|
KubeConfig: utilpointer.String(""),
|
||||||
|
|
||||||
CacheDir: utilpointer.String(getDefaultCacheDir()),
|
CacheDir: utilpointer.String(getDefaultCacheDir()),
|
||||||
ClusterName: utilpointer.String(""),
|
ClusterName: utilpointer.String(""),
|
||||||
AuthInfoName: utilpointer.String(""),
|
AuthInfoName: utilpointer.String(""),
|
||||||
Context: utilpointer.String(""),
|
Context: utilpointer.String(""),
|
||||||
Namespace: utilpointer.String(""),
|
Namespace: utilpointer.String(""),
|
||||||
APIServer: utilpointer.String(""),
|
APIServer: utilpointer.String(""),
|
||||||
TLSServerName: utilpointer.String(""),
|
TLSServerName: utilpointer.String(""),
|
||||||
CertFile: utilpointer.String(""),
|
CertFile: utilpointer.String(""),
|
||||||
KeyFile: utilpointer.String(""),
|
KeyFile: utilpointer.String(""),
|
||||||
CAFile: utilpointer.String(""),
|
CAFile: utilpointer.String(""),
|
||||||
BearerToken: utilpointer.String(""),
|
BearerToken: utilpointer.String(""),
|
||||||
Impersonate: utilpointer.String(""),
|
Impersonate: utilpointer.String(""),
|
||||||
ImpersonateUID: utilpointer.String(""),
|
ImpersonateUID: utilpointer.String(""),
|
||||||
ImpersonateGroup: &impersonateGroup,
|
ImpersonateGroup: &impersonateGroup,
|
||||||
|
DisableCompression: &disableCompression,
|
||||||
|
|
||||||
usePersistentConfig: usePersistentConfig,
|
usePersistentConfig: usePersistentConfig,
|
||||||
// The more groups you have, the more discovery requests you need to make.
|
// The more groups you have, the more discovery requests you need to make.
|
||||||
|
@ -253,6 +253,48 @@ run_retrieve_multiple_tests() {
|
|||||||
set +o errexit
|
set +o errexit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_kubectl_response_compression_tests() {
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
|
||||||
|
create_and_use_new_namespace
|
||||||
|
kube::log::status "Testing kubectl get objects with/without response compression"
|
||||||
|
|
||||||
|
### Test creation of large configmap objects
|
||||||
|
# Pre-condition: no configmaps exists
|
||||||
|
kube::test::get_object_assert configmaps "{{range.items}}{{${id_field:?}}}:{{end}}" ''
|
||||||
|
# Commands to create 3 configmaps each of size 50KB. Sum of their sizes should be >128KB (defaultGzipThresholdBytes)
|
||||||
|
# for apiserver to allow gzip compression of the response. This is required to test the disable-compression option
|
||||||
|
# from client-side
|
||||||
|
some_string=$(dd status=none if=/dev/urandom bs=1K count=50 2>/dev/null | base64)
|
||||||
|
kubectl create configmap "cm-one" --from-literal=somekey="${some_string}"
|
||||||
|
kubectl create configmap "cm-two" --from-literal=somekey="${some_string}"
|
||||||
|
kubectl create configmap "cm-three" --from-literal=somekey="${some_string}"
|
||||||
|
output_message=$(kubectl get configmaps 2>&1 "${kube_flags[@]:?}")
|
||||||
|
# Post-condition: All configmaps should be created
|
||||||
|
kube::test::if_has_string "${output_message}" "cm-one"
|
||||||
|
kube::test::if_has_string "${output_message}" "cm-two"
|
||||||
|
kube::test::if_has_string "${output_message}" "cm-three"
|
||||||
|
|
||||||
|
### Test list call WITH compression
|
||||||
|
output_message=$(kubectl get configmaps --v=8 2>&1 "${kube_flags[@]:?}")
|
||||||
|
# Post-condition: Response headers should include "accept-encoding" header
|
||||||
|
kube::test::if_has_string "${output_message}" "Vary: Accept-Encoding"
|
||||||
|
|
||||||
|
### Test list call WITHOUT compression
|
||||||
|
output_message=$(kubectl get configmaps --disable-compression=true --v=8 2>&1 "${kube_flags[@]:?}")
|
||||||
|
# Post-condition: Response headers should NOT include "accept-encoding" header
|
||||||
|
kube::test::if_has_not_string "${output_message}" "Vary: Accept-Encoding"
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
kubectl delete configmap "cm-one"
|
||||||
|
kubectl delete configmap "cm-two"
|
||||||
|
kubectl delete configmap "cm-three"
|
||||||
|
|
||||||
|
set +o nounset
|
||||||
|
set +o errexit
|
||||||
|
}
|
||||||
|
|
||||||
run_kubectl_sort_by_tests() {
|
run_kubectl_sort_by_tests() {
|
||||||
set -o nounset
|
set -o nounset
|
||||||
set -o errexit
|
set -o errexit
|
||||||
|
Loading…
Reference in New Issue
Block a user