@@ -13,32 +13,41 @@ import (
13
13
"github.com/hashicorp/consul/internal/controller/dependency"
14
14
"github.com/hashicorp/consul/internal/mesh/internal/controllers/gatewayproxy/builder"
15
15
"github.com/hashicorp/consul/internal/mesh/internal/controllers/gatewayproxy/fetcher"
16
+ "github.com/hashicorp/consul/internal/mesh/internal/controllers/sidecarproxy"
16
17
"github.com/hashicorp/consul/internal/mesh/internal/controllers/sidecarproxy/cache"
18
+ "github.com/hashicorp/consul/internal/mesh/internal/types"
17
19
"github.com/hashicorp/consul/internal/resource"
18
20
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
19
21
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1"
22
+ pbmulticluster "github.com/hashicorp/consul/proto-public/pbmulticluster/v2beta1"
20
23
"github.com/hashicorp/consul/proto-public/pbresource"
21
24
)
22
25
23
26
// ControllerName is the name for this controller. It's used for logging or status keys.
24
- const ControllerName = "consul.io/gateway-proxy-controller "
27
+ const ControllerName = "consul.io/gateway-proxy"
25
28
26
29
// Controller is responsible for triggering reconciler for watched resources
27
- func Controller (cache * cache.Cache ) * controller.Controller {
30
+ func Controller (cache * cache.Cache , trustDomainFetcher sidecarproxy. TrustDomainFetcher , dc string , defaultAllow bool ) * controller.Controller {
28
31
// TODO NET-7016 Use caching functionality in NewController being implemented at time of writing
29
32
// TODO NET-7017 Add the host of other types we should watch
30
33
return controller .NewController (ControllerName , pbmesh .ProxyStateTemplateType ).
31
34
WithWatch (pbcatalog .WorkloadType , dependency .ReplaceType (pbmesh .ProxyStateTemplateType )).
32
35
WithWatch (pbmesh .ComputedProxyConfigurationType , dependency .ReplaceType (pbmesh .ProxyStateTemplateType )).
33
36
WithReconciler (& reconciler {
34
- cache : cache ,
37
+ cache : cache ,
38
+ dc : dc ,
39
+ defaultAllow : defaultAllow ,
40
+ getTrustDomain : trustDomainFetcher ,
35
41
})
36
42
}
37
43
38
44
// reconciler is responsible for managing the ProxyStateTemplate for all
39
45
// gateway types: mesh, api (future) and terminating (future).
40
46
type reconciler struct {
41
- cache * cache.Cache
47
+ cache * cache.Cache
48
+ dc string
49
+ defaultAllow bool
50
+ getTrustDomain sidecarproxy.TrustDomainFetcher
42
51
}
43
52
44
53
// Reconcile is responsible for creating and updating the pbmesh.ProxyStateTemplate
@@ -60,9 +69,8 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c
60
69
}
61
70
62
71
if workload == nil {
63
- // If workload has been deleted, then return as ProxyStateTemplate should be cleaned up
64
- // by the garbage collector because of the owner reference.
65
72
rt .Logger .Trace ("workload doesn't exist; skipping reconciliation" , "workload" , workloadID )
73
+ // Workload no longer exists, let garbage collector clean up
66
74
return nil
67
75
}
68
76
@@ -104,7 +112,27 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c
104
112
rt .Logger .Trace ("proxy state template for this gateway doesn't yet exist; generating a new one" )
105
113
}
106
114
107
- newPST := builder .NewProxyStateTemplateBuilder (workload ).Build ()
115
+ exportedServicesID := & pbresource.ID {
116
+ Name : "global" ,
117
+ Tenancy : & pbresource.Tenancy {
118
+ Partition : req .ID .Tenancy .Partition ,
119
+ },
120
+ Type : pbmulticluster .ExportedServicesType ,
121
+ }
122
+
123
+ exportedServices , err := dataFetcher .FetchExportedServices (ctx , exportedServicesID )
124
+ if err != nil {
125
+ rt .Logger .Error ("error reading the associated exported services" , "error" , err )
126
+ exportedServices = & types.DecodedComputedExportedServices {}
127
+ }
128
+
129
+ trustDomain , err := r .getTrustDomain ()
130
+ if err != nil {
131
+ rt .Logger .Error ("error fetching trust domain to compute proxy state template" , "error" , err )
132
+ return err
133
+ }
134
+
135
+ newPST := builder .NewProxyStateTemplateBuilder (workload , exportedServices , rt .Logger , dataFetcher , r .dc , trustDomain ).Build ()
108
136
109
137
proxyTemplateData , err := anypb .New (newPST )
110
138
if err != nil {
0 commit comments