Skip to content

Commit

Permalink
fix aws pricing sdk change again (aws#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 authored Jul 21, 2022
1 parent 3829e76 commit 8ab2b20
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/Pallinder/go-randomdata v1.2.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.44.46
github.com/aws/aws-sdk-go v1.44.60
github.com/deckarep/golang-set v1.8.0
github.com/go-logr/zapr v0.4.0
github.com/imdario/mergo v0.3.13
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aws/aws-sdk-go v1.44.46 h1:BsKENvu24eXg7CWQ2wJAjKbDFkGP+hBtxKJIR3UdcB8=
github.com/aws/aws-sdk-go v1.44.46/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.44.60 h1:KTTogelVR+4dWiIPl7eyxoxaJkziChON6/Y/hVfTipk=
github.com/aws/aws-sdk-go v1.44.60/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down
13 changes: 2 additions & 11 deletions pkg/cloudprovider/aws/fake/pricingapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ limitations under the License.
package fake

import (
"bytes"
"encoding/json"
"errors"
"fmt"

"k8s.io/apimachinery/pkg/util/runtime"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/pricing"
Expand Down Expand Up @@ -54,8 +50,8 @@ func (p *PricingAPI) GetProductsPagesWithContext(_ aws.Context, inp *pricing.Get
return errors.New("no pricing data provided")
}

func NewOnDemandPrice(instanceType string, price float64) *string {
v := aws.JSONValue{
func NewOnDemandPrice(instanceType string, price float64) aws.JSONValue {
return aws.JSONValue{
"product": map[string]interface{}{
"attributes": map[string]interface{}{
"instanceType": instanceType,
Expand All @@ -74,9 +70,4 @@ func NewOnDemandPrice(instanceType string, price float64) *string {
},
},
}

var buf bytes.Buffer
enc := json.NewEncoder(&buf)
runtime.Must(enc.Encode(v))
return aws.String(buf.String())
}
7 changes: 6 additions & 1 deletion pkg/cloudprovider/aws/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ func (p *PricingProvider) onDemandPage(prices map[string]float64) func(output *p

return func(output *pricing.GetProductsOutput, b bool) bool {
for _, outer := range output.PriceList {
dec := json.NewDecoder(bytes.NewBufferString(aws.StringValue(outer)))
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
if err := enc.Encode(outer); err != nil {
logging.FromContext(context.Background()).Errorf("encoding %s", err)
}
dec := json.NewDecoder(&buf)
var pItem priceItem
if err := dec.Decode(&pItem); err != nil {
logging.FromContext(context.Background()).Errorf("decoding %s", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/aws/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ var _ = Describe("Pricing", func() {
// modify our API before creating the pricing provider as it performs an initial update on creation. The pricing
// API provides on-demand prices, the ec2 API provides spot prices
fakePricingAPI.GetProductsOutput.Set(&pricing.GetProductsOutput{
PriceList: []*string{
PriceList: []aws.JSONValue{
fake.NewOnDemandPrice("c98.large", 1.20),
fake.NewOnDemandPrice("c99.large", 1.23),
},
Expand Down Expand Up @@ -2139,7 +2139,7 @@ var _ = Describe("Pricing", func() {
},
})
fakePricingAPI.GetProductsOutput.Set(&pricing.GetProductsOutput{
PriceList: []*string{
PriceList: []aws.JSONValue{
fake.NewOnDemandPrice("c98.large", 1.20),
fake.NewOnDemandPrice("c99.large", 1.23),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/aws/zz_generated.pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package aws

import "time"

// generated at 2022-07-19T21:28:17Z for us-east-1
// generated at 2022-07-21T20:18:10Z for us-east-1

var initialPriceUpdate, _ = time.Parse(time.RFC3339, "2022-07-19T21:28:17Z")
var initialPriceUpdate, _ = time.Parse(time.RFC3339, "2022-07-21T20:18:10Z")
var initialOnDemandPrices = map[string]float64{
// a1 family
"a1.2xlarge": 0.204000, "a1.4xlarge": 0.408000, "a1.large": 0.051000, "a1.medium": 0.025500,
Expand Down

0 comments on commit 8ab2b20

Please sign in to comment.