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

new: Add support LKE, Volume, NodeBalancer, and network transfer pricing endpoints #573

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Sep 4, 2024

📝 Description

This pull request adds support for the following endpoints:

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

Integration Testing

make fixtures ARGS="-run TestNetworkTransferPrice -run TestLKEType -run TestNodeBalancerType -run TestVolumeType"

Manual Testing

  1. In a linodego sandbox environment (e.g. dx-devenv), run the following:
package main

import (
	"context"
	"github.com/kr/pretty"
	"github.com/linode/linodego"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))

	lkeTypes, err := client.ListLKETypes(ctx, nil)
	if err != nil {
		log.Fatalf("failed to get LKE types: %s", err)
	}

	nbTypes, err := client.ListNodeBalancerTypes(ctx, nil)
	if err != nil {
		log.Fatalf("failed to get NodeBalancer types: %s", err)
	}

	volumeTypes, err := client.ListVolumeTypes(ctx, nil)
	if err != nil {
		log.Fatalf("failed to get Volume types: %s", err)
	}

	transferPrices, err := client.ListNetworkTransferPrices(ctx, nil)
	if err != nil {
		log.Fatalf("failed to get network transfer types: %s", err)
	}

	pretty.Println(lkeTypes)
	pretty.Println(nbTypes)
	pretty.Println(volumeTypes)
	pretty.Println(transferPrices)
}
  1. Ensure the output matches the following:
Expected Output
[]linodego.LKEType{
    {
        baseType: linodego.baseType[github.com/linode/linodego.LKETypePrice,github.com/linode/linodego.LKETypeRegionPrice]{
            ID:           "lke-sa",
            Label:        "LKE Standard Availability",
            Price:        linodego.LKETypePrice{},
            RegionPrices: {
            },
            Transfer: 0,
        },
    },
    {
        baseType: linodego.baseType[github.com/linode/linodego.LKETypePrice,github.com/linode/linodego.LKETypeRegionPrice]{
            ID:    "lke-ha",
            Label: "LKE High Availability",
            Price: linodego.LKETypePrice{
                baseTypePrice: linodego.baseTypePrice{Hourly:0.09, Monthly:60},
            },
            RegionPrices: {
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.108, Monthly:72},
                        ID:            "id-cgk",
                    },
                },
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.126, Monthly:84},
                        ID:            "br-gru",
                    },
                },
            },
            Transfer: 0,
        },
    },
}
[]linodego.NodeBalancerType{
    {
        baseType: linodego.baseType[github.com/linode/linodego.NodeBalancerTypePrice,github.com/linode/linodego.NodeBalancerTypeRegionPrice]{
            ID:    "nodebalancer",
            Label: "NodeBalancer",
            Price: linodego.NodeBalancerTypePrice{
                baseTypePrice: linodego.baseTypePrice{Hourly:0.015, Monthly:10},
            },
            RegionPrices: {
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.018, Monthly:12},
                        ID:            "id-cgk",
                    },
                },
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.021, Monthly:14},
                        ID:            "br-gru",
                    },
                },
            },
            Transfer: 0,
        },
    },
}
[]linodego.VolumeType{
    {
        baseType: linodego.baseType[github.com/linode/linodego.VolumeTypePrice,github.com/linode/linodego.VolumeTypeRegionPrice]{
            ID:    "volume",
            Label: "Storage Volume",
            Price: linodego.VolumeTypePrice{
                baseTypePrice: linodego.baseTypePrice{Hourly:0.00015, Monthly:0.1},
            },
            RegionPrices: {
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.00018, Monthly:0.12},
                        ID:            "id-cgk",
                    },
                },
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.00021, Monthly:0.14},
                        ID:            "br-gru",
                    },
                },
            },
            Transfer: 0,
        },
    },
}
[]linodego.NetworkTransferPrice{
    {
        baseType: linodego.baseType[github.com/linode/linodego.NetworkTransferTypePrice,github.com/linode/linodego.NetworkTransferTypeRegionPrice]{
            ID:    "distributed_network_transfer",
            Label: "Distributed Network Transfer",
            Price: linodego.NetworkTransferTypePrice{
                baseTypePrice: linodego.baseTypePrice{Hourly:0.01, Monthly:0},
            },
            RegionPrices: {
            },
            Transfer: 0,
        },
    },
    {
        baseType: linodego.baseType[github.com/linode/linodego.NetworkTransferTypePrice,github.com/linode/linodego.NetworkTransferTypeRegionPrice]{
            ID:    "network_transfer",
            Label: "Network Transfer",
            Price: linodego.NetworkTransferTypePrice{
                baseTypePrice: linodego.baseTypePrice{Hourly:0.005, Monthly:0},
            },
            RegionPrices: {
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.015, Monthly:0},
                        ID:            "id-cgk",
                    },
                },
                {
                    baseTypeRegionPrice: linodego.baseTypeRegionPrice{
                        baseTypePrice: linodego.baseTypePrice{Hourly:0.007, Monthly:0},
                        ID:            "br-gru",
                    },
                },
            },
            Transfer: 0,
        },
    },
}


