gcp

package
v0.0.0-...-8b28c38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UsageDateColumnName          = "usage_date"
	BillingAccountIDColumnName   = "billing_id"
	ProjectIDColumnName          = "project_id"
	ServiceDescriptionColumnName = "service"
	SKUDescriptionColumnName     = "description"
	LabelsColumnName             = "labels"
	ResourceNameColumnName       = "resource"
	CostColumnName               = "cost"
	CreditsColumnName            = "credits"
)
View Source
const (
	GCPHourlyPublicIPCost = 0.01

	GCPMonthlyBasicDiskCost = 0.04
	GCPMonthlySSDDiskCost   = 0.17
	GCPMonthlyGP2DiskCost   = 0.1

	GKEPreemptibleLabel = "cloud.google.com/gke-preemptible"
	GKESpotLabel        = "cloud.google.com/gke-spot"
)
View Source
const (
	GCPReservedInstanceResourceTypeRAM string = "MEMORY"
	GCPReservedInstanceResourceTypeCPU string = "VCPU"
	GCPReservedInstanceStatusActive    string = "ACTIVE"
	GCPReservedInstancePlanOneYear     string = "TWELVE_MONTH"
	GCPReservedInstancePlanThreeYear   string = "THIRTY_SIX_MONTH"
)
View Source
const BigqueryUpdateType = "bigqueryupdate"
View Source
const BillingAPIURLFmt = "https://cloudbilling.googleapis.com/v1/services/6F81-5844-456A/skus?key=%s&currencyCode=%s"
View Source
const BiqQueryWhereDateFmt = `usage_start_time >= "%s" AND usage_start_time < "%s"`
View Source
const BiqQueryWherePartitionFmt = `DATE(_PARTITIONTIME) >= "%s" AND DATE(_PARTITIONTIME) < "%s"`
View Source
const GKE_GPU_TAG = "cloud.google.com/gke-accelerator"
View Source
const ServiceAccountKeyAuthorizerType = "GCPServiceAccountKey"
View Source
const WorkloadIdentityAuthorizerType = "GCPWorkloadIdentity"

Variables

This section is empty.

Functions

func ConvertBigQueryConfigToConfig

func ConvertBigQueryConfigToConfig(bqc BigQueryConfig) config.KeyedConfig

func IsK8s

func IsK8s(labels map[string]string) bool

func ParseGCPProjectID

func ParseGCPProjectID(id string) string

func ParseProviderID

func ParseProviderID(id string) string

func SelectCategory

func SelectCategory(service, description string) string

Types

type Authorizer

type Authorizer interface {
	config.Authorizer
	CreateGCPClientOptions() ([]option.ClientOption, error)
}

Authorizer provide a []option.ClientOption which is used in when creating clients in the GCP SDK

func SelectAuthorizerByType

func SelectAuthorizerByType(typeStr string) (Authorizer, error)

SelectAuthorizerByType is an implementation of AuthorizerSelectorFn and acts as a register for Authorizer types

type BigQueryConfig

type BigQueryConfig struct {
	ProjectID          string            `json:"projectID"`
	BillingDataDataset string            `json:"billingDataDataset"`
	Key                map[string]string `json:"key"`
}

BigQueryConfig contain the required config and credentials to access OOC resources for GCP Deprecated: v1.104 Use BigQueryConfiguration instead

func (*BigQueryConfig) IsEmpty

func (bqc *BigQueryConfig) IsEmpty() bool

IsEmpty returns true if all fields in config are empty, false if not.

type BigQueryConfiguration

type BigQueryConfiguration struct {
	ProjectID  string     `json:"projectID"`
	Dataset    string     `json:"dataset"`
	Table      string     `json:"table"`
	Authorizer Authorizer `json:"authorizer"`
}

func (*BigQueryConfiguration) Equals

func (bqc *BigQueryConfiguration) Equals(config config.Config) bool

func (*BigQueryConfiguration) GetBigQueryClient

func (bqc *BigQueryConfiguration) GetBigQueryClient(ctx context.Context) (*bigquery.Client, error)

func (*BigQueryConfiguration) GetBillingDataDataset

func (bqc *BigQueryConfiguration) GetBillingDataDataset() string

func (*BigQueryConfiguration) Key

func (bqc *BigQueryConfiguration) Key() string

Key uses the Usage Project Id as the Provider Key for GCP

func (*BigQueryConfiguration) Sanitize

func (bqc *BigQueryConfiguration) Sanitize() config.Config

func (*BigQueryConfiguration) UnmarshalJSON

func (bqc *BigQueryConfiguration) UnmarshalJSON(b []byte) error

UnmarshalJSON assumes data is save as an BigQueryConfigurationDTO

func (*BigQueryConfiguration) Validate

func (bqc *BigQueryConfiguration) Validate() error

type BigQueryIntegration

type BigQueryIntegration struct {
	BigQueryQuerier
}

func (*BigQueryIntegration) GetCloudCost

