Skip to content

Commit

Permalink
Merge branch 'master' into drop-crtclient
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Oct 3, 2024
2 parents 8df7f52 + d0b1f7d commit cff0b63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
37 changes: 0 additions & 37 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ import (
"github.com/labstack/echo/v4/middleware"
glog "github.com/labstack/gommon/log"
errs "github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/httpstream"

"k8s.io/apiserver/pkg/util/wsstream"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand All @@ -65,22 +61,13 @@ func authorizationEndpointTarget() string {

type Proxy struct {
app application.Application
cl client.Client
tokenParser *auth.TokenParser
spaceLister *handlers.SpaceLister
metrics *metrics.ProxyMetrics
getMembersFunc commoncluster.GetMemberClustersFunc
}

func NewProxy(app application.Application, proxyMetrics *metrics.ProxyMetrics, getMembersFunc commoncluster.GetMemberClustersFunc) (*Proxy, error) {
cl, err := newClusterClient()
if err != nil {
return nil, err
}
return newProxyWithClusterClient(app, cl, proxyMetrics, getMembersFunc)
}

func newProxyWithClusterClient(app application.Application, cln client.Client, proxyMetrics *metrics.ProxyMetrics, getMembersFunc commoncluster.GetMemberClustersFunc) (*Proxy, error) {
tokenParser, err := auth.DefaultTokenParser()
if err != nil {
return nil, err
Expand All @@ -90,7 +77,6 @@ func newProxyWithClusterClient(app application.Application, cln client.Client, p
spaceLister := handlers.NewSpaceLister(app, proxyMetrics)
return &Proxy{
app: app,
cl: cln,
tokenParser: tokenParser,
spaceLister: spaceLister,
metrics: proxyMetrics,
Expand Down Expand Up @@ -780,29 +766,6 @@ func singleJoiningSlash(a, b string) string {
return a + b
}

func newClusterClient() (client.Client, error) {
scheme := runtime.NewScheme()
if err := v1.AddToScheme(scheme); err != nil {
return nil, err
}
if err := toolchainv1alpha1.AddToScheme(scheme); err != nil {
return nil, err
}

k8sConfig, err := rest.InClusterConfig()
if err != nil {
return nil, err
}

cl, err := client.New(k8sConfig, client.Options{
Scheme: scheme,
})
if err != nil {
return nil, errs.Wrap(err, "cannot create ToolchainCluster client")
}
return cl, nil
}

var ph = textproto.CanonicalMIMEHeaderKey("Sec-WebSocket-Protocol")

func extractTokenFromWebsocketRequest(req *http.Request) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s *TestProxySuite) TestProxy() {
InformerServiceMock: inf,
}
proxyMetrics := metrics.NewProxyMetrics(prometheus.NewRegistry())
p, err := newProxyWithClusterClient(fakeApp, nil, proxyMetrics, proxytest.NewGetMembersFunc(commontest.NewFakeClient(s.T())))
p, err := NewProxy(fakeApp, proxyMetrics, proxytest.NewGetMembersFunc(commontest.NewFakeClient(s.T())))
require.NoError(s.T(), err)

server := p.StartProxy(DefaultPort)
Expand All @@ -135,8 +135,8 @@ func (s *TestProxySuite) TestProxy() {

func (s *TestProxySuite) spinUpProxy(fakeApp *fake.ProxyFakeApp, port string) (*Proxy, *http.Server) {
proxyMetrics := metrics.NewProxyMetrics(prometheus.NewRegistry())
p, err := newProxyWithClusterClient(
fakeApp, nil, proxyMetrics, proxytest.NewGetMembersFunc(commontest.NewFakeClient(s.T())))
p, err := NewProxy(
fakeApp, proxyMetrics, proxytest.NewGetMembersFunc(commontest.NewFakeClient(s.T())))
require.NoError(s.T(), err)

server := p.StartProxy(port)
Expand Down

0 comments on commit cff0b63

Please sign in to comment.