mks-go

module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: Apache-2.0

README

mks-go: Go SDK for Managed Kubernetes Service

Go.dev reference Go Report Card Build Status Coverage Status

Package mks-go provides Go SDK to work with the Selectel Managed Kubernetes Service.

Documentation

The Go library documentation is available at go.dev.

What this library is capable of

You can use this library to work with the following objects of the Selectel Managed Kubernetes Service:

Getting started

Installation

You can install needed mks-go packages via go get command:

go get github.com/selectel/mks-go/pkg/v1/cluster github.com/selectel/mks-go/pkg/v1/task
Authentication

To work with the Selectel Managed Kubernetes Service API you first need to:

Endpoints

Selectel Managed Kubernetes Service currently has the following API endpoints:

URL Region
https://ru-1.mks.selcloud.ru/v1 ru-1
https://ru-2.mks.selcloud.ru/v1 ru-2
https://ru-3.mks.selcloud.ru/v1 ru-3
https://ru-7.mks.selcloud.ru/v1 ru-7
https://ru-8.mks.selcloud.ru/v1 ru-8

You can also retrieve all available API endpoints from the Identity catalog.

Usage example
package main

import (
	"context"
	"fmt"
	"log"

	v1 "github.com/selectel/mks-go/pkg/v1"
	"github.com/selectel/mks-go/pkg/v1/cluster"
	"github.com/selectel/mks-go/pkg/v1/kubeversion"
	"github.com/selectel/mks-go/pkg/v1/nodegroup"
	"github.com/selectel/mks-go/pkg/v1/task"
)

func main() {
	// Token to work with Selectel Cloud project.
	token := "gAAAAABeVNzu-..."

	// MKS endpoint to work with.
	endpoint := "https://ru-3.mks.selcloud.ru/v1"

	// Initialize the MKS V1 client.
	mksClient := v1.NewMKSClientV1(token, endpoint)

	// Prepare empty context.
	ctx := context.Background()

	// Get supported Kubernetes versions.
	kubeVersions, _, err := kubeversion.List(ctx, mksClient)
	if err != nil {
		log.Fatal(err)
	}
	if len(kubeVersions) == 0 {
		log.Fatal("There are no available Kubernetes versions")
	}

	// Use the first version in list.
	kubeVersion := kubeVersions[0]

	// Nodegroup with nodes based on network volumes for root partition.
	firstNodegroup := &nodegroup.CreateOpts{
		Count:            3,
		CPUs:             1,
		RAMMB:            2048,
		VolumeGB:         50,
		VolumeType:       "fast.ru-3a",
		AvailabilityZone: "ru-3a",
	}

	// Nodegroup with nodes based on local volumes for root partition.
	secondNodegroup := &nodegroup.CreateOpts{
		Count:            2,
		CPUs:             2,
		RAMMB:            4096,
		VolumeGB:         20,
		LocalVolume:      true,
		AvailabilityZone: "ru-3a",
	}

	// Build final options for a new cluster.
	createOpts := &cluster.CreateOpts{
		Name:        "test-cluster",
		KubeVersion: kubeVersion.Version,
		Region:      "ru-3",
		Nodegroups: []*nodegroup.CreateOpts{
			firstNodegroup,
			secondNodegroup,
		},
	}

	// Create a cluster.
	newCluster, _, err := cluster.Create(ctx, mksClient, createOpts)
	if err != nil {
		log.Fatal(err)
	}

	// Print cluster fields.
	fmt.Printf("Created cluster: %+v\n", newCluster)

	// Get cluster tasks.
	tasks, _, err := task.List(ctx, mksClient, newCluster.ID)
	if err != nil {
		log.Fatal(err)
	}

	// Print cluster tasks.
	for _, t := range tasks {
		fmt.Printf("Cluster task: %+v\n", t)
	}
}

Directories

Path Synopsis
pkg
v1
Package v1 provides a library to work with the Selectel Managed Kubernetes Service API V1.
Package v1 provides a library to work with the Selectel Managed Kubernetes Service API V1.
v1/cluster
Package cluster provides the ability to retrieve and manage Kubernetes clusters through the MKS V1 API.
Package cluster provides the ability to retrieve and manage Kubernetes clusters through the MKS V1 API.
v1/kubeversion
Package kubeversion provides the ability to retrieve all supported Kubernetes versions through the MKS V1 API.
Package kubeversion provides the ability to retrieve all supported Kubernetes versions through the MKS V1 API.
v1/node
Package node provides the ability to retrieve and manage Kubernetes nodes of a cluster nodegroup through the MKS V1 API.
Package node provides the ability to retrieve and manage Kubernetes nodes of a cluster nodegroup through the MKS V1 API.
v1/nodegroup
Package nodegroup provides the ability to retrieve and manage cluster nodegroups through the MKS V1 API.
Package nodegroup provides the ability to retrieve and manage cluster nodegroups through the MKS V1 API.
v1/task
Package task provides the ability to retrieve cluster tasks through the MKS V1 API.
Package task provides the ability to retrieve cluster tasks through the MKS V1 API.

Jump to

Keyboard shortcuts

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