mirror of https://github.com/status-im/consul.git
NET-6663 Modify sidecarproxy controller to skip xGateway resources (#19902)
* NET-6663 Modify sidecarproxy controller to skip xGateway resources * Check workload metadata after nil-check for workload * Add test asserting that workloads with meta gateway-kind are ignored * Use more common pattern for map access to increase readability
This commit is contained in:
parent
de86ba76ee
commit
010bf533d1
|
@ -122,6 +122,7 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c
|
||||||
rt.Logger.Error("error reading the associated workload", "error", err)
|
rt.Logger.Error("error reading the associated workload", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if workload == nil {
|
if workload == nil {
|
||||||
// If workload has been deleted, then return as ProxyStateTemplate should be cleaned up
|
// If workload has been deleted, then return as ProxyStateTemplate should be cleaned up
|
||||||
// by the garbage collector because of the owner reference.
|
// by the garbage collector because of the owner reference.
|
||||||
|
@ -129,6 +130,12 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the workload is for a xGateway, then do nothing + let the gatewayproxy controller reconcile it
|
||||||
|
if gatewayKind, ok := workload.Metadata["gateway-kind"]; ok && gatewayKind != "" {
|
||||||
|
rt.Logger.Trace("workload is a gateway; skipping reconciliation", "workload", workloadID, "gateway-kind", gatewayKind)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
proxyStateTemplate, err := dataFetcher.FetchProxyStateTemplate(ctx, req.ID)
|
proxyStateTemplate, err := dataFetcher.FetchProxyStateTemplate(ctx, req.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rt.Logger.Error("error reading proxy state template", "error", err)
|
rt.Logger.Error("error reading proxy state template", "error", err)
|
||||||
|
|
|
@ -454,6 +454,38 @@ func (suite *controllerTestSuite) TestReconcile_NoWorkload() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *controllerTestSuite) TestReconcile_GatewayWorkload() {
|
||||||
|
suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) {
|
||||||
|
// This test ensures that gateway workloads are ignored by the controller.
|
||||||
|
|
||||||
|
gatewayWorkload := &pbcatalog.Workload{
|
||||||
|
Addresses: []*pbcatalog.WorkloadAddress{
|
||||||
|
{
|
||||||
|
Host: "10.0.0.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Identity: "mesh-gateway-identity",
|
||||||
|
Ports: map[string]*pbcatalog.WorkloadPort{
|
||||||
|
"mesh": {Port: 20000, Protocol: pbcatalog.Protocol_PROTOCOL_MESH},
|
||||||
|
"tcp": {Port: 8080, Protocol: pbcatalog.Protocol_PROTOCOL_TCP},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resourcetest.Resource(pbcatalog.WorkloadType, "test-gateway-workload").
|
||||||
|
WithData(suite.T(), gatewayWorkload).
|
||||||
|
WithTenancy(tenancy).
|
||||||
|
WithMeta("gateway-kind", "mesh-gateway").
|
||||||
|
Write(suite.T(), suite.client.ResourceServiceClient)
|
||||||
|
|
||||||
|
err := suite.ctl.Reconcile(context.Background(), suite.runtime, controller.Request{
|
||||||
|
ID: resourceID(pbmesh.ProxyStateTemplateType, "test-gateway-workload", tenancy),
|
||||||
|
})
|
||||||
|
|
||||||
|
require.NoError(suite.T(), err)
|
||||||
|
suite.client.RequireResourceNotFound(suite.T(), resourceID(pbmesh.ProxyStateTemplateType, "test-non-mesh-api-workload", tenancy))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *controllerTestSuite) TestReconcile_NonMeshWorkload() {
|
func (suite *controllerTestSuite) TestReconcile_NonMeshWorkload() {
|
||||||
suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) {
|
suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) {
|
||||||
// This test ensures that non-mesh workloads are ignored by the controller.
|
// This test ensures that non-mesh workloads are ignored by the controller.
|
||||||
|
|
Loading…
Reference in New Issue