A Go library and a command-line tool to manage Docker Swarm clusters

go-swarm

Go

go-swarm is a Go library and command-line tool for managing the creation and maintenance of Docker Swarm cluster.

Features:

  • Creates new Swarm Cluster given a Terraform Clusterfile as input.
  • Retrives information about Swarm Clsuters.
  • Join new workers or managers to an existing Swarm Cluster.
  • Assigning Swarm Labels based on underlying VM Node labels.
  • Add-hoc adding new worker or manager nodes.
  • Draining Swarm nodes.
  • Removing Swarm ndoes.

Install

Currently tehre is a command-line tool called swarm that can be installed with:

go install github.com/aucloud/cmd/swarm@latest

Using as a library is to be documented at a later date.

usage

Using the swarm CLI tool is easy:

$ ./swarm
This is a command-line Docker Swarm Manager

This tool is an implementation of the swarm management library used to help
facilitate and automate the creation and management of Docker Swarm Clusters.

Supported functions include:

- Creating a Swarm Clsuter
- Adding new worker or manager nodes
- Draining nodes
- Removing nodes
- Displaying cluster information

Usage:
  swarm [command]

Available Commands:
  create      Creates a new Swarm Cluster
  help        Help about any command
  info        Retrieve and display Swarm Cluster Information
  status      Retrieve and display Swarm Cluster Status

Flags:
      --config string     config file (default is $HOME/.swarm.yaml)
  -D, --debug             Enable debug logging
  -h, --help              help for swarm
  -A, --ssh-addr string   SSH Address to connect to
  -K, --ssh-key string    SSH Key to use for remote execution (default "$HOME/.ssh/id_rsa")
  -U, --ssh-user string   SSH User to use for remote execution (default "rancher")
  -v, --version           version for swarm

Use "swarm [command] --help" for more information about a command.

For example to create a new Swarm cluster from a Terraform run:

terraform output -json Clusterfile | swarm -D create -

This will take the Clusterfile (a JSON representing the VM Nodes created via Terraform) and create a multi-manager Swarm Cluster and join all worker nodes and display the cluster status at the end.

cat Clusterfile.json
{
  "region": "local",
  "environment": "test",
  "cluster": "c1",
  "domain": "localdomain",
  "nodes": [{
    "hostname": "dm1",
    "public_address": "10.0.0.1",
    "private_address": "172.16.0.1",
    "tags": {
      "role": "manager"
    }
  }]
}

License

go-swarm is licensed under the terms of the AGPLv3