func (bqi *BigQueryIntegration) GetCloudCost(start time.Time, end time.Time) (*kubecost.CloudCostSetRange, error)

type BigQueryQuerier

type BigQueryQuerier struct {
	BigQueryConfiguration
	ConnectionStatus cloud.ConnectionStatus
}

func (*BigQueryQuerier) Equals

func (bqq *BigQueryQuerier) Equals(config cloudconfig.Config) bool

func (*BigQueryQuerier) GetStatus

func (bqq *BigQueryQuerier) GetStatus() cloud.ConnectionStatus

func (*BigQueryQuerier) Query

func (bqq *BigQueryQuerier) Query(ctx context.Context, queryStr string) (*bigquery.RowIterator, error)

type CloudCostLoader

type CloudCostLoader struct {
	CloudCost *kubecost.CloudCost
}

func (*CloudCostLoader) Load

func (ccl *CloudCostLoader) Load(values []bigquery.Value, schema bigquery.Schema) error

Load populates the fields of a CloudCostValues with bigquery.Value from provided slice

type GCP

type GCP struct {
	Pricing                 map[string]*GCPPricing
	Clientset               clustercache.ClusterCache
	APIKey                  string
	BaseCPUPrice            string
	ProjectID               string
	BillingDataDataset      string
	DownloadPricingDataLock sync.RWMutex
	ReservedInstances       []*GCPReservedInstance
	Config                  models.ProviderConfig
	ServiceKeyProvided      bool
	ValidPricingKeys        map[string]bool
	MetadataClient          *metadata.Client

	ClusterRegion    string
	ClusterAccountID string
	ClusterProjectID string
	// contains filtered or unexported fields
}

GCP implements a provider interface for GCP

func (*GCP) AllNodePricing

func (gcp *GCP) AllNodePricing() (interface{}, error)

AllNodePricing returns the GCP pricing objects stored

func (*GCP) ApplyReservedInstancePricing

func (gcp *GCP) ApplyReservedInstancePricing(nodes map[string]*models.Node)

func (*GCP) ClusterInfo

func (gcp *GCP) ClusterInfo() (map[string]string, error)

ClusterInfo returns information on the GKE cluster, as provided by metadata.

func (*GCP) ClusterManagementPricing

func (gcp *GCP) ClusterManagementPricing() (string, float64, error)

func (*GCP) CombinedDiscountForNode

func (gcp *GCP) CombinedDiscountForNode(instanceType string, isPreemptible bool, defaultDiscount, negotiatedDiscount float64) float64

func (*GCP) DownloadPricingData

func (gcp *GCP) DownloadPricingData() error

DownloadPricingData fetches data from the GCP Pricing API. Requires a key-- a kubecost key is provided for quickstart, but should be replaced by a users.

func (*GCP) GetAddresses

func (gcp *GCP) GetAddresses() ([]byte, error)

func (*GCP) GetConfig

func (gcp *GCP) GetConfig() (*models.CustomPricing, error)

func (*GCP) GetDisks

func (gcp *GCP) GetDisks() ([]byte, error)

GetDisks returns the GCP disks backing PVs. Useful because sometimes k8s will not clean up PVs correctly. Requires a json config in /var/configs with key region.

func (*GCP) GetKey

func (gcp *GCP) GetKey(labels map[string]string, n *v1.Node) models.Key

func (*GCP) GetLocalStorageQuery

func (gcp *GCP) GetLocalStorageQuery(window, offset time.Duration, rate bool, used bool) string

GetLocalStorageQuery returns the cost of local storage for the given window. Setting rate=true returns hourly spend. Setting used=true only tracks used storage, not total.

func (*GCP) GetManagementPlatform

func (gcp *GCP) GetManagementPlatform() (string, error)

func (*GCP) GetOrphanedResources

func (gcp *GCP) GetOrphanedResources() ([]models.OrphanedResource, error)

func (*GCP) GetPVKey

func (gcp *GCP) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) models.PVKey

func (*GCP) LoadBalancerPricing

func (gcp *GCP) LoadBalancerPricing() (*models.LoadBalancer, error)

func (*GCP) NetworkPricing

func (gcp *GCP) NetworkPricing() (*models.Network, error)

Stubbed NetworkPricing for GCP. Pull directly from gcp.json for now

func (*GCP) NodePricing

func (gcp *GCP) NodePricing(key models.Key) (*models.Node, models.PricingMetadata, error)

NodePricing returns GCP pricing data for a single node

func (*GCP) PVPricing

func (gcp *GCP) PVPricing(pvk models.PVKey) (*models.PV, error)

func (*GCP) PricingSourceStatus

func (gcp *GCP) PricingSourceStatus() map[string]*models.PricingSource

func (*GCP) PricingSourceSummary

func (gcp *GCP) PricingSourceSummary() interface{}

PricingSourceSummary returns the pricing source summary for the provider. The summary represents what was _parsed_ from the pricing source, not everything that was _available_ in the pricing source.

func (*GCP) Regions

func (gcp *GCP) Regions() []string

