Skip to content

Commit

Permalink
Add the client-go debug round tripper to the venafi client
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Wall <richard.wall@venafi.com>
  • Loading branch information
wallrj committed Nov 27, 2024
1 parent 2e85bbf commit 59f1302
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
5 changes: 1 addition & 4 deletions hack/e2e/values.venafi-kubernetes-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ authentication:
enabled: true

extraArgs:
- --logging-format=text
# Show trace logs for the venafi-connection-lib client
# See https://github.com/jetstack/venafi-connection-lib/blob/13c2342fe0140ff084d2aabfd29ae3d10721691b/internal/http_client/metrics_transport.go#L93-L115
- --vmodule=metrics_transport=6
- --logging-format=json
8 changes: 6 additions & 2 deletions pkg/client/client_api_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/jetstack/preflight/api"
"k8s.io/client-go/transport"
)

type (
Expand All @@ -30,12 +31,15 @@ func NewAPITokenClient(agentMetadata *api.AgentMetadata, apiToken, baseURL strin
if baseURL == "" {
return nil, fmt.Errorf("cannot create APITokenClient: baseURL cannot be empty")
}

httpClient := &http.Client{
Timeout: time.Minute,
Transport: transport.DebugWrappers(http.DefaultTransport),
}
return &APITokenClient{
apiToken: apiToken,
agentMetadata: agentMetadata,
baseURL: baseURL,
client: &http.Client{Timeout: time.Minute},
client: httpClient,
}, nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/client/client_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"k8s.io/client-go/transport"

"github.com/jetstack/preflight/api"
)
Expand Down Expand Up @@ -94,7 +95,10 @@ func NewOAuthClient(agentMetadata *api.AgentMetadata, credentials *OAuthCredenti
credentials: credentials,
baseURL: baseURL,
accessToken: &accessToken{},
client: &http.Client{Timeout: time.Minute},
client: &http.Client{
Timeout: time.Minute,
Transport: transport.DebugWrappers(http.DefaultTransport),
},
}, nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/client/client_venafi_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/go-multierror"
"github.com/microcosm-cc/bluemonday"
"k8s.io/client-go/transport"

"github.com/jetstack/preflight/api"
)
Expand Down Expand Up @@ -112,7 +113,10 @@ func NewVenafiCloudClient(agentMetadata *api.AgentMetadata, credentials *VenafiS
credentials: credentials,
baseURL: baseURL,
accessToken: &venafiCloudAccessToken{},
Client: &http.Client{Timeout: time.Minute},
Client: &http.Client{
Timeout: time.Minute,
Transport: transport.DebugWrappers(http.DefaultTransport),
},
uploaderID: uploaderID,
uploadPath: uploadPath,
privateKey: privateKey,
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/client_venconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"k8s.io/client-go/transport"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

"github.com/jetstack/preflight/api"
Expand Down Expand Up @@ -99,11 +100,11 @@ func NewVenConnClient(restcfg *rest.Config, agentMetadata *api.AgentMetadata, in
}

vcpClient := &http.Client{}
tr := http.DefaultTransport.(*http.Transport).Clone()
if trustedCAs != nil {
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.TLSClientConfig.RootCAs = trustedCAs
vcpClient.Transport = tr
}
vcpClient.Transport = transport.DebugWrappers(tr)

return &VenConnClient{
agentMetadata: agentMetadata,
Expand Down

0 comments on commit 59f1302

Please sign in to comment.