Skip to content

Commit 59c0c54

Browse files
authored
[receiver/vcenter] Destroys ContainerViews in client after use (#34254)
**Description:** <Describe what has changed.> Destroys ContainerViews in client calls after their use. Not sure if necessary, but should be better to do this than not. **Link to tracking Issue:** <Issue number if applicable> NA **Testing:** <Describe what testing was performed and which tests were added.> Unit tests run. Integration tests run. Test against live environment. **Documentation:** <Describe the documentation added.> None needed
1 parent 1f88246 commit 59c0c54

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: vcenterreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Adds destroys to the ContainerViews in the client.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [34254]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: This may not be necessary, but it should be better practice than not.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/vcenterreceiver/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (vc *vcenterClient) Datacenters(ctx context.Context) ([]mo.Datacenter, erro
9191
if err != nil {
9292
return nil, fmt.Errorf("unable to retrieve Datacenters: %w", err)
9393
}
94+
defer func() { _ = v.Destroy(ctx) }()
9495

9596
var datacenters []mo.Datacenter
9697
err = v.Retrieve(ctx, []string{"Datacenter"}, []string{
@@ -109,6 +110,7 @@ func (vc *vcenterClient) Datastores(ctx context.Context, containerMoRef vt.Manag
109110
if err != nil {
110111
return nil, fmt.Errorf("unable to retrieve Datastores: %w", err)
111112
}
113+
defer func() { _ = v.Destroy(ctx) }()
112114

113115
var datastores []mo.Datastore
114116
err = v.Retrieve(ctx, []string{"Datastore"}, []string{
@@ -129,6 +131,7 @@ func (vc *vcenterClient) ComputeResources(ctx context.Context, containerMoRef vt
129131
if err != nil {
130132
return nil, fmt.Errorf("unable to retrieve ComputeResources (& ClusterComputeResources): %w", err)
131133
}
134+
defer func() { _ = v.Destroy(ctx) }()
132135

133136
var computes []mo.ComputeResource
134137
err = v.Retrieve(ctx, []string{"ComputeResource"}, []string{
@@ -150,6 +153,7 @@ func (vc *vcenterClient) HostSystems(ctx context.Context, containerMoRef vt.Mana
150153
if err != nil {
151154
return nil, fmt.Errorf("unable to retrieve HostSystems: %w", err)
152155
}
156+
defer func() { _ = v.Destroy(ctx) }()
153157

154158
var hosts []mo.HostSystem
155159
err = v.Retrieve(ctx, []string{"HostSystem"}, []string{
@@ -177,6 +181,7 @@ func (vc *vcenterClient) ResourcePools(ctx context.Context, containerMoRef vt.Ma
177181
if err != nil {
178182
return nil, fmt.Errorf("unable to retrieve ResourcePools (&VirtualApps): %w", err)
179183
}
184+
defer func() { _ = v.Destroy(ctx) }()
180185

181186
var rps []mo.ResourcePool
182187
err = v.Retrieve(ctx, []string{"ResourcePool"}, []string{
@@ -198,6 +203,7 @@ func (vc *vcenterClient) VMs(ctx context.Context, containerMoRef vt.ManagedObjec
198203
if err != nil {
199204
return nil, fmt.Errorf("unable to retrieve VMs: %w", err)
200205
}
206+
defer func() { _ = v.Destroy(ctx) }()
201207

202208
var vms []mo.VirtualMachine
203209
err = v.Retrieve(ctx, []string{"VirtualMachine"}, []string{

0 commit comments

Comments
 (0)