/
platform.go
68 lines (56 loc) · 2.16 KB
/
platform.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
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package platform
import (
core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
)
const (
KubernetesServiceHost = "KUBERNETES_SERVICE_HOST"
)
// Environment provides information for the platform on which the bootstrapping
// is taking place.
type Environment interface {
// Metadata returns a collection of environmental metadata, structured
// as a map for metadata names to values. An example for GCP would be a
// mapping from "gcp_project" to "2344534543". Keys should be prefixed
// by the short name for the platform (example: "gcp_").
Metadata() map[string]string
// Locality returns the run location for the bootstrap transformed from the
// platform-specific representation into the Envoy Locality schema.
Locality() *core.Locality
// Labels returns a collection of labels that exist on the underlying
// instance, structured as a map for label name to values.
Labels() map[string]string
// IsKubernetes determines if running on Kubernetes
IsKubernetes() bool
}
// Unknown provides a default platform environment for cases in which the platform
// on which the bootstrapping is taking place cannot be determined.
type Unknown struct{}
// Metadata returns an empty map.
func (*Unknown) Metadata() map[string]string {
return map[string]string{}
}
// Locality returns an empty core.Locality struct.
func (*Unknown) Locality() *core.Locality {
return &core.Locality{}
}
// Labels returns an empty map.
func (*Unknown) Labels() map[string]string {
return map[string]string{}
}
// IsKubernetes is true to avoid label collisions
func (*Unknown) IsKubernetes() bool {
return true
}