ソースを参照

Use function instead of variable

Bianca Burtoiu 4 年 前
コミット
3472f4fac3
3 ファイル変更7 行追加13 行削除
  1. 0 1
      go.mod
  2. 0 2
      go.sum
  3. 7 10
      pkg/cloud/awsprovider.go

+ 0 - 1
go.mod

@@ -87,7 +87,6 @@ require (
 	github.com/jstemmer/go-junit-report v0.9.1 // indirect
 	github.com/klauspost/compress v1.13.5 // indirect
 	github.com/klauspost/cpuid v1.3.1 // indirect
-	github.com/kubecost/events v0.0.1 // indirect
 	github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
 	github.com/minio/md5-simd v1.1.0 // indirect
 	github.com/minio/sha256-simd v0.1.1 // indirect

+ 0 - 2
go.sum

@@ -388,8 +388,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
 github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
-github.com/kubecost/events v0.0.1 h1:Xo+bPQMIuVSpy0D2QbvjAcyl85tZLUcTn//kMZHR8Dg=
-github.com/kubecost/events v0.0.1/go.mod h1:WtqcuJaHct1gZe+9oCJwHEW1YPaKcPFisDVZYon+lDs=
 github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
 github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
 github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=

+ 7 - 10
pkg/cloud/awsprovider.go

@@ -60,7 +60,7 @@ func (aws *AWS) PricingSourceStatus() map[string]*PricingSource {
 		Enabled: true,
 	}
 
-	if !aws.SpotRefreshEnabled {
+	if !aws.isSpotRefreshEnabled() {
 		sps.Available = false
 		sps.Error = "Spot instances not set up"
 		sps.Enabled = false
@@ -136,7 +136,6 @@ type AWS struct {
 	Pricing                     map[string]*AWSProductTerms
 	SpotPricingByInstanceID     map[string]*spotInfo
 	SpotPricingUpdatedAt        *time.Time
-	SpotRefreshEnabled          bool
 	SpotRefreshRunning          bool
 	SpotPricingLock             sync.RWMutex
 	SpotPricingError            error
@@ -761,6 +760,11 @@ func (aws *AWS) getRegionPricing(nodeList []*v1.Node) (*http.Response, string, e
 	return resp, pricingURL, err
 }
 
+func (aws *AWS) isSpotRefreshEnabled() bool {
+	// Need a valid value for at least one of these fields to consider spot pricing as enabled
+	return len(aws.SpotDataBucket) != 0 || len(aws.SpotDataRegion) != 0 || len(aws.ProjectID) != 0
+}
+
 // DownloadPricingData fetches data from the AWS Pricing API
 func (aws *AWS) DownloadPricingData() error {
 	aws.DownloadPricingDataLock.Lock()
@@ -784,13 +788,6 @@ func (aws *AWS) DownloadPricingData() error {
 
 	aws.ConfigureAuthWith(c) // load aws authentication from configuration or secret
 
-	// Need a valid value for at least one of these fields to consider spot pricing as enabled
-	if len(aws.SpotDataBucket) != 0 || len(aws.SpotDataRegion) != 0 || len(aws.ProjectID) != 0 {
-		aws.SpotRefreshEnabled = true
-	} else {
-		aws.SpotRefreshEnabled = false
-	}
-
 	if len(aws.SpotDataBucket) != 0 && len(aws.ProjectID) == 0 {
 		klog.V(1).Infof("using SpotDataBucket \"%s\" without ProjectID will not end well", aws.SpotDataBucket)
 	}
@@ -1028,7 +1025,7 @@ func (aws *AWS) DownloadPricingData() error {
 	}
 	klog.V(2).Infof("Finished downloading \"%s\"", pricingURL)
 
-	if !aws.SpotRefreshEnabled {
+	if !aws.isSpotRefreshEnabled() {
 		return nil
 	}