Documentation ¶
Overview ¶
Package cluster provides the ability to retrieve and manage Kubernetes clusters through the MKS V1 API.
Example of getting a single cluster referenced by its id
mksCluster, _, err := cluster.Get(ctx, mksClient, clusterID) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", mksCluster)
Example of getting all clusters
mksClusters, _, err := cluster.List(ctx, mksClient) if err != nil { log.Fatal(err) } for _, mksCluster := range mksClusters { fmt.Printf("%+v\n", mksCluster) }
Example of creating a new cluster
createOpts := &cluster.CreateOpts{ Name: "test-cluster-0", KubeVersion: "1.15.7", Region: "ru-1", Nodegroups: []*nodegroup.CreateOpts{ { Count: 1, CPUs: 1, RAMMB: 2048, VolumeGB: 10, VolumeType: "fast.ru-3a", KeypairName: "ssh-key", AvailabilityZone: "ru-3a", Labels: map[string]string{ "label-key0": "label-value0", "label-key1": "label-value1", "label-key2": "label-value2", }, }, }, } mksCluster, _, err := cluster.Create(ctx, mksClient, createOpts) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", mksCluster)
Example of updating an existing cluster
updateOpts := &cluster.UpdateOpts{ MaintenanceWindowStart: "07:00:00", } mksCluster, _, err := cluster.Update(ctx, mksClient, clusterID, updateOpts) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", mksCluster)
Example of deleting a single cluster
_, err := cluster.Delete(ctx, mksClient, clusterID) if err != nil { log.Fatal(err) }
Example of getting a kubeconfig referenced by cluster id
kubeconfig, _, err := cluster.GetKubeconfig(ctx, mksClient, clusterID) if err != nil { log.Fatal(err) } fmt.Print(string(kubeconfig))
Example of rotating certificates by cluster id
_, err := cluster.RotateCerts(ctx, mksClient, clusterID) if err != nil { log.Fatal(err) }
Example of upgrading Kubernetes patch version by cluster id
mksCluster, _, err := cluster.UpgradePatchVersion(ctx, mksClient, clusterID) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", mksCluster)
Example of upgrading Kubernetes minor version by cluster id
mksCluster, _, err := cluster.UpgradeMinorVersion(ctx, mksClient, clusterID) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", mksCluster)
Index ¶
- func Delete(ctx context.Context, client *v1.ServiceClient, clusterID string) (*v1.ResponseResult, error)
- func GetKubeconfig(ctx context.Context, client *v1.ServiceClient, clusterID string) ([]byte, *v1.ResponseResult, error)
- func RotateCerts(ctx context.Context, client *v1.ServiceClient, clusterID string) (*v1.ResponseResult, error)
- type CreateOpts
- type Status
- type UpdateOpts
- type View
- func Create(ctx context.Context, client *v1.ServiceClient, opts *CreateOpts) (*View, *v1.ResponseResult, error)
- func Get(ctx context.Context, client *v1.ServiceClient, clusterID string) (*View, *v1.ResponseResult, error)
- func List(ctx context.Context, client *v1.ServiceClient) ([]*View, *v1.ResponseResult, error)
- func Update(ctx context.Context, client *v1.ServiceClient, clusterID string, ...) (*View, *v1.ResponseResult, error)
- func UpgradeMinorVersion(ctx context.Context, client *v1.ServiceClient, clusterID string) (*View, *v1.ResponseResult, error)
- func UpgradePatchVersion(ctx context.Context, client *v1.ServiceClient, clusterID string) (*View, *v1.ResponseResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete(ctx context.Context, client *v1.ServiceClient, clusterID string) (*v1.ResponseResult, error)
Delete deletes a single cluster by its id.
func GetKubeconfig ¶
func GetKubeconfig(ctx context.Context, client *v1.ServiceClient, clusterID string) ([]byte, *v1.ResponseResult, error)
GetKubeconfig returns a kubeconfig by cluster id.
func RotateCerts ¶
func RotateCerts(ctx context.Context, client *v1.ServiceClient, clusterID string) (*v1.ResponseResult, error)
RotateCerts requests a rotation of cluster certificates by cluster id.
Types ¶
type CreateOpts ¶
type CreateOpts struct { // Name represent the needed name of the cluster. // It shouldn't contain more than 32 symbols and can contain latin letters // with numbers and hyphens and start with a letter or a number. Name string `json:"name,omitempty"` // NetworkID contains a reference to the network of the cluster. // It can be set in cases where network is pre-created. NetworkID string `json:"network_id,omitempty"` // SubnetID contains a reference to the subnet of the cluster. // It can be set in cases where subnet is pre-created. SubnetID string `json:"subnet_id,omitempty"` // KubeVersion represents the needed Kubernetes version of the cluster. // It should be in x.y.z format. KubeVersion string `json:"kube_version,omitempty"` // Region represents the needed region. Region string `json:"region,omitempty"` // Nodegroups contains groups of nodes with their parameters. Nodegroups []*nodegroup.CreateOpts `json:"nodegroups,omitempty"` // AdditionalSoftware represents parameters of additional software that can be installed // in the Kubernetes cluster. AdditionalSoftware map[string]interface{} `json:"additional_software,omitempty"` // MaintenanceWindowStart represents UTC time of when the cluster will start its maintenance tasks. // It should be in hh:mm:ss format if provided. MaintenanceWindowStart string `json:"maintenance_window_start,omitempty"` // EnableAutorepair reflects if worker nodes are allowed to be reinstalled automatically // in case of their unavailability or unhealthiness. Enabled by default. EnableAutorepair *bool `json:"enable_autorepair,omitempty"` // EnablePatchVersionAutoUpgrade specifies if Kubernetes patch version of the cluster is allowed to be upgraded // automatically. Enabled by default. EnablePatchVersionAutoUpgrade *bool `json:"enable_patch_version_auto_upgrade,omitempty"` }
CreateOpts represents options for the cluster Create request.
type Status ¶
type Status string
Status represents custom type for various cluster statuses.
const ( StatusActive Status = "ACTIVE" StatusPendingCreate Status = "PENDING_CREATE" StatusPendingUpdate Status = "PENDING_UPDATE" StatusPendingUpgrade Status = "PENDING_UPGRADE" StatusPendingRotateCerts Status = "PENDING_ROTATE_CERTS" StatusPendingDelete Status = "PENDING_DELETE" StatusPendingResize Status = "PENDING_RESIZE" StatusPendingNodeReinstall Status = "PENDING_NODE_REINSTALL" StatusPendingUpgradePatchVersion Status = "PENDING_UPGRADE_PATCH_VERSION" StatusPendingUpgradeMinorVersion Status = "PENDING_UPGRADE_MINOR_VERSION" StatusPendingUpdateNodegroup Status = "PENDING_UPDATE_NODEGROUP" StatusPendingUpgradeMastersConfiguration Status = "PENDING_UPGRADE_MASTERS_CONFIGURATION" StatusMaintenance Status = "MAINTENANCE" StatusError Status = "ERROR" StatusUnknown Status = "UNKNOWN" )
type UpdateOpts ¶ added in v0.2.0
type UpdateOpts struct { // MaintenanceWindowStart represents UTC time of when the cluster will start its maintenance tasks. // It should be in hh:mm:ss format if provided. MaintenanceWindowStart string `json:"maintenance_window_start,omitempty"` // EnableAutorepair reflects if worker nodes are allowed to be reinstalled automatically // in case of their unavailability or unhealthiness. Enabled by default. EnableAutorepair *bool `json:"enable_autorepair,omitempty"` // EnablePatchVersionAutoUpgrade specifies if Kubernetes patch version of the cluster is allowed to be upgraded // automatically. Enabled by default. EnablePatchVersionAutoUpgrade *bool `json:"enable_patch_version_auto_upgrade,omitempty"` }
UpdateOpts represents options for the cluster Update request.
type View ¶
type View struct { // ID is the identifier of the cluster. ID string `json:"id"` // CreatedAt is the timestamp in UTC timezone of when the cluster has been created. CreatedAt *time.Time `json:"created_at"` // UpdatedAt is the timestamp in UTC timezone of when the cluster has been updated. UpdatedAt *time.Time `json:"updated_at"` // Name represents the name of the cluster. Name string `json:"name"` // Status represents current status of the cluster. Status Status `json:"-"` // ProjectID contains reference to the project of the cluster. ProjectID string `json:"project_id"` // NetworkID contains reference to the network of the cluster. NetworkID string `json:"network_id"` // SubnetID contains reference to the subnet of the cluster. SubnetID string `json:"subnet_id"` // KubeAPIIP represents the IP of the Kubernetes API. KubeAPIIP string `json:"kube_api_ip"` // KubeVersion represents the current Kubernetes version of the cluster. KubeVersion string `json:"kube_version"` // Region represents the region of where the cluster is located. Region string `json:"region"` // AdditionalSoftware represents information about additional software installed in the cluster. AdditionalSoftware map[string]interface{} `json:"additional_software"` // PKITreeUpdatedAt represents the timestamp in UTC timezone of when the PKI-tree of the cluster // has been updated. PKITreeUpdatedAt *time.Time `json:"pki_tree_updated_at"` // MaintenanceWindowStart represents UTC time in "hh:mm:ss" format of when the cluster will start its // maintenance tasks. MaintenanceWindowStart string `json:"maintenance_window_start"` // MaintenanceWindowEnd represents UTC time in "hh:mm:ss" format of when the cluster will end its // maintenance tasks. MaintenanceWindowEnd string `json:"maintenance_window_end"` // MaintenanceLastStart is the timestamp in UTC timezone of the last cluster maintenance start. MaintenanceLastStart *time.Time `json:"maintenance_last_start"` // EnableAutorepair reflects if worker nodes are allowed to be reinstalled automatically // in case of their unavailability or unhealthiness. EnableAutorepair bool `json:"enable_autorepair"` // EnablePatchVersionAutoUpgrade specifies if Kubernetes patch version of the cluster is allowed to be upgraded // automatically. EnablePatchVersionAutoUpgrade bool `json:"enable_patch_version_auto_upgrade"` }
View represents an unmarshalled cluster body from an API response.
func Create ¶
func Create(ctx context.Context, client *v1.ServiceClient, opts *CreateOpts) (*View, *v1.ResponseResult, error)
Create requests a creation of a new cluster.
func Get ¶
func Get(ctx context.Context, client *v1.ServiceClient, clusterID string) (*View, *v1.ResponseResult, error)
Get returns a single cluster by its id.
func List ¶
func List(ctx context.Context, client *v1.ServiceClient) ([]*View, *v1.ResponseResult, error)
List gets a list of all clusters.
func Update ¶ added in v0.2.0
func Update(ctx context.Context, client *v1.ServiceClient, clusterID string, opts *UpdateOpts) (*View, *v1.ResponseResult, error)
Update requests an update of an existing cluster.
func UpgradeMinorVersion ¶ added in v0.4.0
func UpgradeMinorVersion(ctx context.Context, client *v1.ServiceClient, clusterID string) (*View, *v1.ResponseResult, error)
UpgradeMinorVersion requests a Kubernetes minor version upgrade by cluster id.
func UpgradePatchVersion ¶ added in v0.2.0
func UpgradePatchVersion(ctx context.Context, client *v1.ServiceClient, clusterID string) (*View, *v1.ResponseResult, error)
UpgradePatchVersion requests a Kubernetes patch version upgrade by cluster id.