File tree 2 files changed +0
-37
lines changed
2 files changed +0
-37
lines changed Original file line number Diff line number Diff line change @@ -17,25 +17,11 @@ limitations under the License.
17
17
package client
18
18
19
19
import (
20
- "net/http"
21
-
22
20
"github.com/kcp-dev/logicalcluster/v3"
23
21
24
22
"k8s.io/client-go/rest"
25
23
)
26
24
27
- // SetMultiClusterRoundTripper wraps an existing config's roundtripper
28
- // with a custom cluster aware roundtripper.
29
- //
30
- // Note: it is the caller responsibility to make a copy of the rest config
31
- func SetMultiClusterRoundTripper (cfg * rest.Config ) * rest.Config {
32
- cfg .Wrap (func (rt http.RoundTripper ) http.RoundTripper {
33
- return NewClusterRoundTripper (rt )
34
- })
35
-
36
- return cfg
37
- }
38
-
39
25
// SetCluster modifies the config host path to include the
40
26
// cluster endpoint.
41
27
//
Original file line number Diff line number Diff line change @@ -18,35 +18,12 @@ package client
18
18
19
19
import (
20
20
"fmt"
21
- "net/http"
22
21
"regexp"
23
22
"strings"
24
23
25
24
"github.com/kcp-dev/logicalcluster/v3"
26
25
)
27
26
28
- // ClusterRoundTripper is a cluster aware wrapper around http.RoundTripper
29
- type ClusterRoundTripper struct {
30
- delegate http.RoundTripper
31
- }
32
-
33
- // NewClusterRoundTripper creates a new cluster aware round tripper
34
- func NewClusterRoundTripper (delegate http.RoundTripper ) * ClusterRoundTripper {
35
- return & ClusterRoundTripper {
36
- delegate : delegate ,
37
- }
38
- }
39
-
40
- func (c * ClusterRoundTripper ) RoundTrip (req * http.Request ) (* http.Response , error ) {
41
- cluster , ok := logicalcluster .ClusterFromContext (req .Context ())
42
- if ok {
43
- req = req .Clone (req .Context ())
44
- req .URL .Path = generatePath (req .URL .Path , cluster .Path ())
45
- req .URL .RawPath = generatePath (req .URL .RawPath , cluster .Path ())
46
- }
47
- return c .delegate .RoundTrip (req )
48
- }
49
-
50
27
// apiRegex matches any string that has /api/ or /apis/ in it.
51
28
var apiRegex = regexp .MustCompile (`(/api/|/apis/)` )
52
29
You can’t perform that action at this time.
0 commit comments