-
Notifications
You must be signed in to change notification settings - Fork 334
/
plugin.go
101 lines (83 loc) · 3.15 KB
/
plugin.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gateway
import (
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
config_core "github.com/kumahq/kuma/pkg/config/core"
"github.com/kumahq/kuma/pkg/core"
"github.com/kumahq/kuma/pkg/core/datasource"
core_plugins "github.com/kumahq/kuma/pkg/core/plugins"
mesh_k8s "github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/api/v1alpha1"
"github.com/kumahq/kuma/pkg/plugins/runtime/gateway/register"
"github.com/kumahq/kuma/pkg/xds/generator"
"github.com/kumahq/kuma/pkg/xds/template"
)
// OriginGateway marks xDS resources generated by this plugin.
const OriginGateway = "gateway"
const PluginName core_plugins.PluginName = "gateway"
func init() {
core_plugins.Register(PluginName, &plugin{})
}
var (
log = core.Log.WithName("plugin").WithName("runtime").WithName("gateway")
)
type plugin struct{}
var _ core_plugins.BootstrapPlugin = &plugin{}
func (p *plugin) BeforeBootstrap(context *core_plugins.MutablePluginContext, config core_plugins.PluginConfig) error {
if !context.Config().Experimental.MeshGateway {
log.V(1).Info("gateway plugin is disabled")
return nil
}
register.RegisterGatewayTypes()
if context.Config().Environment == config_core.KubernetesEnvironment {
mesh_k8s.RegisterK8SGatewayTypes()
}
return nil
}
func (p *plugin) AfterBootstrap(context *core_plugins.MutablePluginContext, config core_plugins.PluginConfig) error {
if !context.Config().Experimental.MeshGateway {
log.V(1).Info("gateway plugin is disabled")
return nil
}
// Insert our resolver before the default so that we can intercept
// builtin gateway dataplanes.
generator.DefaultTemplateResolver = template.SequentialResolver(
TemplateResolver{},
generator.DefaultTemplateResolver,
)
generator.RegisterProfile(ProfileGatewayProxy, NewProxyProfile(context.Config().Multizone.Zone.Name, context.DataSourceLoader()))
log.Info("registered gateway plugin")
return nil
}
func (p *plugin) Name() core_plugins.PluginName {
return PluginName
}
func (p *plugin) Order() int {
// It has to go before Environment is prepared, so we have resources registered in K8S schema
return core_plugins.EnvironmentPreparingOrder - 1
}
// ProfileGatewayProxy is the name of the gateway proxy template profile.
const ProfileGatewayProxy = "gateway-proxy"
// NewProxyProfile returns a new resource generator profile for builtin
// gateway dataplanes.
func NewProxyProfile(zone string, dataSourceLoader datasource.Loader) generator.ResourceGenerator {
return generator.CompositeResourceGenerator{
generator.AdminProxyGenerator{},
generator.PrometheusEndpointGenerator{},
generator.SecretsProxyGenerator{},
generator.TracingProxyGenerator{},
generator.TransparentProxyGenerator{},
generator.DNSGenerator{},
Generator{
FilterChainGenerators: filterChainGenerators{
FilterChainGenerators: map[mesh_proto.MeshGateway_Listener_Protocol]FilterChainGenerator{
mesh_proto.MeshGateway_Listener_HTTP: &HTTPFilterChainGenerator{},
mesh_proto.MeshGateway_Listener_HTTPS: &HTTPSFilterChainGenerator{
DataSourceLoader: dataSourceLoader,
},
}},
ClusterGenerator: ClusterGenerator{
DataSourceLoader: dataSourceLoader,
Zone: zone,
},
},
}
}