Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-6663 Modify sidecarproxy controller to skip xGateway resources #19902

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,20 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c
rt.Logger.Error("error reading the associated workload", "error", err)
return err
}

if workload == nil {
// If workload has been deleted, then return as ProxyStateTemplate should be cleaned up
// by the garbage collector because of the owner reference.
rt.Logger.Trace("workload doesn't exist; skipping reconciliation", "workload", workloadID)
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)
if err != nil {
rt.Logger.Error("error reading proxy state template", "error", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) {
// This test ensures that non-mesh workloads are ignored by the controller.
Expand Down