-
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
Merged
Changes from all 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
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,26 @@ 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) | ||
|
||
// The log line printed by pflag is not captured by the log recorder. | ||
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" | ||
`), b.String()) | ||
}) | ||
|
||
t.Run("error when no auth method specified", func(t *testing.T) { | ||
_, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
|
@@ -375,19 +392,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 +651,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 +747,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.