-
Notifications
You must be signed in to change notification settings - Fork 85
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 custom groups support to upgrade run resource #1191
Conversation
55d6452
to
67fdfd9
Compare
Optional: true, | ||
Default: true, | ||
}, | ||
"extended_configuration": { |
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 we can reuse schema for key/value pairs, we already have a func getSwitchingProfileIdsSchema
, we might want to rename it and generalize the description. Also advanced_configuration
of edge transport node might benefit from this
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.
Switching profile uses a different schema than edge transport node and upgrade - SwitchingProfileTypeIdEntry vs KeyValuePair.
I'll consolidate edge and upgrade and leave switching profiles as is.
return fmt.Errorf("host %s already exists in group %s", hostID, groupID) | ||
} | ||
group.UpgradeUnits = append(group.UpgradeUnits, model.UpgradeUnit{Id: &hostID}) | ||
_, err = client.Update(groupID, group) |
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 feel simultaneous updates might cause errors here, so we might need to wrap this code (including Get
) in retry. Auto-retry that we have today will not re-read the revision, so Update would fail again if revision got updated. What do you think?
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.
Makes a lot of sense. Do we have any example for such retry mechanism in the code?
BTW it seems like the _revision
attribute is ignored by NSX - I'll open a bug for this.
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 that I've found something.
af8f4a4
to
b9f3123
Compare
/test-all |
1 similar comment
/test-all |
8aeb442
to
f57ef48
Compare
/test-all |
/test-all |
/test-all |
nsxt/resource_nsxt_upgrade_run.go
Outdated
return fmt.Errorf("couldn't find upgrade unit group without id or display_name") | ||
} | ||
// This is a custom group, try to find it by name | ||
groupList, err := upgradeClientSet.GroupClient.List(nil, nil, nil, nil, nil, nil, nil, 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.
is pagination relevant here?
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.
Do we expect more than 1000 groups?
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.
Doesn't sound feasible, but maybe a comment about it would be helpful
var err error | ||
isCreate := false | ||
if groupID == "" { | ||
groupName := group["display_name"].(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.
can the user change display_name
for existing group?
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.
No - this isn't doable as the display_name is used to identify a pre-existing custom group, and as the upgrade support doesn't maintain/support state.
If the upgrade implementation would support state, we could identify the group by id and update the group.
nsxt/resource_nsxt_upgrade_run.go
Outdated
} else if err != nil { | ||
return handleDeleteError("Host Upgrade Group Binding", nsxUnit, err) | ||
} | ||
return addHostToGroup(m, groupID, nsxUnit, false) |
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.
Is the return
here intentional?
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's a bug...
nsxt/resource_nsxt_upgrade_run.go
Outdated
|
||
hostIDs := getUnitIDsFromUnits(group.UpgradeUnits) | ||
if slices.Contains(hostIDs, hostID) { | ||
return fmt.Errorf("host %s already exists in group %s", hostID, groupID) |
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 we swallow this error?
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.
Indeed, thanks
nsxt/resource_nsxt_upgrade_run.go
Outdated
// it should be assigned to the 'Group 1 for ESXI' group (this value is hardcoded in NSX) | ||
groupClient := upgrade.NewUpgradeUnitGroupsClient(connector) | ||
componentType := "HOST" | ||
hostGroups, err := groupClient.List(&componentType, nil, nil, nil, nil, nil, nil, 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.
It seems wasteful to run this API for each getHostDefaultUpgradeGroup
call, can the logic be change to run it once? We only care for default groups here, and default groups are not expected to change throughout the update operation, is that correct?
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.
You mean, load the entire host/group map and cache it for the entire execution?
As the "original" upgrade group for each host could be different according to cluster membership (or lack of cluster association).
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.
Yes, only run the API once and use the list for all calls of this function
I didn't see any update in |
Yeah I missed this. Although as we do not support the state existence, that's a bit meaningless for now. |
But this is only the status type - which doesn't have the extra group attributes. So I'm not sure that a change is required here. |
I think that although we ask to remove state post-upgrade, |
LGTM, except for two doubts:
|
@@ -503,9 +523,83 @@ func updateUpgradeUnitGroups(upgradeClientSet *upgradeClientSet, d *schema.Resou | |||
for _, groupI := range d.Get(componentToGroupKey[component]).([]interface{}) { |
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.
Looks like the code doesn't delete custom groups that were created with previous apply (which might have failed) but are not present in current config, is that correct?
To solve this, d.GetChange("host_group")
might be useful
Add the logic to create and update custom host groups while running the upgrade process. Signed-off-by: Kobi Samoray <[email protected]>
Signed-off-by: Kobi Samoray <[email protected]>
Terraform doesn't show an empty diff, also without these changes as far as I understand (there are dependencies on computed groups within the upgrade process - I think that this is the reason?). |
I would suggest to rely on |
91ff29b
to
f71f3d6
Compare
When a host upgrade group is deleted, clean it from NSX. Signed-off-by: Kobi Samoray <[email protected]>
/test-all |
Add the logic to create and update custom host groups while running the upgrade process.