Skip to content

Commit

Permalink
imported changes from vcluster
Browse files Browse the repository at this point in the history
  • Loading branch information
facchettos committed Apr 9, 2024
1 parent b2df0db commit c0244ed
Show file tree
Hide file tree
Showing 46 changed files with 2,217 additions and 1,871 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/go-plugin v1.6.0
github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a
github.com/loft-sh/vcluster v0.20.0-alpha.2.0.20240403130844-8bb987ed97b4
github.com/loft-sh/vcluster v0.20.0-alpha.3.0.20240409111424-27cde82f6544
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ github.com/loft-sh/utils v0.0.29 h1:P/MObccXToAZy2QoJSQDJ+OJx1qHitpFHEVj3QBSNJs=
github.com/loft-sh/utils v0.0.29/go.mod h1:9hlX9cGpWHg3mNi/oBlv3X4ePGDMK66k8MbOZGFMDTI=
github.com/loft-sh/vcluster v0.20.0-alpha.2.0.20240403130844-8bb987ed97b4 h1:D486kUE5ZQSx2DDQQ5kf/gowKZG/dNw7As4vg9WR7dw=
github.com/loft-sh/vcluster v0.20.0-alpha.2.0.20240403130844-8bb987ed97b4/go.mod h1:Ty7km/e/U7wVF9kIqROOR51/XezgHEtS/za0QVPhKkU=
github.com/loft-sh/vcluster v0.20.0-alpha.3.0.20240409074019-5b5358d2f54d h1:nTQLvvJS4b9tEBMk4s2yQkxnW/9MW5rZl3eCDqeKarE=
github.com/loft-sh/vcluster v0.20.0-alpha.3.0.20240409074019-5b5358d2f54d/go.mod h1:Ty7km/e/U7wVF9kIqROOR51/XezgHEtS/za0QVPhKkU=
github.com/loft-sh/vcluster v0.20.0-alpha.3.0.20240409111424-27cde82f6544 h1:/UxPl3HXlCwT8whH57NanvcInguAWgubal2QxvSGhoE=
github.com/loft-sh/vcluster v0.20.0-alpha.3.0.20240409111424-27cde82f6544/go.mod h1:Ty7km/e/U7wVF9kIqROOR51/XezgHEtS/za0QVPhKkU=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
12 changes: 5 additions & 7 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type manager struct {
syncers []syncertypes.Base

interceptorsHandlers map[string]http.Handler
interceptors []Interceptor
interceptors map[string][]Interceptor
interceptorsPort int

proConfig v2.InitConfigPro
Expand Down Expand Up @@ -198,13 +198,11 @@ func (m *manager) Register(syncer syncertypes.Base) error {
defer m.m.Unlock()

if int, ok := syncer.(Interceptor); ok {
for _, rule := range int.InterceptedRequests() {
if _, ok := m.interceptorsHandlers[rule.HandlerName]; ok {
return fmt.Errorf("could not add the interceptor %s because the handler name %s is already in use", int.Name(), rule.HandlerName)
}
m.interceptorsHandlers[rule.HandlerName] = int
m.interceptors = append(m.interceptors, int)
if _, ok := m.interceptorsHandlers[int.Name()]; ok {
return fmt.Errorf("could not add the interceptor %s because its name is already in use", int.Name())
}
m.interceptorsHandlers[int.Name()] = int
m.interceptors[int.Name()] = append(m.interceptors[int.Name()], int)
} else {
m.syncers = append(m.syncers, syncer)
}
Expand Down
12 changes: 4 additions & 8 deletions plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type server interface {
Serve()

// SetReady signals the plugin server the plugin is ready to start
SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors []Interceptor, port int)
SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors map[string][]Interceptor, port int)

// Initialized retrieves the initialize request
Initialized() <-chan *pluginv2.Initialize_Request
Expand All @@ -44,7 +44,7 @@ type pluginServer struct {
pluginv2.UnimplementedPluginServer

hooks map[types.VersionKindType][]ClientHook
interceptors []Interceptor
interceptors map[string][]Interceptor
interceptorsPort int

initialized chan *pluginv2.Initialize_Request
Expand Down Expand Up @@ -90,7 +90,7 @@ func (p *pluginServer) IsLeader() <-chan struct{} {
return p.isLeader
}

func (p *pluginServer) SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors []Interceptor, port int) {
func (p *pluginServer) SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors map[string][]Interceptor, port int) {
p.hooks = hooks
p.interceptors = interceptors
p.interceptorsPort = port
Expand Down Expand Up @@ -271,11 +271,7 @@ func (p *pluginServer) getClientHooks() ([]*v2.ClientHook, error) {
return registeredHooks, nil
}

func (p *pluginServer) getInterceptorConfig() *v2.InterceptorConfig {
interceptorConfig := &v2.InterceptorConfig{
Interceptors: make([]v2.Interceptor, 0),
Port: p.interceptorsPort,
}
func (p *pluginServer) getInterceptorConfig() map[string]v2.Interceptor {
for _, interceptor := range p.interceptors {
interceptorConfig.Interceptors = append(interceptorConfig.Interceptors, interceptor.InterceptedRequests()...)
}
Expand Down
44 changes: 22 additions & 22 deletions vendor/github.com/AlecAivazis/survey/v2/terminal/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0244ed

Please sign in to comment.