-
Notifications
You must be signed in to change notification settings - Fork 687
/
snapshot.go
79 lines (70 loc) · 1.97 KB
/
snapshot.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
package entrypoint
import (
"encoding/json"
"fmt"
"log"
amb "github.com/datawire/ambassador/pkg/api/getambassador.io/v2"
"github.com/datawire/ambassador/pkg/kates"
snapshotTypes "github.com/datawire/ambassador/pkg/snapshot/v1"
)
// NewKubernetesSnapshot creates a new, empty set of Ambassador inputs.
func NewKubernetesSnapshot() *snapshotTypes.KubernetesSnapshot {
a := &snapshotTypes.KubernetesSnapshot{}
a.FSSecrets = make(map[snapshotTypes.SecretRef]*kates.Secret)
return a
}
// GetAmbId extracts the AmbassadorId from the kubernetes resource.
func GetAmbId(resource kates.Object) amb.AmbassadorID {
switch r := resource.(type) {
case *amb.Host:
var id amb.AmbassadorID
if r.Spec != nil {
if len(r.Spec.AmbassadorID) > 0 {
id = r.Spec.AmbassadorID
} else {
id = r.Spec.DeprecatedAmbassadorID
}
}
return id
case *amb.Mapping:
return r.Spec.AmbassadorID
case *amb.TCPMapping:
return r.Spec.AmbassadorID
case *amb.Module:
return r.Spec.AmbassadorID
case *amb.TLSContext:
return r.Spec.AmbassadorID
case *amb.AuthService:
return r.Spec.AmbassadorID
case *amb.RateLimitService:
return r.Spec.AmbassadorID
case *amb.LogService:
return r.Spec.AmbassadorID
case *amb.TracingService:
return r.Spec.AmbassadorID
case *amb.DevPortal:
return r.Spec.AmbassadorID
case *amb.ConsulResolver:
return r.Spec.AmbassadorID
case *amb.KubernetesEndpointResolver:
return r.Spec.AmbassadorID
case *amb.KubernetesServiceResolver:
return r.Spec.AmbassadorID
}
ann := resource.GetAnnotations()
idstr, ok := ann["getambassador.io/ambassador-id"]
if ok {
var id amb.AmbassadorID
err := json.Unmarshal([]byte(idstr), &id)
if err != nil {
log.Printf("%s: error parsing ambassador-id '%s'", location(resource), idstr)
} else {
return id
}
}
return amb.AmbassadorID{}
}
func location(obj kates.Object) string {
return fmt.Sprintf("%s %s in namespace %s", obj.GetObjectKind().GroupVersionKind().Kind, obj.GetName(),
obj.GetNamespace())
}