-
Notifications
You must be signed in to change notification settings - Fork 296
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
Add ability to assign tags to virtual machines #1014
Conversation
Hi @alexander-demichev. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
pkg/services/govmomi/create_test.go
Outdated
@@ -38,6 +40,7 @@ func TestCreate(t *testing.T) { | |||
t.Fatal(err) | |||
} | |||
model.Service.TLS = new(tls.Config) | |||
model.Service.RegisterEndpoints = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line and _ "github.com/vmware/govmomi/vapi/simulator"
are needed to make simulator register rest session endpoint or it returns an error - unable to create rest client: POST https://127.0.0.1:63223/rest/com/vmware/cis/session: 404 Not Found
/ok-to-test |
@alexander-demichev - we're planning to cut v0.7.1 today, let's review this, merge it and cut a release once it's ready |
Need to add the conversion webhooks for the tests to pass. |
29638ff
to
48bfb68
Compare
@alexander-demichev : I think these tags have to pre-exist in vCenter. Is there a way to dynamically create/delete them with VMs? |
@alexander-demichev would you be able to elaborate on your use case here? I recognize that other infra providers such as CAPA allow this, but you may want to read https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/techpaper/performance/tagging-vsphere67-perf.pdf about tag performance in larger configurations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review the tests yet, I'll do another pass monday
pkg/services/govmomi/service.go
Outdated
@@ -41,7 +42,9 @@ import ( | |||
) | |||
|
|||
// VMService provdes API to interact with the VMs using govmomi | |||
type VMService struct{} | |||
type VMService struct { | |||
Tags []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
pkg/services/govmomi/service.go
Outdated
@@ -273,6 +281,18 @@ func (vms *VMService) reconcilePowerState(ctx *virtualMachineContext) (bool, err | |||
} | |||
} | |||
|
|||
func (vms *VMService) reconcileTags(ctx *virtualMachineContext) error { | |||
tagManager := tags.NewManager(ctx.Session.RestClient) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this blank line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another pass for the API
api/v1alpha3/vspheremachine_types.go
Outdated
|
||
// Tags is an optional set of tags to add to an instance. | ||
// +optional | ||
Tags []string `json:"tags,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put these in the VirtualMachineCloneSpec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make the tag category explicit also ? (this would enable key:value use cases)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yastij Do you have an example of how to attach a tag from a specific category?
@alexander-demichev - the scalability concerns pointed by @ncdc are standing. what is the use case we want to cover and at what scale ? |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
i also have a few use cases for this. having the tags would greatly enhance the ability for extensibility using the VMware Ecosystem tools. the use cases i have seen for this so far are:
regarding the performance issues, while this is something to take into consideration, 25k tag assignments with good performance as mentioned in the article seems quite reasonable. many systems add tags in vSphere and the performance issue i dont think should be a blocker here either. just as maybe the user doesnt have enough resources isnt a blocker for automated deployments. |
Not sure about the initial use case here from reading the PR, but I'd suggest to use an async/throttled out-of-band (ie decoupled) mechanism based on vSphere events for this if possible, eg using the event broker or similar. It helps with separation of concerns (access permissions to VC), scalability concerns, network issues and making the controller logic less vulnerable to reconciliation/blocking issues due to heavy VC RPCs. We've seen users successfully adopting this model for tag management (beyond K8s controllers) and it works nicely (orthogonal) with the async reconciliation pattern in K8s controllers. |
@vrabbi - I agree that we should have this. @alexander-demichev can you address the comments and rebase ? |
@yastij yes, I'll try to find time this week |
48bfb68
to
e391ca1
Compare
Summarizing what's left to be done for the PR:
@alexander-demichev apologies for the long delay with this PR. Is this still something you're interested in contributing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be explicit we are dealing with Tag IDs and not Tag Names
@@ -514,6 +514,11 @@ spec: | |||
a linked clone. This field is ignored if LinkedClone is not enabled. | |||
Defaults to the source's current snapshot. | |||
type: string | |||
tags: | |||
description: Tags is an optional set of tags to add to an instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "Tags is an optional set of tag IDs to add to an instance."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: Tags is an optional set of tags to add to an instance. | |
description: Tags is an optional set of tag IDs to add to an instance. |
@@ -574,6 +574,12 @@ spec: | |||
to create a linked clone. This field is ignored if LinkedClone | |||
is not enabled. Defaults to the source's current snapshot. | |||
type: string | |||
tags: | |||
description: Tags is an optional set of tags to add to an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "Tags is an optional set of tag IDs to add to an instance"
@@ -272,6 +272,11 @@ spec: | |||
a linked clone. This field is ignored if LinkedClone is not enabled. | |||
Defaults to the source's current snapshot. | |||
type: string | |||
tags: | |||
description: Tags is an optional set of tags to add to an instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "Tags is an optional set of tag IDs to add to an instance."
e391ca1
to
9081de6
Compare
Hi all, I updated the PR:
I'm having an issue with generating conversions, it's failing with the following error: |
@@ -140,6 +140,10 @@ func (vms *VMService) ReconcileVM(ctx *context.VMContext) (vm infrav1.VirtualMac | |||
return vm, err | |||
} | |||
|
|||
if err := vms.reconcileTags(vmCtx); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think error handling could be slightly improved here instead of reconciling (potentially forever) on any error, including unrecoverable errors.
To quote from the docs:
AttachMultipleTagsToObject attaches multiple tag IDs to a managed object. This operation is idempotent. If a tag is already attached to the object, then the individual operation is a no-op and no error will be thrown. This operation is not atomic. If the underlying call fails with one or more tags not successfully attached to the managed object reference it might leave the managed object reference in a partially tagged state and needs to be resolved by the caller. In this case BatchErrors is returned and can be used to analyse failure reasons on each failed tag. Specified tagIDs must use URN-notation instead of display names or a generic error will be returned and no tagging operation will be performed. If the managed object reference does not exist a generic 403 Forbidden error will be returned. This operation was added in vSphere API 6.5.
We are working on improved error type handling (for assertions) but the above should give you an impression of different error scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that there are no typed errors at the moment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only partially ([]BatchError
) and the situation is improving as we export more errors. Please see the tests for the method which shows common error scenarios and the errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, we don't distinguish between terminal and intermittent errors and we don't need to tackle that in this PR. What could be useful here is setting a condition on the VSphereMachine for reconciling tags. Right now if there is an error, nothing will show on the VSphereMachine to help the user debug further.
a8ec17d
to
7a2d727
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the changes. tested it out locally and it works. It's a slight nuisance to have to use the tag URNs instead of just the name but that's an API limitation.
@@ -0,0 +1,24 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I ran a make generate
there is a new function in the generated conversion file. Should add that in. This file/function is still needed as it requires us to do the manual conversion.
@@ -140,6 +140,10 @@ func (vms *VMService) ReconcileVM(ctx *context.VMContext) (vm infrav1.VirtualMac | |||
return vm, err | |||
} | |||
|
|||
if err := vms.reconcileTags(vmCtx); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, we don't distinguish between terminal and intermittent errors and we don't need to tackle that in this PR. What could be useful here is setting a condition on the VSphereMachine for reconciling tags. Right now if there is an error, nothing will show on the VSphereMachine to help the user debug further.
@alexander-demichev - pending @gab-satchi's comment on adding a condition, this looks good. Once we merge the v1beta1 types could you rebase your PR ? this way it can make it into the new release |
7a2d727
to
8f12a79
Compare
@yastij Hi, I rebased the PR and added a condition |
8f12a79
to
e3692e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: yastij The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
thanks for the changes /lgtm |
What this PR does / why we need it:
Add the ability to assign tags to virtual machines, similar to what is done in AWS. In order to do so, we need to have
Tags
field inVSphereMachineTemplate
and create REST client. This change assumes that tags are already created by the user.Release note:
-->