Skip to content

Commit

Permalink
fix(tenantop): supplement type of modifying resource pools
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Sep 3, 2024
1 parent 9a22682 commit 2162374
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/constants/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
TenantOpSetConnectWhiteList types.TenantOperationType = "SET_CONNECT_WHITE_LIST"
TenantOpAddResourcePools types.TenantOperationType = "ADD_RESOURCE_POOLS"
TenantOpDeleteResourcePools types.TenantOperationType = "DELETE_RESOURCE_POOLS"
TenantOpModifyResourcePools types.TenantOperationType = "MODIFY_RESOURCE_POOLS"
TenantOpSetCharset types.TenantOperationType = "SET_CHARSET"
TenantOpSetForceDelete types.TenantOperationType = "SET_FORCE_DELETE"
)
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/obtenantoperation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type OBTenantOperationSpec struct {
UnitNumber int `json:"unitNumber,omitempty"`
ConnectWhiteList string `json:"connectWhiteList,omitempty"`
Charset string `json:"charset,omitempty"`
ModifyResourcePools []ResourcePoolSpec `json:"modifyResourcePools,omitempty"`
AddResourcePools []ResourcePoolSpec `json:"addResourcePools,omitempty"`
DeleteResourcePools []string `json:"deleteResourcePools,omitempty"`
ForceDelete *bool `json:"forceDelete,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions api/v1alpha1/obtenantoperation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,20 @@ func (r *OBTenantOperation) validateMutation() error {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("addResourcePools"), r.Spec.AddResourcePools, "The resource pool does not exist in the cluster"))
}
}
case constants.TenantOpModifyResourcePools:
if len(r.Spec.ModifyResourcePools) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("modifyResourcePools"), "modifyResourcePools is required"))
break
}
pools := make(map[string]any)
for _, pool := range obtenant.Spec.Pools {
pools[pool.Zone] = struct{}{}
}
for _, pool := range r.Spec.ModifyResourcePools {
if _, ok := pools[pool.Zone]; !ok {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("modifyResourcePools"), r.Spec.ModifyResourcePools, "The resource pool does not exist"))
}
}
case constants.TenantOpDeleteResourcePools:
if len(r.Spec.DeleteResourcePools) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("deleteResourcePools"), "deleteResourcePools is required"))
Expand Down
11 changes: 11 additions & 0 deletions internal/resource/obtenantoperation/obtenantoperation_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ func UpdateOBTenantResource(m *ObTenantOperationManager) tasktypes.TaskError {
for _, pool := range m.Resource.Spec.AddResourcePools {
obtenant.Spec.Pools = append(obtenant.Spec.Pools, pool)
}
case constants.TenantOpModifyResourcePools:
modifiedPools := make(map[string]*v1alpha1.ResourcePoolSpec)
for _, pool := range m.Resource.Spec.ModifyResourcePools {
modifiedPools[pool.Zone] = &pool

Check warning on line 375 in internal/resource/obtenantoperation/obtenantoperation_task.go

View workflow job for this annotation

GitHub Actions / lint

range-val-address: suspicious assignment of 'pool'. range-loop variables always have the same address (revive)
}
for i := range obtenant.Spec.Pools {
pool := obtenant.Spec.Pools[i]
if modified, ok := modifiedPools[pool.Zone]; ok {
obtenant.Spec.Pools[i] = *modified
}
}
case constants.TenantOpDeleteResourcePools:
deletedPools := make(map[string]any)
for _, pool := range m.Resource.Spec.DeleteResourcePools {
Expand Down

0 comments on commit 2162374

Please sign in to comment.