Skip to content

Commit

Permalink
feat(infrastructure): Handle exact match URL too
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Apr 3, 2024
1 parent 791b691 commit c2e763f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/infrastructure/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ func newHTTPClient(config *rest.Config) (*http.Client, error) {

const (
gatewayAPIPath = "/apis/gateway.networking.k8s.io/"
gatewayAPIPathV1 = gatewayAPIPath + "v1/"
gatewayAPIPathV1Beta1 = gatewayAPIPath + "v1beta1/"
gatewayAPIPathV1 = gatewayAPIPath + "v1"
gatewayAPIPathV1Beta1 = gatewayAPIPath + "v1beta1"
)

type rewriteAPIVersion struct {
http.RoundTripper
}

func (r rewriteAPIVersion) RoundTrip(req *http.Request) (*http.Response, error) {
if strings.HasPrefix(req.URL.Path, gatewayAPIPathV1) {
req.URL.Path = strings.Replace(req.URL.Path, gatewayAPIPathV1, gatewayAPIPathV1Beta1, 1)
if req.URL.Path == gatewayAPIPathV1 || strings.HasPrefix(req.URL.Path, gatewayAPIPathV1) {
req.URL.Path = gatewayAPIPathV1Beta1 + req.URL.Path[len(gatewayAPIPathV1):]
}

return r.RoundTripper.RoundTrip(req)
Expand Down

0 comments on commit c2e763f

Please sign in to comment.