-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix: missing vds info with r/cluster
import
#235
base: main
Are you sure you want to change the base?
fix: missing vds info with r/cluster
import
#235
Conversation
r/cluster
import
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.
The CI caught that the err
is assigned but not used.
getFlattenedVdsSpecsForRefs
returns both a slice of maps and an error. So the err
is necessary to handle potential errors from the apiClient.Clusters.GetVdses
.
here is what the results are now:
|
f364358
to
e3d8f78
Compare
r/cluster
importr/cluster
import
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.
@burnsjared0415 could you address the following issues failing during the linkting?
Error: internal/cluster/cluster_operations.go:376:21: ineffectual assignment to err (ineffassign)
flattenedVdsSpecs, err := getFlattenedVdsSpecsForRefs(ctx, clusterObj.ID, apiClient)
^
Error: internal/cluster/cluster_operations.go:406:21: ineffectual assignment to err (ineffassign)
flattenedVdsSpecs, err := getFlattenedVdsSpecsForRefs(ctx, clusterId, apiClient)
e3d8f78
to
f09fef2
Compare
Rebased based on the changes to main recently. Will need updates given the SDK changes. |
f09fef2
to
06e4980
Compare
Updating Cluster import to solve issues where vds is blank on data source. Signed-off-by: Jared Burns <jared.burns@broadcom.com>
06e4980
to
2963fc2
Compare
if vdsResponse.JSON200 == nil { | ||
return nil, fmt.Errorf("vdsResponse.JSON200 is nil") | ||
} | ||
|
||
flattenedVdsSpecs := make([]map[string]interface{}, len(*vdsResponse.JSON200)) | ||
for i, vds := range *vdsResponse.JSON200 { | ||
portGroups := vds.PortGroups | ||
portGroupSpecs := make([]vcf.PortgroupSpec, len(*portGroups)) | ||
for j, pg := range *portGroups { | ||
portGroupSpecs[j] = vcf.PortgroupSpec{ | ||
Name: pg.Name, | ||
TransportType: pg.TransportType, | ||
ActiveUplinks: pg.ActiveUplinks, | ||
} | ||
} |
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.
@spacegospod - I recall we made some changes to avoid using JSON200 when we bumped to v0.4.1 of the SDK. Can you suggest an update for this section?
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.
Sure thing, what you need is GetResponseAs[YourType](RawResponse)
For reference https://github.com/vmware/terraform-provider-vcf/blob/main/internal/api_client/sddc_manager_client.go#L137
if vdsResponse.JSON200 == nil { | |
return nil, fmt.Errorf("vdsResponse.JSON200 is nil") | |
} | |
flattenedVdsSpecs := make([]map[string]interface{}, len(*vdsResponse.JSON200)) | |
for i, vds := range *vdsResponse.JSON200 { | |
portGroups := vds.PortGroups | |
portGroupSpecs := make([]vcf.PortgroupSpec, len(*portGroups)) | |
for j, pg := range *portGroups { | |
portGroupSpecs[j] = vcf.PortgroupSpec{ | |
Name: pg.Name, | |
TransportType: pg.TransportType, | |
ActiveUplinks: pg.ActiveUplinks, | |
} | |
} | |
switches, vcfErr := api_client.GetResponseAs[whatever type vdsResponse.JSON200 is](vdsResponse) | |
if vcfErr != nil { | |
api_client.LogError(vcfErr) | |
return errors.New(*vcfErr.Message) | |
} | |
... | |
// continue processing `switches` | |
... |
What GetResponseAs does is it checks the response code and parses the raw response body (a byte array) into whatever generic type you provide (if the request is successful) or into vcf.Error (if the request has failed)
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.
@burnsjared0415 - the following should work:
func getFlattenedVdsSpecsForRefs(ctx context.Context, clusterId string, apiClient *vcf.ClientWithResponses) ([]map[string]interface{}, error) {
res, err := apiClient.GetVdsesWithResponse(ctx, clusterId)
if err != nil {
return nil, err
}
switcheObj, vcfErr := api_client.GetResponseAs[[]vcf.Vds](res)
if vcfErr != nil {
api_client.LogError(vcfErr)
return nil, errors.New(*vcfErr.Message)
}
flattenedVdsSpecs := make([]map[string]interface{}, len(*switcheObj))
for i, vds := range *switcheObj {
portGroups := vds.PortGroups
portGroupSpecs := make([]vcf.PortgroupSpec, len(*portGroups))
for j, pg := range *portGroups {
portGroupSpecs[j] = vcf.PortgroupSpec{
Name: pg.Name,
TransportType: pg.TransportType,
ActiveUplinks: pg.ActiveUplinks,
}
}
niocBandwidthAllocations := vds.NiocBandwidthAllocations
niocSpecs := make([]vcf.NiocBandwidthAllocationSpec, len(*niocBandwidthAllocations))
for k, nioc := range *niocBandwidthAllocations {
niocType := ""
if nioc.Type != nil {
niocType = *nioc.Type
}
niocSpecs[k] = vcf.NiocBandwidthAllocationSpec{
Type: niocType,
NiocTrafficResourceAllocation: vcf.NiocTrafficResourceAllocation{
SharesInfo: &vcf.SharesInfo{
Shares: nioc.NiocTrafficResourceAllocation.SharesInfo.Shares,
Level: nioc.NiocTrafficResourceAllocation.SharesInfo.Level,
},
},
}
}
vdsSpec := vcf.VdsSpec{
Name: vds.Name,
IsUsedByNsxt: vds.IsUsedByNsxt,
PortGroupSpecs: &portGroupSpecs,
NiocBandwidthAllocationSpecs: &niocSpecs,
}
flattenedVdsSpecs[i] = network.FlattenVdsSpec(&vdsSpec)
}
return flattenedVdsSpecs, nil
}
In order to have a good experience with our community, we recommend that you read the contributing guidelines for making a pull request.
Summary of Pull Request
Updating Cluster import to solve issues where vds is blank on data source.
Type of Pull Request
Please describe:
Related to Existing Issues
Closes #210
Test and Documentation Coverage
For bug fixes or features:
Breaking Changes?