// baseType is a base struct containing the core fields of a resource type
// returned from the Linode API.
type baseType[PriceType any, RegionPriceType any] struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use a generic base struct so we can still share common type fields while allowing resource types of diverge without a breaking change if necessary.


// NodeBalancerTypePrice represents the base hourly and monthly prices
// for a NodeBalancer type entry.
type NodeBalancerTypePrice struct {
Copy link
Contributor Author

@lgarber-akamai lgarber-akamai Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave each resource type its own price and region prices structs so external users can still store & access them separate from their parent struct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned this pattern and put them similarly in python-sdk as well.

@lgarber-akamai lgarber-akamai marked this pull request as ready for review September 4, 2024 18:55
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner September 4, 2024 18:55
@lgarber-akamai lgarber-akamai requested review from ykim-akamai and ezilber-akamai and removed request for a team September 4, 2024 18:55
@lgarber-akamai lgarber-akamai added the new-feature for new features in the changelog. label Sep 4, 2024
Copy link
Contributor

@ezilber-akamai ezilber-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that a fixture for the lke types tests isn't included? Otherwise, everything is passing and working properly. Nice work!

@lgarber-akamai
Copy link
Contributor Author

lgarber-akamai commented Sep 5, 2024

Is there a reason that a fixture for the lke types tests isn't included? Otherwise, everything is passing and working properly. Nice work!

Nice catch! I forgot to re-run it lol

Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and worked well locally!

@lgarber-akamai lgarber-akamai merged commit 890ff1e into linode:main Sep 6, 2024
4 checks passed
AniJ98 pushed a commit to AniJ98/ajagadis-akamai-linode that referenced this pull request Sep 16, 2024
…ing endpoints (linode#573)

* Add LKE types endpoints

* Support base struct; add NB types endpoints

* Add volume types

* Add network transfer prices

* Add price and region price structs

* Revert IPv6 fixtures

* Add missing fixtures
yec-akamai added a commit that referenced this pull request Sep 17, 2024
* added reserved field to InstanceIP struct for IP Reservation response

* Reserved IP resource for handling IP reservation API's

* Added integration test covering multiple scenarios of reserving IP addresses

* The fixture files for different scenarios of IP Reservation - EndToEnd, InsuffecientPermission, ReserveIP, GetReservedIP, getReservedIPs, DeleteReservedIPs

* Updated the fixture files with responses after the user has permissions to reserve IP

* Changed the error message to relay invalid token for insufficient permission tests

* Updated the error message for Insufficient Permission tests to display appropriate error message along with code

* Made changes to Delete, List, Get, Reserve, EndtoEnd fixtures to record user with adequate permissions

* changed variable name from id to address to keep it consistent with other functions

* Made changes to variable names, achanged logf statements to errorf and fatalf wherever necessary

* changed fixture file names to improve consistency, re-recorded fixtures with latest error messages

* removed debugging fmt statement

* Made changes to reserve IP addresses before listing them using fitler feature. Removed for loop to reserve IPs till limit is reached.

* uncommenting unaffected tests

* Made changes to error messages, added mandatory checks and re-recorded fixtures to reflect new error messages

* Added new middleware system (#571)

* build(deps): bump golang.org/x/oauth2 from 0.22.0 to 0.23.0 (#574)

* build(deps): bump golang.org/x/oauth2 from 0.22.0 to 0.23.0

Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.22.0 to 0.23.0.
- [Commits](golang/oauth2@v0.22.0...v0.23.0)

---
updated-dependencies:
- dependency-name: golang.org/x/oauth2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Ran make tidy

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: ezilber-akamai <ezilber@akamai.com>

* build(deps): bump golang.org/x/text from 0.17.0 to 0.18.0 (#575)

* build(deps): bump golang.org/x/text from 0.17.0 to 0.18.0

Bumps [golang.org/x/text](https://github.com/golang/text) from 0.17.0 to 0.18.0.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](golang/text@v0.17.0...v0.18.0)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* make tidy

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ye Chen <yechen@akamai.com>

* new: Add support LKE, Volume, NodeBalancer, and network transfer pricing endpoints  (#573)

* Add LKE types endpoints

* Support base struct; add NB types endpoints

* Add volume types

* Add network transfer prices

* Add price and region price structs

* Revert IPv6 fixtures

* Add missing fixtures

* Add test case for ip limit exceed

* add cleanup for TestReservedIPAddresses_ExceedLimit

* added interactions to fixture and changed the ecpected error message

* Added note indicating feature is currently not available to all users

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Erik Zilber <ezilber@akamai.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ye Chen <yechen@akamai.com>
Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>
Co-authored-by: ykim-1 <ykim@akamai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants