cloudsql

package
v0.0.0-...-16b5795 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: OSL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cloudsql provides GCP Cloud SQL commitments client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BillingService

type BillingService interface {
	ListSKUs(serviceID string) (*cloudbilling.ListSkusResponse, error)
}

BillingService interface for billing operations (enables mocking).

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles GCP Cloud SQL commitments.

func NewClient

func NewClient(ctx context.Context, projectID, region string, opts ...option.ClientOption) (*Client, error)

NewClient creates a new GCP Cloud SQL client.

func (*Client) GetExistingCommitments

func (c *Client) GetExistingCommitments(_ context.Context) ([]common.Commitment, error)

GetExistingCommitments returns an empty slice for Cloud SQL. Cloud SQL spend-based CUDs are purchased via the Cloud Billing console / Cloud Commerce Consumer Procurement API, not exposed through the sqladmin API. The legacy PricingPlan "PACKAGE" is a per-instance billing mode (non-commitment, deprecated) -- treating it as a commitment caused double-counting against real spend-based CUDs (10-L3). Return empty until a proper commitment- detection path is available.

func (*Client) GetOfferingDetails

func (c *Client) GetOfferingDetails(ctx context.Context, rec common.Recommendation) (*common.OfferingDetails, error)

GetOfferingDetails retrieves Cloud SQL offering details from GCP Billing API.

func (*Client) GetRecommendations

func (c *Client) GetRecommendations(ctx context.Context, p *common.RecommendationParams) ([]common.Recommendation, error)

GetRecommendations gets Cloud SQL recommendations from GCP Recommender API.

func (*Client) GetRegion

func (c *Client) GetRegion() string

GetRegion returns the region.

func (*Client) GetServiceType

func (c *Client) GetServiceType() common.ServiceType

GetServiceType returns the service type.

func (*Client) GetValidResourceTypes

func (c *Client) GetValidResourceTypes(ctx context.Context) ([]string, error)

GetValidResourceTypes returns valid Cloud SQL tiers.

func (*Client) PurchaseCommitment

func (c *Client) PurchaseCommitment(ctx context.Context, rec common.Recommendation, opts common.PurchaseOptions) (common.PurchaseResult, error)

PurchaseCommitment is intentionally a no-op for Cloud SQL: GCP exposes no programmatic API to buy a Cloud SQL committed-use discount. CUD purchases are spend-based and bought via the Cloud Billing console / Cloud Commerce Consumer Procurement API, not via sqladmin.Instances.Insert. The previous implementation created a brand-new billable SQL instance (the legacy PricingPlan "PACKAGE" is a per-instance billing mode, not a commitment), so a "purchase" silently spun up a new database that kept billing. Cloud SQL recommendations are therefore advisory only; this returns a clear not-supported error and never calls any resource-creation API (issue #640).

func (*Client) SetBillingService

func (c *Client) SetBillingService(svc BillingService)

SetBillingService sets the billing service (for testing).

func (*Client) SetRecommenderClient

func (c *Client) SetRecommenderClient(client RecommenderClient)

SetRecommenderClient sets the recommender client (for testing).

func (*Client) SetSQLAdminService

func (c *Client) SetSQLAdminService(svc SQLAdminService)

SetSQLAdminService sets the SQL admin service (for testing).

func (*Client) ValidateOffering

func (c *Client) ValidateOffering(ctx context.Context, rec common.Recommendation) error

ValidateOffering validates that a Cloud SQL tier exists.

type RecommenderClient

type RecommenderClient interface {
	ListRecommendations(ctx context.Context, req *recommenderpb.ListRecommendationsRequest) RecommenderIterator
	Close() error
}

RecommenderClient interface for recommender operations (enables mocking).

type RecommenderIterator

type RecommenderIterator interface {
	Next() (*recommenderpb.Recommendation, error)
}

RecommenderIterator interface for recommender iteration (enables mocking).

type SQLAdminService

type SQLAdminService interface {
	ListInstances(projectID string) (*sqladmin.InstancesListResponse, error)
	InsertInstance(projectID string, instance *sqladmin.DatabaseInstance) (*sqladmin.Operation, error)
	ListTiers(projectID string) (*sqladmin.TiersListResponse, error)
}

SQLAdminService interface for SQL admin operations (enables mocking).

type SQLPricing

type SQLPricing struct {
	HourlyRate        float64
	CommitmentPrice   float64
	OnDemandPrice     float64
	Currency          string
	SavingsPercentage float64
}

SQLPricing contains pricing information for Cloud SQL.

Jump to

Keyboard shortcuts

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