gogo

package module
v0.0.0-...-8e2a169 Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: Apache-2.0 Imports: 9 Imported by: 2

README

GO Library to use JUJU commands to bring up a Kubernetes cluster

Go Report Card

Pre-reqs

go get gopkg.in/yaml.v2

Usage

Currently can bring up kubernetes cluster in CNCT maas lab or on aws.

You will need to set the instance of Juju with the following fields:

JujuDataPrefix variable

In order to run the juju cli in discrete environments, a different JUJU_DATA path is set per Juju.Name. This path prefix defaults to /tmp and will result in the loss of the juju cli state as /tmp is ephemeral.

Set this variable to a path with persistant storage:

import (
    "github.com/dstorck/gogo"
)

gogo.JujuDataPrefix = "/data"
Juju struct options
  • Note - While several fields are optional, you must include either MaasCl and MaasCr or AwsCl and AwsCr
Field Name Required Type Description
Kind Required CloudKind must use one of the const: Maas or Aws
Name Required String JUJU_DATA path and juju clustername for MAAS
Bundle Required String ex "cs:bundle/canonical-kubernetes-193"
p Optional Parallel used for multiple cluster creation
MaasCl Optional MaasCloud maas cloud details
MaasCr Optional MaasCredentials maas credential details
AwsCl Optional AwsCloud aws cloud details
AwsCr Optional AwsCredentials aws credential details

MaasCl Options

Field Name Required Type Description
Endpoint Required String maas url ex-"http://your-ip/MAAS/api/2.0"

MaasCr Options

Field Name Required Type Description
Username Required String maas username
MaasOauth Required String maas api key

AwsCl Options

Field Name Required Type Description
Region Optional String ex "aws/us-west-2"

AwsCr Options

Field Name Required Type Description
Username Required String your aws username
AccessKey Required String aws access key
SecretKey Required String aws secret key
Working commands:
  • SetAWSCreds() - sets aws credentials for use with juju
  • SetMAASCreds() sets maas credentials for use with juju
  • SetMAASCloud() - sets maas cloud information for use with juju
  • Spinup() - spins up cluster from specified creds/cloud/bundle (includes setting cloud and credentials)
  • ControllerReady() - returns boolean with status of controller availability
  • GetStatus() - returns result of running juju status
  • ClusterReady() - returns boolean corresponding to readiness of cluster
  • GetKubeConfig() - returns the contents of the kubeconfig file
  • DestroyCluster() - tears down juju controller and associated cluster
  • DestroyComplete() returns boolean corresponding to successful destruction of cluster
Sample file to bring up maas cluster on Samsung's CNCT nuc lab:
package main

import (
	"fmt"

	"github.com/dstorck/gogo"
)

var testRun = gogo.Juju{
	Kind:   gogo.Maas,
	Name:   "test-cluster",
	Bundle: "cs:bundle/kubernetes-core-306",
	MaasCl: myMaasCloud,
	MaasCr: myMaasCreds,
}

var myMaasCloud = gogo.MaasCloud{
	Endpoint: "<your-maas-url>",
}
var myMaasCreds = gogo.MaasCredentials{
	Username:  "<username>",
	MaasOauth: "<maas-api-key>",
}

// current available commands, not meant to be run all at once
func main() {
  testRun.SetMAASCreds()
  testRun.SetMAASCloud()
  testRun.Spinup()
  status, _ := testRun.GetStatus()
	fmt.Println(status)
  testRun.ClusterReady()
  config,_ := testRun.GetKubeConfig()
	fmt.Println(string(config))
  testRun.DestroyCluster()
  testRun.DestroyComplete()
}
Sample file to bring up aws cluster
package main

import (
	"github.com/dstorck/gogo"
)

var testRun = gogo.Juju{
	Kind:   gogo.Aws,
	Name:   "test-cluster",
	Bundle: "cs:bundle/kubernetes-core-306",
	AwsCr:  myAWScreds,
	AwsCl:  myAWScloud,
}

