Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateClusterID(name string, infraID string, accountName string) (string, error)
- func GetClusterIDFromTags(tags []Tag) string
- func GetClusterNameFromTags(tags []Tag) string
- func GetInfraIDFromTags(tags []Tag) string
- func GetInstanceNameFromTags(tags []Tag) string
- func GetOwnerFromTags(tags []Tag) string
- func JSONMarshal(object interface{}) (string, error)
- type Account
- func (a *Account) AddCluster(cluster *Cluster) error
- func (a *Account) DisableBilling()
- func (a *Account) EnableBilling()
- func (a Account) GetPassword() string
- func (a Account) GetUser() string
- func (a Account) IsBillingEnabled() bool
- func (a Account) IsClusterOnAccount(id string) bool
- func (a Account) PrintAccount()
- type CloudProvider
- type Cluster
- func (c *Cluster) AddInstance(instance Instance) error
- func (c Cluster) IsClusterRunning() bool
- func (c Cluster) IsClusterStopped() bool
- func (c Cluster) PrintCluster()
- func (c *Cluster) Update() error
- func (c *Cluster) UpdateAge() error
- func (c *Cluster) UpdateCosts() error
- func (c *Cluster) UpdateStatus()
- type Expense
- type Instance
- type InstanceStatus
- type Inventory
- type Tag
Constants ¶
const ( // AWSProvider - Amazon Web Services Cloud Provider AWSProvider CloudProvider = "AWS" // AzureProvider - Microsoft Azure Cloud Provider AzureProvider = "Azure" // GCPProvider - Google Cloud Platform Cloud Provider GCPProvider = "GCP" // UnknownProvider - Unknown Platform Cloud Provider UnknownProvider = "UNKNOWN" )
const ( UnknownClusterNameCode = "UNKNOWN-CLUSTER" UnknownClusterIDCode = "UNKNOWN-CLUSTER" )
const ( // Cluster actions ClusterPowerOnAction = "PowerOn" ClusterPowerOffAction = "PowerOff" // Resource types ClusterResourceType = "cluster" InstanceResourceType = "instance" )
const ( // ClusterTagKey string to identify to which cluster is the instance associated ClusterTagKey string = "kubernetes.io/cluster/" )
Variables ¶
var ( ERR_INSTANCE_TOTAL_COST_LESS_ZERO = errors.New("TotalCost of an instance cannot be less than zero") ERR_INSTANCE_DAILY_COST_LESS_ZERO = errors.New("DailyCost of an instance cannot be less than zero") ERR_INSTANCE_AGE_LESS_ZERO = errors.New("Cannot recalculate costs if instance's Age is 0") )
Errors for Instances
Functions ¶
func GenerateClusterID ¶
Obtain the required parameters for generate a ClusterID. If any key parameter is missing, it will return a non-nil error
func GetClusterIDFromTags ¶ added in v0.4.1
func GetClusterNameFromTags ¶ added in v0.4.1
func GetInfraIDFromTags ¶ added in v0.4.1
func GetInstanceNameFromTags ¶ added in v0.4.1
func GetOwnerFromTags ¶ added in v0.4.1
GetOwnerFromTags looks for a tag with the key "Owner" and returns its value
func JSONMarshal ¶
JSONMarshal converts an inventory object as JSON format for printing
Types ¶
type Account ¶
type Account struct {
// ID is the uniq identifier for each account without considering the cloud provider
// AWS: AccountID
// Azure: SubscriptionID
// GCP: ProjectID
ID string `db:"id" json:"id"`
// Account's name. It's considered as an uniq key. Two accounts with same
// name can't belong to same Inventory
Name string `db:"name" json:"name"`
// Infrastructure provider identifier.
Provider CloudProvider `db:"provider" json:"provider"`
// ClusterCount
ClusterCount int `db:"cluster_count" json:"clusterCount"`
// List of clusters deployed on this account indexed by Cluster's name
Clusters map[string]*Cluster `json:"-"`
// Last scan timestamp of the account
LastScanTimestamp time.Time `db:"last_scan_timestamp" json:"lastScanTimestamp"`
// Total cost (US Dollars)
TotalCost float64 `db:"total_cost" json:"totalCost"`
// Cost Last 15d
Last15DaysCost float64 `db:"last_15_days_cost" json:"last15DaysCost"`
// Last month cost
LastMonthCost float64 `db:"last_month_cost" json:"lastMonthCost"`
// Current month so far cost
CurrentMonthSoFarCost float64 `db:"current_month_so_far_cost" json:"currentMonthSoFarCost"`
// contains filtered or unexported fields
}
Account defines an infrastructure provider account
func NewAccount ¶
func NewAccount(id string, name string, provider CloudProvider, user string, password string) *Account
NewAccount create a new Could Provider account to store its instances
func (*Account) AddCluster ¶
AddCluster adds a cluster to the stock
func (*Account) DisableBilling ¶
func (a *Account) DisableBilling()
DisableBilling disables the billing information scanner for this account
func (*Account) EnableBilling ¶
func (a *Account) EnableBilling()
EnableBilling enables the billing information scanner for this account
func (Account) GetPassword ¶
GetPassword returns the password value
func (Account) IsBillingEnabled ¶
IsBillingEnabled returns a boolean value based on if the billing module is enabled or not
func (Account) IsClusterOnAccount ¶
IsClusterOnAccount checks if a cluster is already in the Stock
func (Account) PrintAccount ¶
func (a Account) PrintAccount()
PrintAccount prints account info and every cluster on it by stdout
type CloudProvider ¶
type CloudProvider string
CloudProvider defines the cloud provider of the instance
func GetCloudProvider ¶ added in v0.4.2
func GetCloudProvider(provider string) CloudProvider
GetCloudProvider checks a incoming string and returns the corresponding inventory.CloudProvider value
type Cluster ¶
type Cluster struct {
// ID is the unique key to identify every cluster independently of which account it belongs
// Its built as "name+infra_id+account"
ID string `db:"id" json:"id"`
// Cluster's Name. Must be unique per Account
Name string `db:"name" json:"name"`
// InfraID is the infrastructure ID generated by openshift-installer during the installation.Cluster (Could be undefined)
InfraID string `db:"infra_id" json:"infra_id"`
// Infrastructure provider identifier.
Provider CloudProvider `db:"provider" json:"provider"`
// Defines the status of the cluster if its infrastructure is running or not or it was removed
Status InstanceStatus `db:"status" json:"status"`
// The region of the infrastructure provider in which the cluster is deployed
Region string `db:"region" json:"region"`
// Account name which this cluster belongs to
AccountName string `db:"account_name" json:"accountName"`
// Openshift Console URL. Might not be accesible if its protected
ConsoleLink string `db:"console_link" json:"consoleLink"`
// Instances count
InstanceCount int `db:"instance_count" json:"instanceCount"`
// Last scan timestamp of the cluster
LastScanTimestamp time.Time `db:"last_scan_timestamp" json:"lastScanTimestamp"`
// Timestamp when the cluster was created
CreationTimestamp time.Time `db:"creation_timestamp" json:"creationTimestamp"`
// Amount of days since the cluster was created
Age int `db:"age" json:"age"`
// Cluster's owner
Owner string `db:"owner" json:"owner"`
// Total cost (US Dollars)
TotalCost float64 `db:"total_cost" json:"totalCost"`
// Cost Last 15d
Last15DaysCost float64 `db:"last_15_days_cost" json:"last15DaysCost"`
// Last month cost
LastMonthCost float64 `db:"last_month_cost" json:"lastMonthCost"`
// Current month so far cost
CurrentMonthSoFarCost float64 `db:"current_month_so_far_cost" json:"currentMonthSoFarCost"`
// Cluster's instance (nodes) lists
Instances []Instance
}
Cluster is the object to store Openshift Clusters and its properties
func NewCluster ¶
func NewCluster(name string, infraID string, provider CloudProvider, region string, accountName string, consoleLink string, owner string) *Cluster
NewCluster creates a new cluster instance
func (*Cluster) AddInstance ¶
AddInstance add a new instance to a cluster
func (Cluster) IsClusterRunning ¶ added in v0.4.2
IsClusterRunning checks if the Cluster is Running
func (Cluster) IsClusterStopped ¶ added in v0.4.2
IsClusterStopped checks if the Cluster is Stopped
func (*Cluster) UpdateCosts ¶
UpdateCosts takes every cluster's instance costs and estimates the total cost for the cluster
func (*Cluster) UpdateStatus ¶
func (c *Cluster) UpdateStatus()
UpdateStatus evaluate the status of the cluster checking how many of the nodes are in Running, Stopped or Terminated status. Logic rules: - Empty cluster (no instances) -> Terminated - Any instance Running -> Running (early return) - All instances Terminated -> Terminated - Otherwise (mix of Stopped/Terminated or all Stopped) -> Stopped
type Expense ¶
type Expense struct {
// InstanceID references the instance of the expense
InstanceID string `db:"instance_id" json:"instanceID"`
// Ammount represents the cost in USDollars
Amount float64 `db:"amount" json:"amount"`
// Date (Year, month, day)
Date time.Time `db:"date" json:"date"`
}
Expense defines the expenses applied to an instance
type Instance ¶
type Instance struct {
// Uniq Identifier of the instance
ID string `db:"id" json:"id"`
// Instance Name. In some Cloud Providers, the name is managed as a Tag
Name string `db:"name" json:"name"`
// Instance provider (public/private cloud provider)
Provider CloudProvider `db:"provider" json:"provider"`
// Instance type/size/flavour
InstanceType string `db:"instance_type" json:"instanceType"`
// Availability Zone in which the instance is running on
AvailabilityZone string `db:"availability_zone" json:"availabilityZone"`
// Instance Status
Status InstanceStatus `db:"status" json:"status"`
// ClusterID
ClusterID string `db:"cluster_id" json:"clusterID"`
// Last scan timestamp of the instance
LastScanTimestamp time.Time `db:"last_scan_timestamp" json:"lastScanTimestamp"`
// Timestamp when the instance was created
CreationTimestamp time.Time `db:"creation_timestamp" json:"creationTimestamp"`
// Ammount of days since the instance was created
Age int `db:"age" json:"age"`
// Daily cost (US Dollars) estimated based on total cost and age of the instance
DailyCost float64 `db:"daily_cost" json:"dailyCost"`
// Total cost (US Dollars) accumulated since ClusterIQ is scanning
TotalCost float64 `db:"total_cost" json:"totalCost"`
// Instance Tags as key-value array
Tags []Tag `json:"tags"`
// Expenses list associated to the instance
Expenses []Expense `json:"expenses"`
}
Instance model a cloud provider instance
func NewInstance ¶
func NewInstance(id string, name string, provider CloudProvider, instanceType string, availabilityZone string, status InstanceStatus, clusterID string, tags []Tag, creationTimestamp time.Time) *Instance
NewInstance returns a new Instance object
func (Instance) PrintInstance ¶
func (i Instance) PrintInstance()
PrintInstance prints Instance details
func (*Instance) UpdateCosts ¶
UpdateCosts updates the totalCost of the instance using the instance age and the DailyCost
type InstanceStatus ¶
type InstanceStatus string
InstanceStatus defines the status of the instance
const ( // Running Instance status Running InstanceStatus = "Running" // Stopped Instance status Stopped InstanceStatus = "Stopped" // Terminated Instance status Terminated InstanceStatus = "Terminated" )
func AsInstanceStatus ¶
func AsInstanceStatus(status string) InstanceStatus
AsInstanceStatus converts the incoming argument into a InstanceStatus type
type Inventory ¶
type Inventory struct {
// Accounts map indexed by Account's Name
Accounts map[string]*Account `db:"accounts" json:"accounts"`
// Date of Inventory creation/update
CreationTimestamp time.Time `db:"creationTimestamp" json:"creationTimestamp"`
}
Inventory object to store inventored resources
func (*Inventory) AddAccount ¶
AddAccount adds a new account into the Inventory
func (Inventory) IsAccountOnInventory ¶
IsAccountOnInventory checks if a cluster is already in the Inventory
func (Inventory) PrintInventory ¶
func (s Inventory) PrintInventory()
PrintInventory prints the entire Inventory content
type Tag ¶
type Tag struct {
// Tag's key
Key string `db:"key" json:"key"`
// Tag's Value
Value string `db:"value" json:"value"`
// InstanceID reference
InstanceID string `db:"instance_id" json:"instance_id"`
}
Tag model generic tags as a Key-Value object
func LookForTagByKey ¶ added in v0.4.1
lookForTagByKey looks for a Tag based on its Key and returns a pointer to it