Skip to content

Commit c06b991

Browse files
Merge pull request #2 from AndrewChubatiuk/fix-scaler
Updated scaling
2 parents c51851a + 00bf081 commit c06b991

30 files changed

+838
-327
lines changed

.circleci/config.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version: 2.1
22

3+
orbs:
4+
docker: circleci/[email protected]
5+
36
executors:
47
go-linux:
58
resource_class: medium
@@ -57,20 +60,33 @@ workflows:
5760
jobs:
5861
- check-deps-go:
5962
filters:
60-
tags:
61-
only: /^v\d+\.\d+\.\d+$/
63+
tags:
64+
only: /^v\d+\.\d+\.\d+$/
6265
- lint-go:
6366
filters:
64-
tags:
65-
only: /^v\d+\.\d+\.\d+$/
67+
tags:
68+
only: /^v\d+\.\d+\.\d+$/
6669
- linux-build-go:
6770
filters:
68-
tags:
69-
only: /^v\d+\.\d+\.\d+$/
71+
tags:
72+
only: /^v\d+\.\d+\.\d+$/
7073
- linux-test-go:
7174
filters:
72-
tags:
73-
only: /^v\d+\.\d+\.\d+$/
75+
tags:
76+
only: /^v\d+\.\d+\.\d+$/
77+
- docker/publish:
78+
attach-at: ./bin/
79+
deploy: true
80+
image: achubatiuk/nomad-autoscaler
81+
tag: $CIRCLE_BRANCH
82+
requires:
83+
- check-deps-go
84+
- lint-go
85+
- linux-build-go
86+
- linux-test-go
87+
filters:
88+
tags:
89+
only: /^v\d+\.\d+\.\d+$/
7490
- release:
7591
requires:
7692
- check-deps-go

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
bin/*
2-
2+
.terraform.lock.hcl
3+
*.tfstate
4+
*.tfstate.backup
5+
*.tfstate.*.backup
6+
*.tfplan
7+
**/.terraform/*
8+
creds.json
9+
.vscode

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM hashicorp/nomad-autoscaler:0.3.6
2+
ADD bin/hcloud-server /plugins/

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ build:
3232
@CGO_ENABLED=0 GO111MODULE=on \
3333
go build \
3434
-ldflags $(GO_LDFLAGS) \
35-
-o ./bin/nomad-hcloud-autoscaler
35+
-o ./bin/hcloud-server
3636
@echo "==> Done"
3737

3838
.PHONY: lint
@@ -66,5 +66,5 @@ test: ## Test the source code
6666
.PHONY: clean
6767
clean:
6868
@echo "==> Cleaning build artifacts..."
69-
@rm -f ./bin/nomad-hcloud-autoscaler
69+
@rm -f ./bin/*
7070
@echo "==> Done"

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# nomad-hcloud-autoscaler
22

3-
Example configuration
3+
## Demo
4+
Run `terraform apply` in [demo](demo/setup) folder to create:
5+
- nomad server which runs services for:
6+
- nomad-autoscaler
7+
- prometheus
8+
- redis
9+
Autoscaler scales hcloud nodes for redis. After successful run both Nomad and Consul are wide-world open and credentials for both you can find in terraform output
10+
11+
12+
## Configuration
413

514
`config.hcl`
615
```
@@ -75,7 +84,7 @@ template {
7584
hcloud_user_data = ""
7685
hcloud_ssh_keys = "XXX"
7786
hcloud_server_type = "cx11"
78-
hcloud_name_prefix = "XXX"
87+
hcloud_group_id = "XXX"
7988
hcloud_labels = "XXX_node=true"
8089
hcloud_networks = "XXX"
8190
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "ipv4_addresses" {
2+
value = hcloud_server.server.*.ipv4_address
3+
}
4+
5+
output "ids" {
6+
value = hcloud_server.server.*.id
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
data "hcloud_datacenters" "dc" {}
2+
3+
resource "random_shuffle" "dc" {
4+
count = var.server_count
5+
input = local.locations
6+
result_count = 1
7+
}
8+
9+
resource "hcloud_server" "server" {
10+
count = var.server_count
11+
name = "${var.prefix}-${count.index}"
12+
image = var.image
13+
datacenter = random_shuffle.dc[count.index].result[0]
14+
ssh_keys = var.ssh_keys
15+
server_type = var.server_type
16+
user_data = var.user_data
17+
labels = merge(var.labels, { "Name" = var.prefix })
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
variable "location" {
2+
type = string
3+
default = null
4+
}
5+
6+
variable "labels" {
7+
type = map(string)
8+
default = {}
9+
}
10+
11+
variable "prefix" {}
12+
13+
variable "server_count" {}
14+
15+
variable "ssh_keys" {
16+
type = list(string)
17+
}
18+
19+
variable "server_type" {}
20+
21+
variable "user_data" {}
22+
23+
variable "image" {
24+
default = "ubuntu-20.04"
25+
}
26+
27+
locals {
28+
locations = [for dc in data.hcloud_datacenters.dc.names : dc if var.location != null && can(regex("^${var.location}-dc\\d+$", dc))]
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
hcloud = {
4+
source = "hetznercloud/hcloud"
5+
}
6+
random = {
7+
source = "hashicorp/random"
8+
}
9+
}
10+
required_version = ">= 0.13"
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "nomad_job" "service" {
2+
jobspec = file(var.path)
3+
}

0 commit comments

Comments
 (0)