var myAWScreds = gogo.AWSCredentials{
	Username:  "<your-aws-username>",
	AccessKey: "<your-access-key>",
	SecretKey: "<your-secret-key",
}

var myAWScloud = gogo.AWSCloud{
	Region: "aws/us-west-2",
}

// currently available commands, not meant to be run all at once
func main() {
  // testRun.SetAWSCreds()
  // testRun.GetStatus()
  // testRun.Spinup()
  // testRun.ControllerReady()
  // testRun.ClusterReady()
  // testRun.GetKubeConfig()
  // testRun.DestroyCluster()
  // testRun.DestroyComplete()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JujuDataPrefix = "/tmp/"

JujuDataPrefix is the path prefix used for the JUJU_DATA environment variable this path will store required juju state and should be persistent

Functions

func CreateAWSCredsYaml

func CreateAWSCredsYaml(username string, accessKey string, secretKey string) (string, error)

CreateAWSCredsYaml is used to create the yaml string to pass to "juju add-credential"

func CreateMAASCloudYaml

func CreateMAASCloudYaml(name string, endpoint string) (string, error)

CreateMAASCloudYaml is used to create the yaml string to pass to "juju add-cloud"

func CreateMAASCredsYaml

func CreateMAASCredsYaml(cloudName string, username string, maasOauth string) (string, error)

CreateMAASCredsYaml is used to create the yaml string to pass to "juju add-credential"

Types

type AWSCloud

type AWSCloud struct {
	Region string
}

AWSCloud information to be used with AWS Creds

type AWSCredentials

type AWSCredentials struct {
	Username  string
	AccessKey string
	SecretKey string
}

AWSCredentials information

type CloudKind

type CloudKind string

CloudKind is the kind of cloud, eg. aws, maas, etc.

const (
	Aws  CloudKind = "aws"
	Maas CloudKind = "maas"
)

Supported Cloud Kinds

type Juju

type Juju struct {
	Kind   CloudKind // should be gogo.Aws or gogo.Maas - will be used to figure out which creds and cloud to set
	Name   string
	Bundle string // ex "cs:bundle/canonical-kubernetes-193"
	MaasCl MaasCloud
	MaasCr MaasCredentials
	AwsCl  AWSCloud
	AwsCr  AWSCredentials
}

Juju defines the cluster name, which bundle to use, and the manifest for credentials and cloud

func (*Juju) ClusterReady

func (j *Juju) ClusterReady() (bool, error)

ClusterReady will check status and return true if cluster is running

func (*Juju) ControllerReady

func (j *Juju) ControllerReady() (bool, error)

ControllerReady checks model status and returns bool

func (*Juju) DestroyCluster

func (j *Juju) DestroyCluster() error

DestroyCluster will kill off one cluster

func (*Juju) DestroyComplete

func (j *Juju) DestroyComplete() (bool, error)

DestroyComplete checks juju for controllers to make sure none are left

func (*Juju) GetKubeConfig

func (j *Juju) GetKubeConfig() ([]byte, error)

GetKubeConfig returns the kubeconfig file contents

func (*Juju) GetStatus

func (j *Juju) GetStatus() (string, error)

GetStatus return juju status

func (*Juju) SetAWSCreds

func (j *Juju) SetAWSCreds() error

SetAWSCreds will grab and credential information and set it

func (*Juju) SetMAASCloud

func (j *Juju) SetMAASCloud() error

SetMAASCloud will run juju add-cloud with maasCloud yaml created above

func (*Juju) SetMAASCreds

func (j *Juju) SetMAASCreds() error

SetMAASCreds will pass in maas credentials to juju add-credential

func (*Juju) Spinup

func (j *Juju) Spinup() error

Spinup will create one cluster

type MaasCloud

type MaasCloud struct {
	Endpoint string
}

MaasCloud information

type MaasCredentials

type MaasCredentials struct {
	Username  string
	MaasOauth string
}

MaasCredentials to be used with MaasCloud

type Parallel

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

Parallel sets the waitgroup if user wishes to bring up several clusters at once

Jump to

Keyboard shortcuts

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