Просмотр исходного кода

clean up

Signed-off-by: nickcurie <nick.curie64@gmail.com>
nickcurie 3 лет назад
Родитель
Сommit
68c842a24b
2 измененных файлов с 16 добавлено и 15 удалено
  1. 4 11
      pkg/cloud/awsprovider.go
  2. 12 4
      pkg/cloud/gcpprovider.go

+ 4 - 11
pkg/cloud/awsprovider.go

@@ -54,6 +54,8 @@ const (
 
 	InUseState    = "in-use"
 	AttachedState = "attached"
+
+	AWSHourlyPublicIPCost = 0.005
 )
 
 var (
@@ -1696,7 +1698,7 @@ func (aws *AWS) GetOrphanedResources() ([]OrphanedResource, error) {
 
 	for _, address := range addresses {
 		if aws.isAddressOrphaned(address) {
-			cost := timeutil.HoursPerMonth * 0.005
+			cost := AWSHourlyPublicIPCost * timeutil.HoursPerMonth
 
 			or := OrphanedResource{
 				Kind:        "address",
@@ -1711,16 +1713,7 @@ func (aws *AWS) GetOrphanedResources() ([]OrphanedResource, error) {
 }
 
 func (aws *AWS) findCostForDisk(disk *ec2Types.Volume) (*float64, error) {
-	//todo: use AWS pricing
-	// price := 0.04
-	// if strings.Contains(string(disk.VolumeType), "ssd") {
-	// 	price = 0.17
-	// }
-	// if strings.Contains(string(disk.VolumeType), "gp2") {
-	// 	price = 0.1
-	// }
-	// cost := price * float64(*disk.Size)
-	// return &cost, nil
+	//todo: use AWS pricing from all regions
 	if disk.AvailabilityZone == nil {
 		return nil, fmt.Errorf("nil region")
 	}

+ 12 - 4
pkg/cloud/gcpprovider.go

@@ -35,6 +35,14 @@ import (
 const GKE_GPU_TAG = "cloud.google.com/gke-accelerator"
 const BigqueryUpdateType = "bigqueryupdate"
 
+const (
+	GCPHourlyPublicIPCost = 0.01
+
+	GCPMonthlyBasicDiskCost = 0.04
+	GCPMonthlySSDDiskCost   = 0.17
+	GCPMonthlyGP2DiskCost   = 0.1
+)
+
 // List obtained by installing the `gcloud` CLI tool,
 // logging into gcp account, and running command
 // `gcloud compute regions list`
@@ -479,7 +487,7 @@ func (gcp *GCP) GetOrphanedResources() ([]OrphanedResource, error) {
 		for _, address := range addressList.Addresses {
 			if gcp.isAddressOrphaned(address) {
 				//todo: use GCP pricing
-				cost := 0.01 * timeutil.HoursPerMonth
+				cost := GCPHourlyPublicIPCost * timeutil.HoursPerMonth
 
 				or := OrphanedResource{
 					Kind:   "address",
@@ -500,12 +508,12 @@ func (gcp *GCP) GetOrphanedResources() ([]OrphanedResource, error) {
 
 func (gcp *GCP) findCostForDisk(disk *compute.Disk) (*float64, error) {
 	//todo: use GCP pricing struct
-	price := 0.04
+	price := GCPMonthlyBasicDiskCost
 	if strings.Contains(disk.Type, "ssd") {
-		price = 0.17
+		price = GCPMonthlySSDDiskCost
 	}
 	if strings.Contains(disk.Type, "gp2") {
-		price = 0.1
+		price = GCPMonthlyGP2DiskCost
 	}
 	cost := price * float64(disk.SizeGb)