Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

burnsjared0415
Copy link
Contributor

@burnsjared0415 burnsjared0415 commented Aug 22, 2024

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

  • This is a bug fix.
  • This is an enhancement or feature.
  • This is a code style/formatting update.
  • This is a documentation update.
  • This is a refactoring update.
  • This is a chore update
  • This is something else.
    Please describe:

Related to Existing Issues

Closes #210

Test and Documentation Coverage

For bug fixes or features:

  • Tests have been completed.
  • Documentation has been added/updated.

Breaking Changes?

  • Yes, there are breaking changes.
  • No, there are no breaking changes.

@github-actions github-actions bot added needs-review Needs Review provider Provider labels Aug 22, 2024
@burnsjared0415 burnsjared0415 changed the title fix: missing vds info with r/cluster import 🚧fix: missing vds info with r/cluster import Aug 22, 2024
@tenthirtyam tenthirtyam changed the title 🚧fix: missing vds info with r/cluster import 🚧 fix: missing vds info with r/cluster import Aug 22, 2024
@tenthirtyam tenthirtyam added bug Bug and removed needs-review Needs Review labels Aug 22, 2024
@tenthirtyam tenthirtyam added this to the On Deck milestone Aug 22, 2024
@github-actions github-actions bot added the needs-review Needs Review label Aug 22, 2024
@tenthirtyam tenthirtyam removed the needs-review Needs Review label Aug 22, 2024
Copy link
Collaborator

@tenthirtyam tenthirtyam left a 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.

@tenthirtyam tenthirtyam linked an issue Aug 23, 2024 that may be closed by this pull request
4 tasks
@github-actions github-actions bot added the needs-review Needs Review label Aug 23, 2024
@tenthirtyam tenthirtyam modified the milestones: On Deck, v0.11.0 Aug 23, 2024
@burnsjared0415
Copy link
Contributor Author

here is what the results are now:

 "is_used_by_nsx": true,
                "name": "xxx-vds01",
                "nioc_bandwidth_allocations": [
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 100,
                    "shares_level": "high",
                    "type": "vsan"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 25,
                    "shares_level": "low",
                    "type": "vmotion"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 25,
                    "shares_level": "low",
                    "type": "vdp"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 25,
                    "shares_level": "low",
                    "type": "nfs"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 25,
                    "shares_level": "low",
                    "type": "hbr"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 25,
                    "shares_level": "low",
                    "type": "iSCSI"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 100,
                    "shares_level": "high",
                    "type": "virtualMachine"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 50,
                    "shares_level": "normal",
                    "type": "management"
                  },
                  {
                    "limit": 0,
                    "reservation": 0,
                    "shares": 25,
                    "shares_level": "low",
                    "type": "faultTolerance"
                  }
                ],
                "portgroup": [
                  {
                    "active_uplinks": [
                      "uplink1",
                      "uplink2"
                    ],
                    "name": "xxx-pg-mgmt",
                    "transport_type": "MANAGEMENT"
                  },
                  {
                    "active_uplinks": [
                      "uplink1",
                      "uplink2"
                    ],
                    "name": "xxxx-pg-vmotion",
                    "transport_type": "VMOTION"
                  }
                ]
              }
            ]
          },
          "sensitive_attributes": []
        }
      ]
    }
  ],
  "check_results": null
}

@burnsjared0415 burnsjared0415 force-pushed the bug/fix-vds-portgroups_nioc branch from f364358 to e3d8f78 Compare August 27, 2024 14:26
@tenthirtyam tenthirtyam self-requested a review September 3, 2024 21:30
@tenthirtyam tenthirtyam changed the title 🚧 fix: missing vds info with r/cluster import fix: missing vds info with r/cluster import Sep 3, 2024
@tenthirtyam tenthirtyam modified the milestones: v0.11.0, On Deck Sep 25, 2024
Copy link
Collaborator

@tenthirtyam tenthirtyam left a 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)

@tenthirtyam tenthirtyam marked this pull request as ready for review October 11, 2024 19:52
@tenthirtyam tenthirtyam force-pushed the bug/fix-vds-portgroups_nioc branch from e3d8f78 to f09fef2 Compare November 13, 2024 14:48
@tenthirtyam
Copy link
Collaborator

Rebased based on the changes to main recently. Will need updates given the SDK changes.

@tenthirtyam tenthirtyam marked this pull request as draft November 13, 2024 14:53
@tenthirtyam tenthirtyam self-requested a review November 13, 2024 14:54
@tenthirtyam tenthirtyam modified the milestones: On Deck, v.0.14.0 Nov 26, 2024
@burnsjared0415 burnsjared0415 force-pushed the bug/fix-vds-portgroups_nioc branch from f09fef2 to 06e4980 Compare December 5, 2024 13:13
@github-actions github-actions bot added dependencies Dependencies chore Chore labels Dec 5, 2024
@tenthirtyam tenthirtyam self-requested a review December 5, 2024 14:34
@tenthirtyam tenthirtyam marked this pull request as ready for review December 5, 2024 14:34
Updating Cluster import to solve issues where vds is blank on data source.

Signed-off-by: Jared Burns <jared.burns@broadcom.com>
@tenthirtyam tenthirtyam force-pushed the bug/fix-vds-portgroups_nioc branch from 06e4980 to 2963fc2 Compare December 5, 2024 14:36
Comment on lines +475 to +489
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,
}
}
Copy link
Collaborator

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?

Copy link
Contributor

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

Suggested change
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)

Copy link
Collaborator

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
}

@tenthirtyam tenthirtyam self-requested a review December 5, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug chore Chore dependencies Dependencies needs-review Needs Review provider Provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/cluster: import does not include vmnic and vds
3 participants