/
config.go
65 lines (57 loc) · 2.05 KB
/
config.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
// 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 config
import (
"errors"
"github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/api/v1alpha1/validation"
"github.com/envoyproxy/gateway/internal/logging"
"github.com/envoyproxy/gateway/internal/utils/env"
)
const (
// DefaultNamespace is the default namespace of Envoy Gateway.
DefaultNamespace = "envoy-gateway-system"
// DefaultDNSDomain is the default DNS domain used by k8s services.
DefaultDNSDomain = "cluster.local"
// EnvoyGatewayServiceName is the name of the Envoy Gateway service.
EnvoyGatewayServiceName = "envoy-gateway"
// EnvoyPrefix is the prefix applied to the Envoy ConfigMap, Service, Deployment, and ServiceAccount.
EnvoyPrefix = "envoy"
)
// Server wraps the EnvoyGateway configuration and additional parameters
// used by Envoy Gateway server.
type Server struct {
// EnvoyGateway is the configuration used to startup Envoy Gateway.
EnvoyGateway *v1alpha1.EnvoyGateway
// Namespace is the namespace that Envoy Gateway runs in.
Namespace string
// DNSDomain is the dns domain used by k8s services. Defaults to "cluster.local".
DNSDomain string
// Logger is the logr implementation used by Envoy Gateway.
Logger logging.Logger
}
// New returns a Server with default parameters.
func New() (*Server, error) {
return &Server{
EnvoyGateway: v1alpha1.DefaultEnvoyGateway(),
Namespace: env.Lookup("ENVOY_GATEWAY_NAMESPACE", DefaultNamespace),
DNSDomain: env.Lookup("KUBERNETES_CLUSTER_DOMAIN", DefaultDNSDomain),
// the default logger
Logger: logging.DefaultLogger(v1alpha1.LogLevelInfo),
}, nil
}
// Validate validates a Server config.
func (s *Server) Validate() error {
switch {
case s == nil:
return errors.New("server config is unspecified")
case len(s.Namespace) == 0:
return errors.New("namespace is empty string")
}
if err := validation.ValidateEnvoyGateway(s.EnvoyGateway); err != nil {
return err
}
return nil
}