Skip to content

Commit d918f28

Browse files
committed
PR Feedback
1 parent af392fc commit d918f28

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

internal/resource/resource_plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (r *Resource) Process(ctx context.Context, msg *bus.Message) {
9494

9595
return
9696
}
97-
resource := r.resourceService.UpdateInstances(instanceList)
97+
resource := r.resourceService.UpdateInstances(ctx, instanceList)
9898

9999
r.messagePipe.Process(ctx, &bus.Message{Topic: bus.ResourceUpdateTopic, Data: resource})
100100

@@ -107,7 +107,7 @@ func (r *Resource) Process(ctx context.Context, msg *bus.Message) {
107107

108108
return
109109
}
110-
resource := r.resourceService.DeleteInstances(instanceList)
110+
resource := r.resourceService.DeleteInstances(ctx, instanceList)
111111

112112
r.messagePipe.Process(ctx, &bus.Message{Topic: bus.ResourceUpdateTopic, Data: resource})
113113

internal/resource/resource_service.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const (
4444

4545
type resourceServiceInterface interface {
4646
AddInstances(instanceList []*mpi.Instance) *mpi.Resource
47-
UpdateInstances(instanceList []*mpi.Instance) *mpi.Resource
48-
DeleteInstances(instanceList []*mpi.Instance) *mpi.Resource
47+
UpdateInstances(ctx context.Context, instanceList []*mpi.Instance) *mpi.Resource
48+
DeleteInstances(ctx context.Context, instanceList []*mpi.Instance) *mpi.Resource
4949
ApplyConfig(ctx context.Context, instanceID string) error
5050
Instance(instanceID string) *mpi.Instance
5151
GetHTTPUpstreamServers(ctx context.Context, instance *mpi.Instance, upstreams string) ([]client.UpstreamServer,
@@ -128,7 +128,7 @@ func (r *ResourceService) RemoveOperator(instanceList []*mpi.Instance) {
128128
}
129129
}
130130

131-
func (r *ResourceService) UpdateInstances(instanceList []*mpi.Instance) *mpi.Resource {
131+
func (r *ResourceService) UpdateInstances(ctx context.Context, instanceList []*mpi.Instance) *mpi.Resource {
132132
r.resourceMutex.Lock()
133133
defer r.resourceMutex.Unlock()
134134

@@ -144,14 +144,15 @@ func (r *ResourceService) UpdateInstances(instanceList []*mpi.Instance) *mpi.Res
144144
}
145145
r.resource = resourceCopy
146146
} else {
147-
slog.Warn("Error updating resource instances", "instances", instanceList)
147+
slog.WarnContext(ctx, "Unable to clone resource while updating instances", "resource",
148+
r.resource, "instances", instanceList)
148149
}
149150
}
150151

151152
return r.resource
152153
}
153154

154-
func (r *ResourceService) DeleteInstances(instanceList []*mpi.Instance) *mpi.Resource {
155+
func (r *ResourceService) DeleteInstances(ctx context.Context, instanceList []*mpi.Instance) *mpi.Resource {
155156
r.resourceMutex.Lock()
156157
defer r.resourceMutex.Unlock()
157158

@@ -164,7 +165,8 @@ func (r *ResourceService) DeleteInstances(instanceList []*mpi.Instance) *mpi.Res
164165
}
165166
}
166167
} else {
167-
slog.Warn("Error deleting instances from resource", "instances", instanceList)
168+
slog.WarnContext(ctx, "Unable to clone resource while deleting instances", "resource",
169+
r.resource, "instances", instanceList)
168170
}
169171
}
170172
r.RemoveOperator(instanceList)

internal/resource/resource_service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestResourceService_UpdateInstance(t *testing.T) {
104104
t.Run(test.name, func(tt *testing.T) {
105105
resourceService := NewResourceService(ctx, types.AgentConfig())
106106
resourceService.resource.Instances = []*v1.Instance{protos.GetNginxOssInstance([]string{})}
107-
resource := resourceService.UpdateInstances(test.instanceList)
107+
resource := resourceService.UpdateInstances(ctx, test.instanceList)
108108
assert.Equal(tt, test.resource.GetInstances(), resource.GetInstances())
109109
})
110110
}
@@ -141,7 +141,7 @@ func TestResourceService_DeleteInstance(t *testing.T) {
141141
protos.GetNginxOssInstance([]string{}),
142142
protos.GetNginxPlusInstance([]string{}),
143143
}
144-
resource := resourceService.DeleteInstances(test.instanceList)
144+
resource := resourceService.DeleteInstances(ctx, test.instanceList)
145145
assert.Equal(tt, test.resource.GetInstances(), resource.GetInstances())
146146
})
147147
}

internal/resource/resourcefakes/fake_resource_service_interface.go

Lines changed: 32 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)