-
Notifications
You must be signed in to change notification settings - Fork 363
/
runner.go
60 lines (51 loc) · 1.56 KB
/
runner.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
// 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 runner
import (
"context"
"fmt"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/message"
"github.com/envoyproxy/gateway/internal/provider/kubernetes"
)
type Config struct {
config.Server
ProviderResources *message.ProviderResources
}
type Runner struct {
Config
}
func New(cfg *Config) *Runner {
return &Runner{Config: *cfg}
}
func (r *Runner) Name() string {
return string(v1alpha1.LogComponentProviderRunner)
}
// Start the provider runner
func (r *Runner) Start(ctx context.Context) (err error) {
r.Logger = r.Logger.WithName(r.Name()).WithValues("runner", r.Name())
if r.EnvoyGateway.Provider.Type == v1alpha1.ProviderTypeKubernetes {
r.Logger.Info("Using provider", "type", v1alpha1.ProviderTypeKubernetes)
cfg, err := ctrl.GetConfig()
if err != nil {
return fmt.Errorf("failed to get kubeconfig: %w", err)
}
p, err := kubernetes.New(cfg, &r.Config.Server, r.ProviderResources)
if err != nil {
return fmt.Errorf("failed to create provider %s: %w", v1alpha1.ProviderTypeKubernetes, err)
}
go func() {
err := p.Start(ctx)
if err != nil {
r.Logger.Error(err, "unable to start provider")
}
}()
return nil
}
// Unsupported provider.
return fmt.Errorf("unsupported provider type %v", r.EnvoyGateway.Provider.Type)
}