-
Notifications
You must be signed in to change notification settings - Fork 25
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
VC-37264: Disable compression to give us time to work on a fix #628
Merged
+49
−241
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
20d9b6f
remove logic behind --disable-compression but keep it to avoid breakage
maelvls 695b95c
rm-disable-compression: hide the flag --disable-compression
maelvls 537c1e6
rm-disable-compression: use pflag's MarkDeprecated
maelvls 4a8bccd
rm-disable-compression: fix test
maelvls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,9 +168,8 @@ type AgentCmdFlags struct { | |
// Prometheus (--enable-metrics) enables the Prometheus metrics server. | ||
Prometheus bool | ||
|
||
// DisableCompression (--disable-compression) disables the GZIP compression | ||
// when uploading the data. Useful for debugging purposes, or when an | ||
// intermediate proxy doesn't like compressed data. | ||
// DisableCompression (--disable-compression) is deprecated and no longer | ||
// has an effect. | ||
DisableCompression bool | ||
} | ||
|
||
|
@@ -302,8 +301,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) { | |
&cfg.DisableCompression, | ||
"disable-compression", | ||
false, | ||
"Disables GZIP compression when uploading the data. Useful for debugging purposes or when an intermediate proxy doesn't like compressed data.", | ||
"Deprecated. No longer has an effect.", | ||
) | ||
c.PersistentFlags().MarkHidden("disable-compression") | ||
} | ||
|
||
type AuthMode string | ||
|
@@ -346,7 +346,6 @@ type CombinedConfig struct { | |
VenConnNS string | ||
|
||
// VenafiCloudKeypair and VenafiCloudVenafiConnection modes only. | ||
DisableCompression bool | ||
ExcludeAnnotationKeysRegex []*regexp.Regexp | ||
ExcludeLabelKeysRegex []*regexp.Regexp | ||
|
||
|
@@ -588,10 +587,9 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags) | |
|
||
// Validation of --disable-compression. | ||
{ | ||
if flags.DisableCompression && res.AuthMode != VenafiCloudKeypair && res.AuthMode != VenafiCloudVenafiConnection { | ||
errs = multierror.Append(errs, fmt.Errorf("--disable-compression can only be used with the %s and %s modes", VenafiCloudKeypair, VenafiCloudVenafiConnection)) | ||
if flags.DisableCompression { | ||
log.Info("The flag --disable-compression has been deprecated an no longer has any effect.") | ||
} | ||
res.DisableCompression = flags.DisableCompression | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $ go run ./ agent --one-shot --api-token should-not-be-required --install-namespace venafi --output-path /dev/null --agent-config-file examples/cert-manager-agent.yaml --disable-compression
I1122 17:06:03.444467 284739 run.go:59] "Starting" logger="Run" version="development" commit=""
I1122 17:06:03.444747 284739 config.go:403] "Using the Jetstack Secure API Token auth mode since --api-token was specified." logger="Run"
I1122 17:06:03.444766 284739 config.go:421] "Using deprecated Endpoint configuration. User Server instead." logger="Run"
I1122 17:06:03.444773 284739 config.go:591] "The flag --disable-compression has been deprecated an no longer has any effect." logger="Run"
I1122 17:06:03.444805 284739 run.go:117] "Healthz endpoints enabled" logger="Run.APIServer" addr=":8081" path="/healthz"
I1122 17:06:03.444816 284739 run.go:121] "Readyz endpoints enabled" logger="Run.APIServer" addr=":8081" path="/readyz"
E1122 17:06:03.445471 284739 run.go:269] "Error messages will not show in the pod's events because the POD_NAME environment variable is empty" logger="Run"
I1122 17:06:03.753982 284739 run.go:322] "Data saved to local file" logger="Run.gatherAndOutputData" outputPath="/dev/null" |
||
|
||
// Validation of the config fields exclude_annotation_keys_regex and | ||
|
@@ -709,7 +707,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie | |
break // Don't continue with the client if kubeconfig wasn't loaded. | ||
} | ||
|
||
preflightClient, err = client.NewVenConnClient(restCfg, metadata, cfg.InstallNS, cfg.VenConnName, cfg.VenConnNS, nil, cfg.DisableCompression) | ||
preflightClient, err = client.NewVenConnClient(restCfg, metadata, cfg.InstallNS, cfg.VenConnName, cfg.VenConnNS, nil) | ||
if err != nil { | ||
errs = multierror.Append(errs, err) | ||
} | ||
|
@@ -767,7 +765,7 @@ func createCredentialClient(log logr.Logger, credentials client.Credentials, cfg | |
log.Info("Loading upload_path from \"venafi-cloud\" configuration.") | ||
uploadPath = cfg.UploadPath | ||
} | ||
return client.NewVenafiCloudClient(agentMetadata, creds, cfg.Server, uploaderID, uploadPath, cfg.DisableCompression) | ||
return client.NewVenafiCloudClient(agentMetadata, creds, cfg.Server, uploaderID, uploadPath) | ||
|
||
case *client.OAuthCredentials: | ||
return client.NewOAuthClient(agentMetadata, creds, cfg.Server) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package agent | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
@@ -165,6 +162,25 @@ func Test_ValidateAndCombineConfig(t *testing.T) { | |
assert.Equal(t, true, got.StrictMode) | ||
}) | ||
|
||
t.Run("--disable-compression is deprecated and doesn't do anything", func(t *testing.T) { | ||
path := withFile(t, `{"user_id":"[email protected]","user_secret":"foo","client_id": "k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo","client_secret": "f39w_3KT9Vp0VhzcPzvh-uVbudzqCFmHER3Huj0dvHgJwVrjxsoOQPIw_1SDiCfa","auth_server_domain":"auth.jetstack.io"}`) | ||
log, b := recordLogs(t) | ||
_, _, err := ValidateAndCombineConfig(log, | ||
withConfig(testutil.Undent(` | ||
server: https://api.venafi.eu | ||
period: 1h | ||
organization_id: foo | ||
cluster_id: bar | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--credentials-file", path, "--install-namespace", "venafi")) | ||
require.NoError(t, err) | ||
assert.Equal(t, testutil.Undent(` | ||
INFO Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud. | ||
INFO Using period from config period="1h0m0s" | ||
INFO The flag --disable-compression has been deprecated an no longer has any effect. | ||
`), b.String()) | ||
}) | ||
|
||
t.Run("error when no auth method specified", func(t *testing.T) { | ||
_, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
|
@@ -375,19 +391,6 @@ func Test_ValidateAndCombineConfig(t *testing.T) { | |
assert.IsType(t, &client.OAuthClient{}, cl) | ||
}) | ||
|
||
t.Run("jetstack-secure-oauth-auth: can't use --disable-compression", func(t *testing.T) { | ||
path := withFile(t, `{"user_id":"[email protected]","user_secret":"foo","client_id": "k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo","client_secret": "f39w_3KT9Vp0VhzcPzvh-uVbudzqCFmHER3Huj0dvHgJwVrjxsoOQPIw_1SDiCfa","auth_server_domain":"auth.jetstack.io"}`) | ||
_, _, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: https://api.venafi.eu | ||
period: 1h | ||
organization_id: foo | ||
cluster_id: bar | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--credentials-file", path, "--install-namespace", "venafi")) | ||
require.EqualError(t, err, "1 error occurred:\n\t* --disable-compression can only be used with the Venafi Cloud Key Pair Service Account and Venafi Cloud VenafiConnection modes\n\n") | ||
}) | ||
|
||
t.Run("jetstack-secure-oauth-auth: --credential-file used but file is missing", func(t *testing.T) { | ||
t.Setenv("POD_NAMESPACE", "venafi") | ||
got, _, err := ValidateAndCombineConfig(discardLogs(), | ||
|
@@ -647,83 +650,6 @@ func Test_ValidateAndCombineConfig_VenafiCloudKeyPair(t *testing.T) { | |
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("the request body is compressed", func(t *testing.T) { | ||
srv, cert, setVenafiCloudAssert := testutil.FakeVenafiCloud(t) | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
if gotReq.URL.Path == "/v1/oauth/token/serviceaccount" { | ||
return | ||
} | ||
assert.Equal(t, "/v1/tlspk/upload/clusterdata/no", gotReq.URL.Path) | ||
|
||
// Let's check that the body is compressed as expected. | ||
assert.Equal(t, "gzip", gotReq.Header.Get("Content-Encoding")) | ||
uncompressR, err := gzip.NewReader(gotReq.Body) | ||
require.NoError(t, err, "body might not be compressed") | ||
defer uncompressR.Close() | ||
uncompressed, err := io.ReadAll(uncompressR) | ||
require.NoError(t, err) | ||
assert.Contains(t, string(uncompressed), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
privKeyPath := withFile(t, fakePrivKeyPEM) | ||
got, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: `+srv.URL+` | ||
period: 1h | ||
cluster_id: "test cluster name" | ||
venafi-cloud: | ||
uploader_id: no | ||
upload_path: /v1/tlspk/upload/clusterdata | ||
`)), | ||
withCmdLineFlags("--client-id", "5bc7d07c-45da-11ef-a878-523f1e1d7de1", "--private-key-path", privKeyPath, "--install-namespace", "venafi"), | ||
) | ||
require.NoError(t, err) | ||
testutil.TrustCA(t, cl, cert) | ||
assert.Equal(t, VenafiCloudKeypair, got.AuthMode) | ||
require.NoError(t, err) | ||
|
||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("--disable-compression works", func(t *testing.T) { | ||
srv, cert, setVenafiCloudAssert := testutil.FakeVenafiCloud(t) | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
// Only care about /v1/tlspk/upload/clusterdata/:uploader_id?name= | ||
if gotReq.URL.Path == "/v1/oauth/token/serviceaccount" { | ||
return | ||
} | ||
|
||
assert.Equal(t, "/v1/tlspk/upload/clusterdata/no", gotReq.URL.Path) | ||
|
||
// Let's check that the body isn't compressed. | ||
assert.Equal(t, "", gotReq.Header.Get("Content-Encoding")) | ||
b := new(bytes.Buffer) | ||
_, err := b.ReadFrom(gotReq.Body) | ||
require.NoError(t, err) | ||
assert.Contains(t, b.String(), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
|
||
privKeyPath := withFile(t, fakePrivKeyPEM) | ||
got, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: `+srv.URL+` | ||
period: 1h | ||
cluster_id: "test cluster name" | ||
venafi-cloud: | ||
uploader_id: no | ||
upload_path: /v1/tlspk/upload/clusterdata | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--client-id", "5bc7d07c-45da-11ef-a878-523f1e1d7de1", "--private-key-path", privKeyPath, "--install-namespace", "venafi"), | ||
) | ||
require.NoError(t, err) | ||
testutil.TrustCA(t, cl, cert) | ||
assert.Equal(t, VenafiCloudKeypair, got.AuthMode) | ||
require.NoError(t, err) | ||
|
||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
// Slower test cases due to envtest. That's why they are separated from the | ||
|
@@ -820,53 +746,6 @@ func Test_ValidateAndCombineConfig_VenafiConnection(t *testing.T) { | |
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("the request is compressed by default", func(t *testing.T) { | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
// Let's check that the body is compressed as expected. | ||
assert.Equal(t, "gzip", gotReq.Header.Get("Content-Encoding")) | ||
uncompressR, err := gzip.NewReader(gotReq.Body) | ||
require.NoError(t, err, "body might not be compressed") | ||
defer uncompressR.Close() | ||
uncompressed, err := io.ReadAll(uncompressR) | ||
require.NoError(t, err) | ||
assert.Contains(t, string(uncompressed), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
cfg, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
period: 1h | ||
cluster_id: test cluster name | ||
`)), | ||
withCmdLineFlags("--venafi-connection", "venafi-components", "--install-namespace", "venafi")) | ||
require.NoError(t, err) | ||
testutil.VenConnStartWatching(t, cl) | ||
testutil.TrustCA(t, cl, cert) | ||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("--disable-compression works", func(t *testing.T) { | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
// Let's check that the body isn't compressed. | ||
assert.Equal(t, "", gotReq.Header.Get("Content-Encoding")) | ||
b := new(bytes.Buffer) | ||
_, err := b.ReadFrom(gotReq.Body) | ||
require.NoError(t, err) | ||
assert.Contains(t, b.String(), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
cfg, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: `+srv.URL+` | ||
period: 1h | ||
cluster_id: test cluster name | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--venafi-connection", "venafi-components", "--install-namespace", "venafi")) | ||
require.NoError(t, err) | ||
testutil.VenConnStartWatching(t, cl) | ||
testutil.TrustCA(t, cl, cert) | ||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
func Test_ParseConfig(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional. Consider using the
pflag.MarkDeprecated
method instead, which will hide the flag from the --help and therefore from the documented CLI help.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, that would be even better.
I've tried this:
But it uses logrus' logger, so it doesn't show as JSON (first line of the below snippet):
Is that OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use MarkHidden instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to use
MarkDeprecated
as you initially suggested. It seemed more appropriate and I was able to remove all traces of theDisableCompression
variable, so even better.I don't think this "plain text" line is a big deal; no one will ever see it anyways, and I can fix it later if I can find a way to set up pflag's logger.