-
Notifications
You must be signed in to change notification settings - Fork 335
/
manager.go
70 lines (57 loc) · 1.55 KB
/
manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.
package testutils
import (
v1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/envoyproxy/gateway/api/v1alpha1"
extType "github.com/envoyproxy/gateway/internal/extension/types"
)
var _ extType.Manager = (*Manager)(nil)
type Manager struct {
extension v1alpha1.ExtensionManager
}
func NewManager(ext v1alpha1.ExtensionManager) extType.Manager {
return &Manager{
extension: ext,
}
}
func (m *Manager) HasExtension(g v1.Group, k v1.Kind) bool {
extension := m.extension
// TODO: not currently checking the version since extensionRef only supports group and kind.
for _, gvk := range extension.Resources {
if g == v1.Group(gvk.Group) && k == v1.Kind(gvk.Kind) {
return true
}
}
return false
}
func (m *Manager) GetPreXDSHookClient(xdsHookType v1alpha1.XDSTranslatorHook) extType.XDSHookClient {
if m.extension.Hooks == nil {
return nil
}
if m.extension.Hooks.XDSTranslator == nil {
return nil
}
for _, hook := range m.extension.Hooks.XDSTranslator.Pre {
if xdsHookType == hook {
return &XDSHookClient{}
}
}
return nil
}
func (m *Manager) GetPostXDSHookClient(xdsHookType v1alpha1.XDSTranslatorHook) extType.XDSHookClient {
if m.extension.Hooks == nil {
return nil
}
if m.extension.Hooks.XDSTranslator == nil {
return nil
}
for _, hook := range m.extension.Hooks.XDSTranslator.Post {
if xdsHookType == hook {
return &XDSHookClient{}
}
}
return nil
}