func (*GCP) ServiceAccountStatus

func (gcp *GCP) ServiceAccountStatus() *models.ServiceAccountStatus

func (*GCP) UpdateConfig

func (gcp *GCP) UpdateConfig(r io.Reader, updateType string) (*models.CustomPricing, error)

func (*GCP) UpdateConfigFromConfigMap

func (gcp *GCP) UpdateConfigFromConfigMap(a map[string]string) (*models.CustomPricing, error)

type GCPPricing

type GCPPricing struct {
	Name                string           `json:"name"`
	SKUID               string           `json:"skuId"`
	Description         string           `json:"description"`
	Category            *GCPResourceInfo `json:"category"`
	ServiceRegions      []string         `json:"serviceRegions"`
	PricingInfo         []*PricingInfo   `json:"pricingInfo"`
	ServiceProviderName string           `json:"serviceProviderName"`
	Node                *models.Node     `json:"node"`
	PV                  *models.PV       `json:"pv"`
}

GCPPricing represents GCP pricing data for a SKU

type GCPReservedCounter

type GCPReservedCounter struct {
	RemainingCPU int64
	RemainingRAM int64
	Instance     *GCPReservedInstance
}

type GCPReservedInstance

type GCPReservedInstance struct {
	ReservedRAM int64
	ReservedCPU int64
	Plan        *GCPReservedInstancePlan
	StartDate   time.Time
	EndDate     time.Time
	Region      string
}

func (*GCPReservedInstance) String

func (r *GCPReservedInstance) String() string

type GCPReservedInstancePlan

type GCPReservedInstancePlan struct {
	Name    string
	CPUCost float64
	RAMCost float64
}

type GCPResourceInfo

type GCPResourceInfo struct {
	ServiceDisplayName string `json:"serviceDisplayName"`
	ResourceFamily     string `json:"resourceFamily"`
	ResourceGroup      string `json:"resourceGroup"`
	UsageType          string `json:"usageType"`
}

GCPResourceInfo contains metadata about the node.

type PricingExpression

type PricingExpression struct {
	UsageUnit                string         `json:"usageUnit"`
	UsageUnitDescription     string         `json:"usageUnitDescription"`
	BaseUnit                 string         `json:"baseUnit"`
	BaseUnitConversionFactor int64          `json:"-"`
	DisplayQuantity          int            `json:"displayQuantity"`
	TieredRates              []*TieredRates `json:"tieredRates"`
}

PricingExpression contains metadata about a cost.

type PricingInfo

type PricingInfo struct {
	Summary                string             `json:"summary"`
	PricingExpression      *PricingExpression `json:"pricingExpression"`
	CurrencyConversionRate float64            `json:"currencyConversionRate"`
	EffectiveTime          string             `json:""`
}

PricingInfo contains metadata about a cost.

type ServiceAccountKey

type ServiceAccountKey struct {
	Key map[string]string `json:"key"`
}

func (*ServiceAccountKey) CreateGCPClientOptions

func (gkc *ServiceAccountKey) CreateGCPClientOptions() ([]option.ClientOption, error)

func (*ServiceAccountKey) Equals

func (gkc *ServiceAccountKey) Equals(config config.Config) bool

func (*ServiceAccountKey) MarshalJSON

func (gkc *ServiceAccountKey) MarshalJSON() ([]byte, error)

MarshalJSON custom json marshalling functions, sets properties as tagged in struct and sets the authorizer type property

func (*ServiceAccountKey) Sanitize

func (gkc *ServiceAccountKey) Sanitize() config.Config

func (*ServiceAccountKey) Validate

func (gkc *ServiceAccountKey) Validate() error

type TieredRates

type TieredRates struct {
	StartUsageAmount int            `json:"startUsageAmount"`
	UnitPrice        *UnitPriceInfo `json:"unitPrice"`
}

TieredRates contain data about variable pricing.

type UnitPriceInfo

type UnitPriceInfo struct {
	CurrencyCode string  `json:"currencyCode"`
	Units        string  `json:"units"`
	Nanos        float64 `json:"nanos"`
}

UnitPriceInfo contains data about the actual price being charged.

type WorkloadIdentity

type WorkloadIdentity struct{}

WorkloadIdentity passes an empty slice of client options which causes the GCP SDK to check for the workload identity in the environment

func (*WorkloadIdentity) CreateGCPClientOptions

func (wi *WorkloadIdentity) CreateGCPClientOptions() ([]option.ClientOption, error)

func (*WorkloadIdentity) Equals

func (wi *WorkloadIdentity) Equals(config config.Config) bool

func (*WorkloadIdentity) MarshalJSON

func (wi *WorkloadIdentity) MarshalJSON() ([]byte, error)

MarshalJSON custom json marshalling functions, sets properties as tagged in struct and sets the authorizer type property

func (*WorkloadIdentity) Sanitize

func (wi *WorkloadIdentity) Sanitize() config.Config

func (*WorkloadIdentity) Validate

func (wi *WorkloadIdentity) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL