This repository has been archived by the owner on May 16, 2018. It is now read-only.
/
plugin.go
59 lines (50 loc) · 1.65 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
package kubernetes
import (
envoyapi "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
"github.com/pkg/errors"
"github.com/solo-io/gloo-api/pkg/api/types/v1"
"github.com/solo-io/gloo/pkg/bootstrap"
"github.com/solo-io/gloo/pkg/endpointdiscovery"
"github.com/solo-io/gloo/pkg/plugin"
)
func init() {
plugin.Register(&Plugin{}, createEndpointDiscovery)
}
func createEndpointDiscovery(opts bootstrap.Options) (endpointdiscovery.Interface, error) {
kubeConfig := opts.KubeOptions.KubeConfig
masterUrl := opts.KubeOptions.MasterURL
resyncDuration := opts.ConfigWatcherOptions.SyncFrequency
disc, err := NewEndpointDiscovery(masterUrl, kubeConfig, resyncDuration)
if err != nil {
return nil, errors.Wrap(err, "failed to start Kubernetes endpoint discovery")
}
return disc, err
}
type Plugin struct{}
const (
// define Upstream type name
UpstreamTypeKube = "kubernetes"
)
func (p *Plugin) GetDependencies(_ *v1.Config) *plugin.Dependencies {
return nil
}
func (p *Plugin) ProcessUpstream(_ *plugin.UpstreamPluginParams, in *v1.Upstream, out *envoyapi.Cluster) error {
if in.Type != UpstreamTypeKube {
return nil
}
// decode does validation for us
if _, err := DecodeUpstreamSpec(in.Spec); err != nil {
return errors.Wrap(err, "invalid kubernetes upstream spec")
}
// just configure the cluster to use EDS:ADS and call it a day
out.Type = envoyapi.Cluster_EDS
out.EdsClusterConfig = &envoyapi.Cluster_EdsClusterConfig{
EdsConfig: &envoycore.ConfigSource{
ConfigSourceSpecifier: &envoycore.ConfigSource_Ads{
Ads: &envoycore.AggregatedConfigSource{},
},
},
}
return nil
}