Owner
AUCloud
AUCloud AO&M Open Source Projects
AUCloud
Comments
  • Swarm provider fails to SSH to Docker swarm manager using VM public IP address

    Swarm provider fails to SSH to Docker swarm manager using VM public IP address

    During creation of a Docker cluster with the swarm provider into a Digitalocean account, we encountered the error shown below. Once the host mask was placed in the .ssh/config file (with attribute StrictHostKeyChecking set to no), we were able to re-apply the terraform config and the cluster resource was created correctly.

    swarm_cluster.cluster: Creating...
    2021-11-12T14:12:41.752+1000 [DEBUG] provider.terraform-provider-swarm_v1.0.0: time="2021-11-12T14:12:41+10:00" level=error msg="error switching to node 159.223.55.20" error="error creating remote runner: dial tcp 159.223.55.20:22: connect: connection refused"
    ╷
    │ Error: Unable to switch to first manager node
    │
    │   with swarm_cluster.cluster,
    │   on main.tf line 47, in resource "swarm_cluster" "cluster":
    │   47: resource "swarm_cluster" "cluster" {
    │
    │ Error switching to first manager node dm1.aucloud.SGP1 via 159.223.55.20: error switching to node 159.223.55.20:
    │ error creating remote runner: dial tcp 159.223.55.20:22: connect: connection refused
    ╵
    2021-11-12T14:12:41.811+1000 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
    2021-11-12T14:12:41.813+1000 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/aucloud/swarm/1.0.0/darwin_amd64/terraform-provider-swarm_v1.0.0 pid=23905
    2021-11-12T14:12:41.814+1000 [DEBUG] provider: plugin exited```
  • Unable to obtain terraform output information due to a file read failure in the swarm provider.

    Unable to obtain terraform output information due to a file read failure in the swarm provider.

    Versions

    terraform version: v1.0.2
    swarm provider: v0.1.0
    

    Issue

    The following error was thrown when attempting to deploy a 3 manager and 3 worker swarm:

    │ Error: Unable to switch to first manager node
    │
    │   with swarm_cluster.cluster,
    │   on main.tf line 46, in resource "swarm_cluster" "cluster":
    │   46: resource "swarm_cluster" "cluster" {
    │
    │ Error switching to first manager node heketi01-dm1 via 10.9.9.48: error switching to node 10.9.9.48: error creating remote runner: stat : no such file or directory
    

    The root cause is missing provider configuration, but it was not evident in this output that the ssh private key was not found.

    Logs

    The terraform.log output (TF_LOG_PROVIDER=debug):

    2021-11-08T10:37:48.762+1000 [INFO]  CLI command args: []string{"apply", "-var-file", "tfvars/glusterprovider_sbx_r00.tfvars"}
    2021-11-08T10:37:48.768+1000 [INFO]  AWS Auth provider used: "SharedCredentialsProvider"
    2021-11-08T10:37:49.183+1000 [DEBUG] checking for provisioner in "."
    2021-11-08T10:37:49.186+1000 [DEBUG] checking for provisioner in "/usr/local/bin"
    2021-11-08T10:37:49.186+1000 [DEBUG] checking for provisioner in "/Users/ap0002/.terraform.d/plugins"
    2021-11-08T10:37:49.187+1000 [INFO]  Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory
    2021-11-08T10:37:49.187+1000 [INFO]  backend/local: starting Apply operation
    

    Root Cause

    The following configuration was missing from main.tf:

    provider "swarm" {
      ssh_user = var.terraform_ssh_user
      ssh_key = var.terraform_ssh_key
    }
    

    This maps the private key from the user variable terraform_ssh_user for the swarm provider.

    Expected Outcome

    Please provide better error output for this error condition. The README should capture the config requirements, but this information is not enough to troubleshoot off.

  • Fixes ensureManager() to use the PublicAddress of a matching nodes

    Fixes ensureManager() to use the PublicAddress of a matching nodes

    Fixes #5

    This addresses the problem in #5 by ensuring that we alway communicate with nodes via their .PublicAddress. We add support for filtering VMNodes by Public and Private address (in addition to tags which was already present). This lets us refactor .ensureManager() to correctly get the Public Address of one of the manager nodes to switch to when performing cluster modifications.

  • Swarm manage assumes PrivateAddress when swithcing nodes

    Swarm manage assumes PrivateAddress when swithcing nodes

    While doing some testing on a Compute + Storage cluster on Digital Ocean I noticed that swarm tool and the go-swarm library assumes the node's private address when switching nodes:

    (⎈ |local:default)
    prologic@Jamess-iMac
    Thu Dec 09 14:43:31
    ~/Projects/terraform-digitalocean-docker-swarm
     (storage_cluster) 130
    $ terraform output -json Clusterfile | swarm -D -U rancher -K terraform_rsa create -
    DEBU[0003] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    DEBU[0005] running cmd on ssh://[email protected]:22: docker swarm init --advertise-addr 10.130.0.7 --listen-addr 10.130.0.7  args="[]"
    DEBU[0009] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    DEBU[0010] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    DEBU[0011] running cmd on ssh://[email protected]:22: docker swarm join-token -q manager  args="[]"
    DEBU[0012] running cmd on ssh://[email protected]:22: docker swarm join-token -q worker  args="[]"
    DEBU[0016] running cmd on ssh://[email protected]:22: docker swarm join --advertise-addr 10.130.0.6 --listen-addr 10.130.0.6 --token SWMTKN-1-52zpwz2zpfgbrme9gw046r2at9ftphoxxokc158etc9manvbyt-1xf8cwuqb9uqe07eeo5n2a8ez 10.130.0.7:2377  args="[]"
    DEBU[0022] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    DEBU[0028] running cmd on ssh://[email protected]:22: docker swarm join --advertise-addr 10.130.0.2 --listen-addr 10.130.0.2 --token SWMTKN-1-52zpwz2zpfgbrme9gw046r2at9ftphoxxokc158etc9manvbyt-1xf8cwuqb9uqe07eeo5n2a8ez 10.130.0.7:2377  args="[]"
    DEBU[0032] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    DEBU[0036] running cmd on ssh://[email protected]:22: docker swarm join --advertise-addr 10.130.0.3 --listen-addr 10.130.0.3 --token SWMTKN-1-52zpwz2zpfgbrme9gw046r2at9ftphoxxokc158etc9manvbyt-eg1343suxpb6pbrfpcng46q57 10.130.0.7:2377  args="[]"
    DEBU[0041] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    DEBU[0042] running cmd on ssh://[email protected]:22: docker info --format "{{ json . }}"  args="[]"
    ERRO[0194] error switching to node 10.130.0.6            error="error creating remote runner: failed to establish an SSH connection to 10.130.0.6:22: timed out trying to connect to ssh after 2m32s: dial tcp 10.130.0.6:22: connect: operation timed out"
    WARN[0194] error switch to remote manager (trying next manager): %werror switching to node 10.130.0.6: error creating remote runner: failed to establish an SSH connection to 10.130.0.6:22: timed out trying to connect to ssh after 2m32s: dial tcp 10.130.0.6:22: connect: operation timed out  error="error switching to node 10.130.0.6: error creating remote runner: failed to establish an SSH connection to 10.130.0.6:22: timed out trying to connect to ssh after 2m32s: dial tcp 10.130.0.6:22: connect: operation timed out"
    ERRO[0347] error switching to node 10.130.0.2            error="error creating remote runner: failed to establish an SSH connection to 10.130.0.2:22: timed out trying to connect to ssh after 2m32s: dial tcp 10.130.0.2:22: connect: operation timed out"
    WARN[0347] error switch to remote manager (trying next manager): %werror switching to node 10.130.0.2: error creating remote runner: failed to establish an SSH connection to 10.130.0.2:22: timed out trying to connect to ssh after 2m32s: dial tcp 10.130.0.2:22: connect: operation timed out  error="error switching to node 10.130.0.2: error creating remote runner: failed to establish an SSH connection to 10.130.0.2:22: timed out trying to connect to ssh after 2m32s: dial tcp 10.130.0.2:22: connect: operation timed out"
    ERRO[0499] error switching to node 10.130.0.7            error="error creating remote runner: failed to establish an SSH connection to 10.130.0.7:22: timed out trying to connect to ssh after 2m31s: dial tcp 10.130.0.7:22: connect: operation timed out"
    WARN[0499] error switch to remote manager (trying next manager): %werror switching to node 10.130.0.7: error creating remote runner: failed to establish an SSH connection to 10.130.0.7:22: timed out trying to connect to ssh after 2m31s: dial tcp 10.130.0.7:22: connect: operation timed out  error="error switching to node 10.130.0.7: error creating remote runner: failed to establish an SSH connection to 10.130.0.7:22: timed out trying to connect to ssh after 2m31s: dial tcp 10.130.0.7:22: connect: operation timed out"
    error creating swarm cluster: error labelling worker: error connecting to manager node: unable to connect to suitable manager
    

    I think we either need to assume the node's public address here os make this configurable.

    OTOH it's not super clear to me why the private networking and ssh listening port isn't working across the ndoe's private addresses in Digital Ocean -- probably worth finding that out...

  • Add support for using ssh agent authentication

    Add support for using ssh agent authentication

    This builds on the https://github.com/aucloud/go-runcmd/pull/4 PR to allow to use SSH agent authentication when provisioning using the Terraform swarm provider

    At the moment, there is an go.mod replace directive to use the new version of go-runcmd, but it should be replaced once the go-runcmd changes are in.

e2d is a command-line tool for deploying and managing etcd clusters, both in the cloud or on bare-metal

e2d is a command-line tool for deploying and managing etcd clusters, both in the cloud or on bare-metal. It also includes e2db, an ORM-like abstraction for working with etcd.

Aug 23, 2022
A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Dec 18, 2021
An open-source GitLab command line tool bringing GitLab's cool features to your command line
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Dec 22, 2021
An interactive command-line tool to manage your environments
An interactive command-line tool to manage your environments

goto An interactive command-line tool to manage your environments Overview You always need to login to some Linux machine or connect to a MySQL instan

Jul 11, 2022
kcli: command line interface tool to interact with K8trics API server as well as manage its lifecycle
kcli: command line interface tool to interact with K8trics API server as well as manage its lifecycle

K8trics CLI (kcli) kcli is command line interface tool to interact with K8trics API server as well as manage its lifecycle. kcli can provision and dep

Dec 15, 2021
This is a command line application to manage and fine-tune Time Machine exclude paths.

heptapod This is a command line application to manage and fine-tune Time Machine exclude paths. This repository is a WIP! The advertised functionality

Dec 28, 2022
Manage your gists from the command-line.
Manage your gists from the command-line.

Gister Manage your gists from the command-line. You can even manage your gists using your favorite editor. Demo Create a github access token https://h

Nov 28, 2022
Easily manage your work via command line

Wo Easily manage your work via command line Introduction Wo, is cli that provides it easy to manage your workspace. Wo provides to manipulating workfl

Dec 11, 2021
Subnet-cli - A command-line interface to manage Avalanche Subnets
Subnet-cli - A command-line interface to manage Avalanche Subnets

subnet-cli A command-line interface to manage Avalanche Subnets. Install git clo

Nov 26, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Dec 31, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Feb 5, 2022
fofax is a fofa query tool written in go, positioned as a command-line tool and characterized by simplicity and speed.
fofax is a fofa query tool written in go, positioned as a command-line tool and characterized by simplicity and speed.

fofaX 0x00 Introduction fofax is a fofa query tool written in go, positioned as

Jan 8, 2023
A command-line tool and library for generating regular expressions from user-provided test cases
A command-line tool and library for generating regular expressions from user-provided test cases

Table of Contents What does this tool do? Do I still need to learn to write regexes then? Current features How to install? 4.1 The command-line tool 4

Jan 9, 2023
Library and command line tool for reading xDSL stats

xDSL Stats Parser This is a library and command line tool for reading basic xDSL stats, as well bitloading, SNR, QLN and Hlog data. It supports many d

Nov 12, 2022
Gowebdav - A golang WebDAV client library and command line tool.

GoWebDAV A golang WebDAV client library. Main features gowebdav library allows to perform following actions on the remote WebDAV server: create path g

Jan 3, 2023
Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Mar 27, 2022
eksctl is a simple CLI tool for creating clusters on EKS
eksctl is a simple CLI tool for creating clusters on EKS

eksctl is a simple CLI tool for creating clusters on EKS - Amazon's new managed Kubernetes service for EC2. It is written in Go, and uses CloudFormation.

Jan 7, 2023
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023