-
Notifications
You must be signed in to change notification settings - Fork 707
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
Flux oci support 2 #4932
Merged
gfichtenholt
merged 13 commits into
vmware-tanzu:main
from
gfichtenholt:flux-oci-support-2
Jun 22, 2022
Merged
Flux oci support 2 #4932
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8fd775b
incremental
gfichtenholt 2af903b
Merge branch 'main' into flux-oci-support-2
gfichtenholt de4cf46
inremental
gfichtenholt a5107f4
Merge branch 'main' into flux-oci-support-2
gfichtenholt 42cc0ca
incremental
gfichtenholt beaf62f
incremental
gfichtenholt f550866
incremental
gfichtenholt 944fca8
incremental
gfichtenholt 0ee44de
incremental
gfichtenholt 67dddb9
incremental
gfichtenholt 7658abd
incremental
gfichtenholt 7eb2bb2
incremental
gfichtenholt d314d46
Michael's comments
gfichtenholt 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
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
104 changes: 104 additions & 0 deletions
104
cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/common/transport/transport.go
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
Copyright 2022 The Flux authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// a copy of fluxcd source-controller internal/transport/transport.go | ||
package transport | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// TransportPool is a progressive and non-blocking pool | ||
// for http.Transport objects, optimised for Gargabe Collection | ||
// and without a hard limit on number of objects created. | ||
// | ||
// Its main purpose is to enable for transport objects to be | ||
// used across helm chart download requests and helm/pkg/getter | ||
// instances by leveraging the getter.WithTransport(t) construct. | ||
// | ||
// The use of this pool improves the default behaviour of helm getter | ||
// which creates a new connection per request, or per getter instance, | ||
// resulting on unnecessary TCP connections with the target. | ||
// | ||
// http.Transport objects may contain sensitive material and also have | ||
// settings that may impact the security of HTTP operations using | ||
// them (i.e. InsecureSkipVerify). Therefore, ensure that they are | ||
// used in a thread-safe way, and also by reseting TLS specific state | ||
// after each use. | ||
// | ||
// Calling the Release(t) function will reset TLS specific state whilst | ||
// also releasing the transport back to the pool to be reused. | ||
// | ||
// xref: https://github.com/helm/helm/pull/10568 | ||
// xref2: https://github.com/fluxcd/source-controller/issues/578 | ||
type TransportPool struct { | ||
} | ||
|
||
var pool = &sync.Pool{ | ||
New: func() interface{} { | ||
return &http.Transport{ | ||
DisableCompression: true, | ||
Proxy: http.ProxyFromEnvironment, | ||
|
||
// Due to the non blocking nature of this approach, | ||
// at peak usage a higher number of transport objects | ||
// may be created. sync.Pool will ensure they are | ||
// gargage collected when/if needed. | ||
// | ||
// By setting a low value to IdleConnTimeout the connections | ||
// will be closed after that period of inactivity, allowing the | ||
// transport to be garbage collected. | ||
IdleConnTimeout: 60 * time.Second, | ||
|
||
// use safe defaults based off http.DefaultTransport | ||
DialContext: (&net.Dialer{ | ||
Timeout: 30 * time.Second, | ||
KeepAlive: 30 * time.Second, | ||
}).DialContext, | ||
TLSHandshakeTimeout: 10 * time.Second, | ||
ExpectContinueTimeout: 1 * time.Second, | ||
} | ||
}, | ||
} | ||
|
||
// NewOrIdle tries to return an existing transport that is not currently being used. | ||
// If none is found, creates a new Transport instead. | ||
// | ||
// tlsConfig can optionally set the TLSClientConfig for the transport. | ||
func NewOrIdle(tlsConfig *tls.Config) *http.Transport { | ||
t := pool.Get().(*http.Transport) | ||
t.TLSClientConfig = tlsConfig | ||
|
||
return t | ||
} | ||
|
||
// Release releases the transport back to the TransportPool after | ||
// sanitising its sensitive fields. | ||
func Release(transport *http.Transport) error { | ||
if transport == nil { | ||
return fmt.Errorf("cannot release nil transport") | ||
} | ||
|
||
transport.TLSClientConfig = nil | ||
|
||
pool.Put(transport) | ||
return nil | ||
} |
58 changes: 58 additions & 0 deletions
58
cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/common/transport/transport_test.go
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2022 The Flux authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package transport | ||
|
||
import ( | ||
"crypto/tls" | ||
"testing" | ||
) | ||
|
||
func Test_TransportReuse(t *testing.T) { | ||
t1 := NewOrIdle(nil) | ||
t2 := NewOrIdle(nil) | ||
|
||
if t1 == t2 { | ||
t.Errorf("same transported returned twice") | ||
} | ||
|
||
err := Release(t2) | ||
if err != nil { | ||
t.Errorf("error releasing transport t2: %v", err) | ||
} | ||
|
||
t3 := NewOrIdle(&tls.Config{ | ||
ServerName: "testing", | ||
}) | ||
if t3.TLSClientConfig == nil || t3.TLSClientConfig.ServerName != "testing" { | ||
t.Errorf("TLSClientConfig not properly configured") | ||
} | ||
|
||
err = Release(t3) | ||
if err != nil { | ||
t.Errorf("error releasing transport t3: %v", err) | ||
} | ||
if t3.TLSClientConfig != nil { | ||
t.Errorf("TLSClientConfig not cleared after release") | ||
} | ||
|
||
err = Release(nil) | ||
if err == nil { | ||
t.Errorf("should not allow release nil transport") | ||
} else if err.Error() != "cannot release nil transport" { | ||
t.Errorf("wanted error message: 'cannot release nil transport' got: %q", err.Error()) | ||
} | ||
} |
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.
Looks like it's just this one file for the transport that's been copied in: I reckon it might be worth a comment here why we're deciding to copy this file into here (why the functionality is important enough - probably obvious to you, but won't be to other contributors until they dig in). Also, I think you already checked last time, but is there a way to convince the flux project to move this (one) package out of their
internal
packages?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.
it implements pooling. I.e. it is goodness
I am certainly not trying to blaze any trails with this
kubeapps/pkg/helm/helm.go
Line 35 in 284c24e
re: is there a way to convince the flux project to move this (one) package out of their internal packages
Egghh, how would I start this conversation? What can I offer to flux guys to make it worth the effort of changing what's there? There has to be something in it for flux guys in what I am suggesting. Let me sleep on it....
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 will add some words to clarify why I chose to copy