-
Notifications
You must be signed in to change notification settings - Fork 683
/
snapshot.go
78 lines (69 loc) · 2.01 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
package entrypoint
import (
"context"
"encoding/json"
"fmt"
"github.com/datawire/dlib/dlog"
amb "github.com/emissary-ingress/emissary/v3/pkg/api/getambassador.io/v3alpha1"
"github.com/emissary-ingress/emissary/v3/pkg/kates"
snapshotTypes "github.com/emissary-ingress/emissary/v3/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(ctx context.Context, 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
}
}
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 {
dlog.Errorf(ctx, "%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())
}